1
0
mirror of https://github.com/golang/go synced 2024-11-23 20:40:07 -07:00

cmd/compile/internal/gc: change flags to bool where possible

Some of the Debug[x] flags are actually boolean too, but not all, so
they need to be handled separately.

While here, change some obj.Flagstr and obj.Flagint64 calls to
directly use flag.StringVar and flag.Int64Var instead.

Change-Id: Iccedf6fed4328240ee2257f57fe6d66688f237c4
Reviewed-on: https://go-review.googlesource.com/22052
Reviewed-by: Michael Hudson-Doyle <michael.hudson@canonical.com>
This commit is contained in:
Matthew Dempsky 2016-04-13 18:37:18 -07:00
parent ae98045958
commit 980ab12ade
19 changed files with 88 additions and 87 deletions

View File

@ -316,11 +316,12 @@ func genhash(sym *Sym, t *Type) {
// for a struct containing a reflect.Value, which itself has // for a struct containing a reflect.Value, which itself has
// an unexported field of type unsafe.Pointer. // an unexported field of type unsafe.Pointer.
old_safemode := safemode old_safemode := safemode
safemode = false
safemode = 0
Disable_checknil++ Disable_checknil++
funccompile(fn) funccompile(fn)
Disable_checknil-- Disable_checknil--
safemode = old_safemode safemode = old_safemode
} }
@ -509,7 +510,7 @@ func geneq(sym *Sym, t *Type) {
// for a struct containing a reflect.Value, which itself has // for a struct containing a reflect.Value, which itself has
// an unexported field of type unsafe.Pointer. // an unexported field of type unsafe.Pointer.
old_safemode := safemode old_safemode := safemode
safemode = 0 safemode = false
// Disable checknils while compiling this code. // Disable checknils while compiling this code.
// We are comparing a struct or an array, // We are comparing a struct or an array,

View File

@ -261,7 +261,7 @@ func export(out *bufio.Writer, trace bool) int {
} }
// write compiler-specific flags // write compiler-specific flags
p.bool(safemode != 0) p.bool(safemode)
if p.trace { if p.trace {
p.tracef("\n") p.tracef("\n")
} }

View File

@ -419,7 +419,7 @@ func closuredebugruntimecheck(r *Node) {
Warnl(r.Lineno, "stack closure, captured vars = %v", r.Func.Cvars) Warnl(r.Lineno, "stack closure, captured vars = %v", r.Func.Cvars)
} }
} }
if compiling_runtime > 0 && r.Esc == EscHeap { if compiling_runtime && r.Esc == EscHeap {
yyerrorl(r.Lineno, "heap-allocated closure, not allowed in runtime.") yyerrorl(r.Lineno, "heap-allocated closure, not allowed in runtime.")
} }
} }

View File

