mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
Currently, cmd/compile optimizes `var a = true; var b = a` into `var a = true; var b = true`. But this may not be safe if we need to initialize any other global variables between `a` and `b`, and the initialization involves calling a user-defined function that reassigns `a`. This CL changes staticinit to keep track of the initialization expressions that we've seen so far, and to stop applying the staticcopy optimization once we've seen an initialization expression that might have modified another global variable within this package. To help identify affected initializers, this CL adds a -d=staticcopy flag to warn when a staticcopy is suppressed and turned into a dynamic copy. Currently, `go build -gcflags=all=-d=staticcopy std` reports only four instances: ``` encoding/xml/xml.go:1600:5: skipping static copy of HTMLEntity+0 with map[string]string{...} encoding/xml/xml.go:1869:5: skipping static copy of HTMLAutoClose+0 with []string{...} net/net.go:661:5: skipping static copy of .stmp_31+0 with poll.ErrNetClosing net/http/transport.go:2566:5: skipping static copy of errRequestCanceled+0 with ~R0 ``` Fixes #51913. Change-Id: Iab41cf6f84c44f7f960e4e62c28a8aeaade4fbcf Reviewed-on: https://go-review.googlesource.com/c/go/+/395541 Auto-Submit: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Heschi Kreinick <heschi@google.com>
72 lines
5.2 KiB
Go
72 lines
5.2 KiB
Go
// Copyright 2009 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Debug arguments, set by -d flag.
|
|
|
|
package base
|
|
|
|
// Debug holds the parsed debugging configuration values.
|
|
var Debug DebugFlags
|
|
|
|
// DebugFlags defines the debugging configuration values (see var Debug).
|
|
// Each struct field is a different value, named for the lower-case of the field name.
|
|
// Each field must be an int or string and must have a `help` struct tag.
|
|
//
|
|
// The -d option takes a comma-separated list of settings.
|
|
// Each setting is name=value; for ints, name is short for name=1.
|
|
type DebugFlags struct {
|
|
Append int `help:"print information about append compilation"`
|
|
Checkptr int `help:"instrument unsafe pointer conversions\n0: instrumentation disabled\n1: conversions involving unsafe.Pointer are instrumented\n2: conversions to unsafe.Pointer force heap allocation" concurrent:"ok"`
|
|
Closure int `help:"print information about closure compilation"`
|
|
Defer int `help:"print information about defer compilation"`
|
|
DisableNil int `help:"disable nil checks" concurrent:"ok"`
|
|
DumpInlFuncProps string `help:"dump function properties from inl heuristics to specified file"`
|
|
DumpPtrs int `help:"show Node pointers values in dump output"`
|
|
DwarfInl int `help:"print information about DWARF inlined function creation"`
|
|
EscapeMutationsCalls int `help:"print extra escape analysis diagnostics about mutations and calls" concurrent:"ok"`
|
|
Export int `help:"print export data"`
|
|
Fmahash string `help:"hash value for use in debugging platform-dependent multiply-add use" concurrent:"ok"`
|
|
GCAdjust int `help:"log adjustments to GOGC" concurrent:"ok"`
|
|
GCCheck int `help:"check heap/gc use by compiler" concurrent:"ok"`
|
|
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" concurrent:"ok"`
|
|
InterfaceCycles int `help:"allow anonymous interface cycles"`
|
|
Libfuzzer int `help:"enable coverage instrumentation for libfuzzer"`
|
|
LoopVar int `help:"shared (0, default), 1 (private loop variables), 2, private + log"`
|
|
LoopVarHash string `help:"for debugging changes in loop behavior. Overrides experiment and loopvar flag."`
|
|
LocationLists int `help:"print information about DWARF location list creation"`
|
|
Nil int `help:"print information about nil checks"`
|
|
NoOpenDefer int `help:"disable open-coded defers" concurrent:"ok"`
|
|
NoRefName int `help:"do not include referenced symbol names in object file" concurrent:"ok"`
|
|
PCTab string `help:"print named pc-value table\nOne of: pctospadj, pctofile, pctoline, pctoinline, pctopcdata"`
|
|
Panic int `help:"show all compiler panics"`
|
|
Reshape int `help:"print information about expression reshaping"`
|
|
Shapify int `help:"print information about shaping recursive types"`
|
|
Slice int `help:"print information about slice compilation"`
|
|
SoftFloat int `help:"force compiler to emit soft-float code" concurrent:"ok"`
|
|
StaticCopy int `help:"print information about missed static copies" concurrent:"ok"`
|
|
SyncFrames int `help:"how many writer stack frames to include at sync points in unified export data"`
|
|
TypeAssert int `help:"print information about type assertion inlining"`
|
|
WB int `help:"print information about write barriers"`
|
|
ABIWrap int `help:"print information about ABI wrapper generation"`
|
|
MayMoreStack string `help:"call named function before all stack growth checks" concurrent:"ok"`
|
|
PGODebug int `help:"debug profile-guided optimizations"`
|
|
PGOInline int `help:"enable profile-guided inlining" concurrent:"ok"`
|
|
PGOInlineCDFThreshold string `help:"cumulative threshold percentage for determining call sites as hot candidates for inlining" concurrent:"ok"`
|
|
PGOInlineBudget int `help:"inline budget for hot functions" concurrent:"ok"`
|
|
PGODevirtualize int `help:"enable profile-guided devirtualization" concurrent:"ok"`
|
|
WrapGlobalMapDbg int `help:"debug trace output for global map init wrapping"`
|
|
WrapGlobalMapCtl int `help:"global map init wrap control (0 => default, 1 => off, 2 => stress mode, no size cutoff)"`
|
|
ZeroCopy int `help:"enable zero-copy string->[]byte conversions" concurrent:"ok"`
|
|
|
|
ConcurrentOk bool // true if only concurrentOk flags seen
|
|
}
|
|
|
|
// DebugSSA is called to set a -d ssa/... option.
|
|
// If nil, those options are reported as invalid options.
|
|
// If DebugSSA returns a non-empty string, that text is reported as a compiler error.
|
|
var DebugSSA func(phase, flag string, val int, valString string) string
|