From 152119990f62e9a791493f52933b7a113aaa4234 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Mon, 21 Nov 2022 17:17:06 -0800 Subject: [PATCH] cmd/compile: add -d=inlstaticinit debug flag 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 TryBot-Result: Gopher Robot Run-TryBot: Matthew Dempsky --- src/cmd/compile/internal/base/debug.go | 1 + src/cmd/compile/internal/base/flag.go | 1 + src/cmd/compile/internal/staticinit/sched.go | 4 ++++ test/fixedbugs/issue56778.go | 2 +- test/inline.go | 2 +- test/noinit.go | 2 +- 6 files changed, 9 insertions(+), 3 deletions(-) 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. -- 2.50.0