diff --git a/src/cmd/compile/internal/base/debug.go b/src/cmd/compile/internal/base/debug.go index 2a0aa2f5c8..4667fdb1da 100644 --- a/src/cmd/compile/internal/base/debug.go +++ b/src/cmd/compile/internal/base/debug.go @@ -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"` diff --git a/src/cmd/compile/internal/base/flag.go b/src/cmd/compile/internal/base/flag.go index f1685104b1..1546c277fd 100644 --- a/src/cmd/compile/internal/base/flag.go +++ b/src/cmd/compile/internal/base/flag.go @@ -167,6 +167,7 @@ func ParseFlags() { Debug.ConcurrentOk = true Debug.InlFuncsWithClosures = 1 + Debug.InlStaticInit = 0 if buildcfg.Experiment.Unified { Debug.Unified = 1 } diff --git a/src/cmd/compile/internal/staticinit/sched.go b/src/cmd/compile/internal/staticinit/sched.go index 0f037d5467..12bf932a7b 100644 --- a/src/cmd/compile/internal/staticinit/sched.go +++ b/src/cmd/compile/internal/staticinit/sched.go @@ -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. diff --git a/test/fixedbugs/issue56778.go b/test/fixedbugs/issue56778.go index 8bb5c3e213..3c27501fd2 100644 --- a/test/fixedbugs/issue56778.go +++ b/test/fixedbugs/issue56778.go @@ -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 diff --git a/test/inline.go b/test/inline.go index cf2cd8cd60..1aa8fccbbd 100644 --- a/test/inline.go +++ b/test/inline.go @@ -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 diff --git a/test/noinit.go b/test/noinit.go index ed8e572e51..505467cf8f 100644 --- a/test/noinit.go +++ b/test/noinit.go @@ -1,4 +1,4 @@ -// run +// run -gcflags=-d=inlstaticinit=1 //go:build !gcflags_noopt // Copyright 2010 The Go Authors. All rights reserved.