@ -1330,7 +1330,7 @@ func makefuncsym(s *Sym) {
if isblanksym(s) { if isblanksym(s) {
return return
} }
if compiling_runtime != 0 && s.Name == "getg" { if compiling_runtime && s.Name == "getg" {
// runtime.getg() is not a real function and so does // runtime.getg() is not a real function and so does
// not get a funcsym. // not get a funcsym.
return return
@ -1440,7 +1440,7 @@ func (c *nowritebarrierrecChecker) visitcall(n *Node) {
if fn == nil || fn.Op != ONAME || fn.Class != PFUNC || fn.Name.Defn == nil { if fn == nil || fn.Op != ONAME || fn.Class != PFUNC || fn.Name.Defn == nil {
return return
} }
if (compiling_runtime != 0 || fn.Sym.Pkg == Runtimepkg) && fn.Sym.Name == "allocm" { if (compiling_runtime || fn.Sym.Pkg == Runtimepkg) && fn.Sym.Name == "allocm" {
return return
} }
defn := fn.Name.Defn defn := fn.Name.Defn

View File

@ -15,8 +15,8 @@ import (
) )
var ( var (
newexport int // if set, use new export format newexport bool // if set, use new export format
Debug_export int // if set, print debugging information about export data Debug_export int // if set, print debugging information about export data
exportsize int exportsize int
) )
@ -377,7 +377,7 @@ func dumpexport() {
} }
size := 0 // size of export section without enclosing markers size := 0 // size of export section without enclosing markers
if forceNewExport || newexport != 0 { if forceNewExport || newexport {
// binary export // binary export
// The linker also looks for the $$ marker - use char after $$ to distinguish format. // The linker also looks for the $$ marker - use char after $$ to distinguish format.
exportf("\n$$B\n") // indicate binary format exportf("\n$$B\n") // indicate binary format
@ -417,7 +417,7 @@ func dumpexport() {
exportf("\n$$\n") // indicate textual format exportf("\n$$\n") // indicate textual format
exportsize = 0 exportsize = 0
exportf("package %s", localpkg.Name) exportf("package %s", localpkg.Name)
if safemode != 0 { if safemode {
exportf(" safe") exportf(" safe")
} }
exportf("\n") exportf("\n")

View File

@ -246,7 +246,7 @@ func cgen_dcl(n *Node) {
if n.Class&PHEAP == 0 { if n.Class&PHEAP == 0 {
return return
} }
if compiling_runtime != 0 { if compiling_runtime {
Yyerror("%v escapes to heap, not allowed in runtime.", n) Yyerror("%v escapes to heap, not allowed in runtime.", n)
} }
if prealloc[n] == nil { if prealloc[n] == nil {

View File

@ -144,9 +144,9 @@ var nsyntaxerrors int
var decldepth int32 var decldepth int32
var safemode int var safemode bool
var nolocalimports int var nolocalimports bool
var Debug [256]int var Debug [256]int
@ -261,21 +261,21 @@ var Funcdepth int32
var typecheckok bool var typecheckok bool
var compiling_runtime int var compiling_runtime bool
var compiling_wrappers int var compiling_wrappers int
var use_writebarrier int var use_writebarrier bool
var pure_go int var pure_go bool
var flag_installsuffix string var flag_installsuffix string
var flag_race int var flag_race bool
var flag_msan int var flag_msan bool
var flag_largemodel int var flag_largemodel bool
// Whether we are adding any sort of code instrumentation, such as // Whether we are adding any sort of code instrumentation, such as
// when the race detector is enabled. // when the race detector is enabled.
@ -285,7 +285,7 @@ var debuglive int
var Ctxt *obj.Link var Ctxt *obj.Link
var writearchive int var writearchive bool
var bstdout *bufio.Writer var bstdout *bufio.Writer

View File

@ -71,7 +71,7 @@ func typecheckinl(fn *Node) {
} }
save_safemode := safemode save_safemode := safemode
safemode = 0 safemode = false
savefn := Curfn savefn := Curfn
Curfn = fn Curfn = fn
@ -492,7 +492,7 @@ func mkinlcall(n *Node, fn *Node, isddd bool) *Node {
pkg := fnpkg(fn) pkg := fnpkg(fn)
if pkg != localpkg && pkg != nil { if pkg != localpkg && pkg != nil {
safemode = 0 safemode = false
} }
n = mkinlcall1(n, fn, isddd) n = mkinlcall1(n, fn, isddd)
safemode = save_safemode safemode = save_safemode

View File

@ -914,17 +914,17 @@ func (l *lexer) getlinepragma() rune {
case "go:noinline": case "go:noinline":
l.pragma |= Noinline l.pragma |= Noinline
case "go:systemstack": case "go:systemstack":
if compiling_runtime == 0 { if !compiling_runtime {
Yyerror("//go:systemstack only allowed in runtime") Yyerror("//go:systemstack only allowed in runtime")
} }
l.pragma |= Systemstack l.pragma |= Systemstack
case "go:nowritebarrier": case "go:nowritebarrier":
if compiling_runtime == 0 { if !compiling_runtime {
Yyerror("//go:nowritebarrier only allowed in runtime") Yyerror("//go:nowritebarrier only allowed in runtime")
} }
l.pragma |= Nowritebarrier l.pragma |= Nowritebarrier
case "go:nowritebarrierrec": case "go:nowritebarrierrec":
if compiling_runtime == 0 { if !compiling_runtime {
Yyerror("//go:nowritebarrierrec only allowed in runtime") Yyerror("//go:nowritebarrierrec only allowed in runtime")
} }
l.pragma |= Nowritebarrierrec | Nowritebarrier // implies Nowritebarrier l.pragma |= Nowritebarrierrec | Nowritebarrier // implies Nowritebarrier

View File

@ -142,15 +142,14 @@ func Main() {
Nacl = goos == "nacl" Nacl = goos == "nacl"
if Nacl { if Nacl {
flag_largemodel = 1 flag_largemodel = true
} }
outfile = "" flag.BoolVar(&compiling_runtime, "+", false, "compiling runtime")
obj.Flagcount("+", "compiling runtime", &compiling_runtime)
obj.Flagcount("%", "debug non-static initializers", &Debug['%']) obj.Flagcount("%", "debug non-static initializers", &Debug['%'])
obj.Flagcount("A", "for bootstrapping, allow 'any' type", &Debug['A']) obj.Flagcount("A", "for bootstrapping, allow 'any' type", &Debug['A'])
obj.Flagcount("B", "disable bounds checking", &Debug['B']) obj.Flagcount("B", "disable bounds checking", &Debug['B'])
obj.Flagstr("D", "set relative `path` for local imports", &localimport) flag.StringVar(&localimport, "D", "", "set relative `path` for local imports")
obj.Flagcount("E", "debug symbol export", &Debug['E']) obj.Flagcount("E", "debug symbol export", &Debug['E'])
obj.Flagfn1("I", "add `directory` to import search path", addidir) obj.Flagfn1("I", "add `directory` to import search path", addidir)
obj.Flagcount("K", "debug missing line numbers", &Debug['K']) obj.Flagcount("K", "debug missing line numbers", &Debug['K'])
@ -162,57 +161,59 @@ func Main() {
obj.Flagcount("S", "print assembly listing", &Debug['S']) obj.Flagcount("S", "print assembly listing", &Debug['S'])
obj.Flagfn0("V", "print compiler version", doversion) obj.Flagfn0("V", "print compiler version", doversion)
obj.Flagcount("W", "debug parse tree after type checking", &Debug['W']) obj.Flagcount("W", "debug parse tree after type checking", &Debug['W'])
obj.Flagstr("asmhdr", "write assembly header to `file`", &asmhdr) flag.StringVar(&asmhdr, "asmhdr", "", "write assembly header to `file`")
obj.Flagstr("buildid", "record `id` as the build id in the export metadata", &buildid) flag.StringVar(&buildid, "buildid", "", "record `id` as the build id in the export metadata")
obj.Flagcount("complete", "compiling complete package (no C or assembly)", &pure_go) flag.BoolVar(&pure_go, "complete", false, "compiling complete package (no C or assembly)")
obj.Flagstr("d", "print debug information about items in `list`", &debugstr) flag.StringVar(&debugstr, "d", "", "print debug information about items in `list`")
obj.Flagcount("e", "no limit on number of errors reported", &Debug['e']) obj.Flagcount("e", "no limit on number of errors reported", &Debug['e'])
obj.Flagcount("f", "debug stack frames", &Debug['f']) obj.Flagcount("f", "debug stack frames", &Debug['f'])
obj.Flagcount("g", "debug code generation", &Debug['g']) obj.Flagcount("g", "debug code generation", &Debug['g'])
obj.Flagcount("h", "halt on error", &Debug['h']) obj.Flagcount("h", "halt on error", &Debug['h'])
obj.Flagcount("i", "debug line number stack", &Debug['i']) obj.Flagcount("i", "debug line number stack", &Debug['i'])
obj.Flagfn1("importmap", "add `definition` of the form source=actual to import map", addImportMap) obj.Flagfn1("importmap", "add `definition` of the form source=actual to import map", addImportMap)
obj.Flagstr("installsuffix", "set pkg directory `suffix`", &flag_installsuffix) flag.StringVar(&flag_installsuffix, "installsuffix", "", "set pkg directory `suffix`")
obj.Flagcount("j", "debug runtime-initialized variables", &Debug['j']) obj.Flagcount("j", "debug runtime-initialized variables", &Debug['j'])
obj.Flagcount("l", "disable inlining", &Debug['l']) obj.Flagcount("l", "disable inlining", &Debug['l'])
obj.Flagcount("live", "debug liveness analysis", &debuglive) obj.Flagcount("live", "debug liveness analysis", &debuglive)
obj.Flagcount("m", "print optimization decisions", &Debug['m']) obj.Flagcount("m", "print optimization decisions", &Debug['m'])
obj.Flagcount("msan", "build code compatible with C/C++ memory sanitizer", &flag_msan) flag.BoolVar(&flag_msan, "msan", false, "build code compatible with C/C++ memory sanitizer")
obj.Flagcount("newexport", "use new export format", &newexport) // TODO(gri) remove eventually (issue 13241) flag.BoolVar(&newexport, "newexport", false, "use new export format") // TODO(gri) remove eventually (issue 13241)
obj.Flagcount("nolocalimports", "reject local (relative) imports", &nolocalimports) flag.BoolVar(&nolocalimports, "nolocalimports", false, "reject local (relative) imports")
obj.Flagstr("o", "write output to `file`", &outfile) flag.StringVar(&outfile, "o", "", "write output to `file`")
obj.Flagstr("p", "set expected package import `path`", &myimportpath) flag.StringVar(&myimportpath, "p", "", "set expected package import `path`")
obj.Flagcount("pack", "write package file instead of object file", &writearchive) flag.BoolVar(&writearchive, "pack", false, "write package file instead of object file")
obj.Flagcount("r", "debug generated wrappers", &Debug['r']) obj.Flagcount("r", "debug generated wrappers", &Debug['r'])
obj.Flagcount("race", "enable race detector", &flag_race) flag.BoolVar(&flag_race, "race", false, "enable race detector")
obj.Flagcount("s", "warn about composite literals that can be simplified", &Debug['s']) obj.Flagcount("s", "warn about composite literals that can be simplified", &Debug['s'])
obj.Flagstr("trimpath", "remove `prefix` from recorded source file paths", &Ctxt.LineHist.TrimPathPrefix) flag.StringVar(&Ctxt.LineHist.TrimPathPrefix, "trimpath", "", "remove `prefix` from recorded source file paths")
obj.Flagcount("u", "reject unsafe code", &safemode) flag.BoolVar(&safemode, "u", false, "reject unsafe code")
obj.Flagcount("v", "increase debug verbosity", &Debug['v']) obj.Flagcount("v", "increase debug verbosity", &Debug['v'])
obj.Flagcount("w", "debug type checking", &Debug['w']) obj.Flagcount("w", "debug type checking", &Debug['w'])
use_writebarrier = 1 flag.BoolVar(&use_writebarrier, "wb", true, "enable write barrier")
obj.Flagcount("wb", "enable write barrier", &use_writebarrier)
obj.Flagcount("x", "debug lexer", &Debug['x']) obj.Flagcount("x", "debug lexer", &Debug['x'])
obj.Flagcount("y", "debug declarations in canned imports (with -d)", &Debug['y']) obj.Flagcount("y", "debug declarations in canned imports (with -d)", &Debug['y'])
var flag_shared int var flag_shared bool
var flag_dynlink bool var flag_dynlink bool
if supportsDynlink(Thearch.LinkArch.Arch) { if supportsDynlink(Thearch.LinkArch.Arch) {
obj.Flagcount("shared", "generate code that can be linked into a shared library", &flag_shared) flag.BoolVar(&flag_shared, "shared", false, "generate code that can be linked into a shared library")
flag.BoolVar(&flag_dynlink, "dynlink", false, "support references to Go symbols defined in other shared libraries") flag.BoolVar(&flag_dynlink, "dynlink", false, "support references to Go symbols defined in other shared libraries")
} }
if Thearch.LinkArch.Family == sys.AMD64 { if Thearch.LinkArch.Family == sys.AMD64 {
obj.Flagcount("largemodel", "generate code that assumes a large memory model", &flag_largemodel) flag.BoolVar(&flag_largemodel, "largemodel", false, "generate code that assumes a large memory model")
} }
obj.Flagstr("cpuprofile", "write cpu profile to `file`", &cpuprofile) flag.StringVar(&cpuprofile, "cpuprofile", "", "write cpu profile to `file`")
obj.Flagstr("memprofile", "write memory profile to `file`", &memprofile) flag.StringVar(&memprofile, "memprofile", "", "write memory profile to `file`")
obj.Flagint64("memprofilerate", "set runtime.MemProfileRate to `rate`", &memprofilerate) flag.Int64Var(&memprofilerate, "memprofilerate", 0, "set runtime.MemProfileRate to `rate`")
flag.BoolVar(&ssaEnabled, "ssa", true, "use SSA backend to generate code") flag.BoolVar(&ssaEnabled, "ssa", true, "use SSA backend to generate code")
obj.Flagparse(usage) obj.Flagparse(usage)
if flag_dynlink { if flag_dynlink {
flag_shared = 1 flag_shared = true
}
if flag_shared {
// TODO(mdempsky): Change Flag_shared to bool.
Ctxt.Flag_shared = 1
} }
Ctxt.Flag_shared = int32(flag_shared)
Ctxt.Flag_dynlink = flag_dynlink Ctxt.Flag_dynlink = flag_dynlink
Ctxt.Flag_optimize = Debug['N'] == 0 Ctxt.Flag_optimize = Debug['N'] == 0
@ -225,17 +226,17 @@ func Main() {
startProfile() startProfile()
if flag_race != 0 { if flag_race {
racepkg = mkpkg("runtime/race") racepkg = mkpkg("runtime/race")
racepkg.Name = "race" racepkg.Name = "race"
} }
if flag_msan != 0 { if flag_msan {
msanpkg = mkpkg("runtime/msan") msanpkg = mkpkg("runtime/msan")
msanpkg.Name = "msan" msanpkg.Name = "msan"
} }
if flag_race != 0 && flag_msan != 0 { if flag_race && flag_msan {
log.Fatal("cannot use both -race and -msan") log.Fatal("cannot use both -race and -msan")
} else if flag_race != 0 || flag_msan != 0 { } else if flag_race || flag_msan {
instrumenting = true instrumenting = true
} }
@ -471,7 +472,7 @@ func Main() {
fninit(xtop) fninit(xtop)
} }
if compiling_runtime != 0 { if compiling_runtime {
checknowritebarrierrec() checknowritebarrierrec()
} }
@ -569,7 +570,7 @@ func islocalname(name string) bool {
func findpkg(name string) (file string, ok bool) { func findpkg(name string) (file string, ok bool) {
if islocalname(name) { if islocalname(name) {
if safemode != 0 || nolocalimports != 0 { if safemode || nolocalimports {
return "", false return "", false
} }
@ -612,10 +613,10 @@ func findpkg(name string) (file string, ok bool) {
if flag_installsuffix != "" { if flag_installsuffix != "" {
suffixsep = "_" suffixsep = "_"
suffix = flag_installsuffix suffix = flag_installsuffix
} else if flag_race != 0 { } else if flag_race {
suffixsep = "_" suffixsep = "_"
suffix = "race" suffix = "race"
} else if flag_msan != 0 { } else if flag_msan {
suffixsep = "_" suffixsep = "_"
suffix = "msan" suffix = "msan"
} }
@ -694,7 +695,7 @@ func importfile(f *Val, indent []byte) {
} }
if path_ == "unsafe" { if path_ == "unsafe" {
if safemode != 0 { if safemode {
Yyerror("cannot import package unsafe") Yyerror("cannot import package unsafe")
errorexit() errorexit()
} }
@ -818,7 +819,7 @@ func importfile(f *Val, indent []byte) {
errorexit() errorexit()
} }
if safemode != 0 && !importpkg.Safe { if safemode && !importpkg.Safe {
Yyerror("cannot import unsafe package %q", importpkg.Path) Yyerror("cannot import unsafe package %q", importpkg.Path)
} }
} }
@ -896,7 +897,7 @@ func mkpackage(pkgname string) {
p = p[:i] p = p[:i]
} }
suffix := ".o" suffix := ".o"
if writearchive > 0 { if writearchive {
suffix = ".a" suffix = ".a"
} }
outfile = p + suffix outfile = p + suffix

View File

@ -33,7 +33,7 @@ func dumpobj() {
startobj := int64(0) startobj := int64(0)
var arhdr [ArhdrSize]byte var arhdr [ArhdrSize]byte
if writearchive != 0 { if writearchive {
bout.WriteString("!<arch>\n") bout.WriteString("!<arch>\n")
arhdr = [ArhdrSize]byte{} arhdr = [ArhdrSize]byte{}
bout.Write(arhdr[:]) bout.Write(arhdr[:])
@ -43,7 +43,7 @@ func dumpobj() {
fmt.Fprintf(bout, "go object %s %s %s %s\n", obj.Getgoos(), obj.Getgoarch(), obj.Getgoversion(), obj.Expstring()) fmt.Fprintf(bout, "go object %s %s %s %s\n", obj.Getgoos(), obj.Getgoarch(), obj.Getgoversion(), obj.Expstring())
dumpexport() dumpexport()
if writearchive != 0 { if writearchive {
bout.Flush() bout.Flush()
size := bout.Offset() - startobj size := bout.Offset() - startobj
if size&1 != 0 { if size&1 != 0 {
@ -62,7 +62,7 @@ func dumpobj() {
} }
if pragcgobuf != "" { if pragcgobuf != "" {
if writearchive != 0 { if writearchive {
// write empty export section; must be before cgo section // write empty export section; must be before cgo section
fmt.Fprintf(bout, "\n$$\n\n$$\n\n") fmt.Fprintf(bout, "\n$$\n\n$$\n\n")
} }
@ -90,7 +90,7 @@ func dumpobj() {
dumpdata() dumpdata()
obj.Writeobjdirect(Ctxt, bout) obj.Writeobjdirect(Ctxt, bout)
if writearchive != 0 { if writearchive {
bout.Flush() bout.Flush()
size := bout.Offset() - startobj size := bout.Offset() - startobj
if size&1 != 0 { if size&1 != 0 {

View File

@ -364,7 +364,7 @@ func compile(fn *Node) {
dowidth(Curfn.Type) dowidth(Curfn.Type)
if len(fn.Nbody.Slice()) == 0 { if len(fn.Nbody.Slice()) == 0 {
if pure_go != 0 || strings.HasPrefix(fn.Func.Nname.Sym.Name, "init.") { if pure_go || strings.HasPrefix(fn.Func.Nname.Sym.Name, "init.") {
Yyerror("missing function body for %q", fn.Func.Nname.Sym.Name) Yyerror("missing function body for %q", fn.Func.Nname.Sym.Name)
return return
} }

View File

@ -54,14 +54,14 @@ func instrument(fn *Node) {
return return
} }
if flag_race == 0 || !ispkgin(norace_inst_pkgs) { if !flag_race || !ispkgin(norace_inst_pkgs) {
instrumentlist(fn.Nbody, nil) instrumentlist(fn.Nbody, nil)
// nothing interesting for race detector in fn->enter // nothing interesting for race detector in fn->enter
instrumentlist(fn.Func.Exit, nil) instrumentlist(fn.Func.Exit, nil)
} }
if flag_race != 0 { if flag_race {
// nodpc is the PC of the caller as extracted by // nodpc is the PC of the caller as extracted by
// getcallerpc. We use -widthptr(FP) for x86. // getcallerpc. We use -widthptr(FP) for x86.
// BUG: this will not work on arm. // BUG: this will not work on arm.
@ -503,7 +503,7 @@ func callinstr(np **Node, init *Nodes, wr int, skip int) bool {
n = treecopy(n, 0) n = treecopy(n, 0)
makeaddable(n) makeaddable(n)
var f *Node var f *Node
if flag_msan != 0 { if flag_msan {
name := "msanread" name := "msanread"
if wr != 0 { if wr != 0 {
name = "msanwrite" name = "msanwrite"
@ -515,7 +515,7 @@ func callinstr(np **Node, init *Nodes, wr int, skip int) bool {
Fatalf("instrument: %v badwidth", t) Fatalf("instrument: %v badwidth", t)
} }
f = mkcall(name, nil, init, uintptraddr(n), Nodintconst(w)) f = mkcall(name, nil, init, uintptraddr(n), Nodintconst(w))
} else if flag_race != 0 && (t.IsStruct() || t.IsArray()) { } else if flag_race && (t.IsStruct() || t.IsArray()) {
name := "racereadrange" name := "racereadrange"
if wr != 0 { if wr != 0 {
name = "racewriterange" name = "racewriterange"
@ -527,7 +527,7 @@ func callinstr(np **Node, init *Nodes, wr int, skip int) bool {
Fatalf("instrument: %v badwidth", t) Fatalf("instrument: %v badwidth", t)
} }
f = mkcall(name, nil, init, uintptraddr(n), Nodintconst(w)) f = mkcall(name, nil, init, uintptraddr(n), Nodintconst(w))
} else if flag_race != 0 { } else if flag_race {
name := "raceread" name := "raceread"
if wr != 0 { if wr != 0 {
name = "racewrite" name = "racewrite"

View File

@ -1424,10 +1424,10 @@ func dumptypestructs() {
// add paths for runtime and main, which 6l imports implicitly. // add paths for runtime and main, which 6l imports implicitly.
dimportpath(Runtimepkg) dimportpath(Runtimepkg)
if flag_race != 0 { if flag_race {
dimportpath(racepkg) dimportpath(racepkg)
} }
if flag_msan != 0 { if flag_msan {
dimportpath(msanpkg) dimportpath(msanpkg)
} }
dimportpath(mkpkg("main")) dimportpath(mkpkg("main"))

View File

@ -554,7 +554,7 @@ func (s *state) stmt(n *Node) {
case OCALLFUNC, OCALLMETH, OCALLINTER: case OCALLFUNC, OCALLMETH, OCALLINTER:
s.call(n, callNormal) s.call(n, callNormal)
if n.Op == OCALLFUNC && n.Left.Op == ONAME && n.Left.Class == PFUNC && if n.Op == OCALLFUNC && n.Left.Op == ONAME && n.Left.Class == PFUNC &&
(compiling_runtime != 0 && n.Left.Sym.Name == "throw" || (compiling_runtime && n.Left.Sym.Name == "throw" ||
n.Left.Sym.Pkg == Runtimepkg && (n.Left.Sym.Name == "gopanic" || n.Left.Sym.Name == "selectgo" || n.Left.Sym.Name == "block")) { n.Left.Sym.Pkg == Runtimepkg && (n.Left.Sym.Name == "gopanic" || n.Left.Sym.Name == "selectgo" || n.Left.Sym.Name == "block")) {
m := s.mem() m := s.mem()
b := s.endBlock() b := s.endBlock()
@ -579,7 +579,7 @@ func (s *state) stmt(n *Node) {
if n.Left.Class&PHEAP == 0 { if n.Left.Class&PHEAP == 0 {
return return
} }
if compiling_runtime != 0 { if compiling_runtime {
Fatalf("%v escapes to heap, not allowed in runtime.", n) Fatalf("%v escapes to heap, not allowed in runtime.", n)
} }

View File

@ -750,7 +750,7 @@ func assignop(src *Type, dst *Type, why *string) Op {
// TODO(rsc,lvd): This behaves poorly in the presence of inlining. // TODO(rsc,lvd): This behaves poorly in the presence of inlining.
// https://golang.org/issue/2795 // https://golang.org/issue/2795
if safemode != 0 && importpkg == nil && src != nil && src.Etype == TUNSAFEPTR { if safemode && importpkg == nil && src != nil && src.Etype == TUNSAFEPTR {
Yyerror("cannot use unsafe.Pointer") Yyerror("cannot use unsafe.Pointer")
errorexit() errorexit()
} }

View File

@ -1354,7 +1354,7 @@ OpSwitch:
if t.Results().NumFields() == 1 { if t.Results().NumFields() == 1 {
n.Type = l.Type.Results().Field(0).Type n.Type = l.Type.Results().Field(0).Type
if n.Op == OCALLFUNC && n.Left.Op == ONAME && (compiling_runtime != 0 || n.Left.Sym.Pkg == Runtimepkg) && n.Left.Sym.Name == "getg" { if n.Op == OCALLFUNC && n.Left.Op == ONAME && (compiling_runtime || n.Left.Sym.Pkg == Runtimepkg) && n.Left.Sym.Name == "getg" {
// Emit code for runtime.getg() directly instead of calling function. // Emit code for runtime.getg() directly instead of calling function.
// Most such rewrites (for example the similar one for math.Sqrt) should be done in walk, // Most such rewrites (for example the similar one for math.Sqrt) should be done in walk,
// so that the ordering pass can make sure to preserve the semantics of the original code // so that the ordering pass can make sure to preserve the semantics of the original code
@ -2176,7 +2176,7 @@ OpSwitch:
} }
} }
if safemode != 0 && incannedimport == 0 && importpkg == nil && compiling_wrappers == 0 && t != nil && t.Etype == TUNSAFEPTR { if safemode && incannedimport == 0 && importpkg == nil && compiling_wrappers == 0 && t != nil && t.Etype == TUNSAFEPTR {
Yyerror("cannot use unsafe.Pointer") Yyerror("cannot use unsafe.Pointer")
} }

View File

@ -9,7 +9,7 @@ func unsafenmagic(nn *Node) *Node {
fn := nn.Left fn := nn.Left
args := nn.List args := nn.List
if safemode != 0 || fn == nil || fn.Op != ONAME { if safemode || fn == nil || fn.Op != ONAME {
return nil return nil
} }
s := fn.Sym s := fn.Sym

View File

@ -594,8 +594,7 @@ opswitch:
// for a struct containing a reflect.Value, which itself has // for a struct containing a reflect.Value, which itself has
// an unexported field of type unsafe.Pointer. // an unexported field of type unsafe.Pointer.
old_safemode := safemode old_safemode := safemode
safemode = false
safemode = 0
n = walkcompare(n, init) n = walkcompare(n, init)
safemode = old_safemode safemode = old_safemode
@ -1938,7 +1937,7 @@ func walkprint(nn *Node, init *Nodes) *Node {
on = substArgTypes(on, n.Type) // any-1 on = substArgTypes(on, n.Type) // any-1
} else if Isint[et] { } else if Isint[et] {
if et == TUINT64 { if et == TUINT64 {
if (t.Sym.Pkg == Runtimepkg || compiling_runtime != 0) && t.Sym.Name == "hex" { if (t.Sym.Pkg == Runtimepkg || compiling_runtime) && t.Sym.Name == "hex" {
on = syslook("printhex") on = syslook("printhex")
} else { } else {
on = syslook("printuint") on = syslook("printuint")
@ -2041,7 +2040,7 @@ func isglobal(n *Node) bool {
// Do we need a write barrier for the assignment l = r? // Do we need a write barrier for the assignment l = r?
func needwritebarrier(l *Node, r *Node) bool { func needwritebarrier(l *Node, r *Node) bool {
if use_writebarrier == 0 { if !use_writebarrier {
return false return false
} }
@ -2550,7 +2549,7 @@ func paramstoheap(params *Type, out bool) []*Node {
} }
// generate allocation & copying code // generate allocation & copying code
if compiling_runtime != 0 { if compiling_runtime {
Yyerror("%v escapes to heap, not allowed in runtime.", v) Yyerror("%v escapes to heap, not allowed in runtime.", v)
} }
if prealloc[v] == nil { if prealloc[v] == nil {