]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add -d=inlstaticinit debug flag
authorMatthew Dempsky <mdempsky@google.com>
Tue, 22 Nov 2022 01:17:06 +0000 (17:17 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 22 Nov 2022 01:42:49 +0000 (01:42 +0000)
This CL adds -d=inlstaticinit to control whether static initialization
of inlined function calls (added in CL 450136) is allowed.

We've needed to fix it once already (CL 451555) and Google-internal
testing is hitting additional failure cases, so putting this
optimization behind a feature flag seems appropriate regardless.

Also, while we diagnose and fix the remaining cases, this CL also
disables the optimization to avoid miscompilations.

Updates #56894.

Change-Id: If52a358ad1e9d6aad1c74fac5a81ff9cfa5a3793
Reviewed-on: https://go-review.googlesource.com/c/go/+/452676
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>

src/cmd/compile/internal/base/debug.go
src/cmd/compile/internal/base/flag.go
src/cmd/compile/internal/staticinit/sched.go
test/fixedbugs/issue56778.go
test/inline.go
test/noinit.go

index 2a0aa2f5c898c8ae90088b852731310097976890..4667fdb1da98767c999d8a5061768cf9edec2d47 100644 (file)
@@ -31,6 +31,7 @@ type DebugFlags struct {
        GCProg                int    `help:"print dump of GC programs"`
        Gossahash             string `help:"hash value for use in debugging the compiler"`
        InlFuncsWithClosures  int    `help:"allow functions with closures to be inlined" concurrent:"ok"`
+       InlStaticInit         int    `help:"allow static initialization of inlined calls"`
        InterfaceCycles       int    `help:"allow anonymous interface cycles"`
        Libfuzzer             int    `help:"enable coverage instrumentation for libfuzzer"`
        LocationLists         int    `help:"print information about DWARF location list creation"`
index f1685104b1d4e203c4d98ff5b743170e193c4e0c..1546c277fd34d9a5121022dfbe731908264b5b3f 100644 (file)
@@ -167,6 +167,7 @@ func ParseFlags() {
 
        Debug.ConcurrentOk = true
        Debug.InlFuncsWithClosures = 1
+       Debug.InlStaticInit = 0
        if buildcfg.Experiment.Unified {
                Debug.Unified = 1
        }
index 0f037d5467a1281dbc96ff14f380e8cec4a8f265..12bf932a7be25503d6faf3e154aead406ea70ffd 100644 (file)
@@ -451,6 +451,10 @@ func (s *Schedule) addvalue(p *Plan, xoffset int64, n ir.Node) {
 }
 
 func (s *Schedule) staticAssignInlinedCall(l *ir.Name, loff int64, call *ir.InlinedCallExpr, typ *types.Type) bool {
+       if base.Debug.InlStaticInit == 0 {
+               return false
+       }
+
        // Handle the special case of an inlined call of
        // a function body with a single return statement,
        // which turns into a single assignment plus a goto.
index 8bb5c3e21398f4d28cfb34ab6acd869926063c1c..3c27501fd27d870ae047fc6524d3448b7a0f08e1 100644 (file)
@@ -1,4 +1,4 @@
-// compiledir
+// compiledir -d=inlstaticinit=1
 
 // Copyright 2022 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
index cf2cd8cd60326e537ce28188feba0783e5189b88..1aa8fccbbdc62509d2f23789c680137ab4491d0d 100644 (file)
@@ -1,4 +1,4 @@
-// errorcheckwithauto -0 -m -d=inlfuncswithclosures=1
+// errorcheckwithauto -0 -m -d=inlfuncswithclosures=1 -d=inlstaticinit=1
 
 // Copyright 2015 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
index ed8e572e511121d492b15c8a0575ce0d38012a04..505467cf8f332631648889c2a4b94fae16cb888a 100644 (file)
@@ -1,4 +1,4 @@
-// run
+// run -gcflags=-d=inlstaticinit=1
 //go:build !gcflags_noopt
 
 // Copyright 2010 The Go Authors. All rights reserved.