]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/gc: change flags to bool where possible
authorMatthew Dempsky <mdempsky@google.com>
Thu, 14 Apr 2016 01:37:18 +0000 (18:37 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 14 Apr 2016 02:10:35 +0000 (02:10 +0000)
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>
19 files changed:
src/cmd/compile/internal/gc/alg.go
src/cmd/compile/internal/gc/bexport.go
src/cmd/compile/internal/gc/closure.go
src/cmd/compile/internal/gc/dcl.go
src/cmd/compile/internal/gc/export.go
src/cmd/compile/internal/gc/gen.go
src/cmd/compile/internal/gc/go.go
src/cmd/compile/internal/gc/inl.go
src/cmd/compile/internal/gc/lex.go
src/cmd/compile/internal/gc/main.go
src/cmd/compile/internal/gc/obj.go
src/cmd/compile/internal/gc/pgen.go
src/cmd/compile/internal/gc/racewalk.go
src/cmd/compile/internal/gc/reflect.go
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/typecheck.go
src/cmd/compile/internal/gc/unsafe.go
src/cmd/compile/internal/gc/walk.go

index e9b5afe8381c1b96360b18c53bb96961b24b6f6a..6e85438610284e3abf55dbf3d18385001265574b 100644 (file)
@@ -316,11 +316,12 @@ func genhash(sym *Sym, t *Type) {
        // for a struct containing a reflect.Value, which itself has
        // an unexported field of type unsafe.Pointer.
        old_safemode := safemode
+       safemode = false
 
-       safemode = 0
        Disable_checknil++
        funccompile(fn)
        Disable_checknil--
+
        safemode = old_safemode
 }
 
@@ -509,7 +510,7 @@ func geneq(sym *Sym, t *Type) {
        // for a struct containing a reflect.Value, which itself has
        // an unexported field of type unsafe.Pointer.
        old_safemode := safemode
-       safemode = 0
+       safemode = false
 
        // Disable checknils while compiling this code.
        // We are comparing a struct or an array,
index eef2e2200d96cd2f0b519880a2d718a4e1e343a5..e5fa3c39a6549bdfba47c7635eb298d8ebb696ea 100644 (file)
@@ -261,7 +261,7 @@ func export(out *bufio.Writer, trace bool) int {
        }
 
        // write compiler-specific flags
-       p.bool(safemode != 0)
+       p.bool(safemode)
        if p.trace {
                p.tracef("\n")
        }
index 80c8d309afbb93d4bd9dbc0b67dec3dcba53f2ef..db4eb3f14ddad2c0ae8de74ea429846cb9f25841 100644 (file)
@@ -419,7 +419,7 @@ func closuredebugruntimecheck(r *Node) {
                        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.")
        }
 }
index c652c65962296d0414ad78cf54bdaab7607af2ec..e1028f681c8470466e27f7a2cd772bc0ffac4fd9 100644 (file)
@@ -1330,7 +1330,7 @@ func makefuncsym(s *Sym) {
        if isblanksym(s) {
                return
        }
-       if compiling_runtime != 0 && s.Name == "getg" {
+       if compiling_runtime && s.Name == "getg" {
                // runtime.getg() is not a real function and so does
                // not get a funcsym.
                return
@@ -1440,7 +1440,7 @@ func (c *nowritebarrierrecChecker) visitcall(n *Node) {
        if fn == nil || fn.Op != ONAME || fn.Class != PFUNC || fn.Name.Defn == nil {
                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
        }
        defn := fn.Name.Defn
index ae36657a6539420a32d0f49bbdc418bdc403cb0e..cfe192f3ba726ffa85f0bf8d3ff9789fcc1860bc 100644 (file)
@@ -15,8 +15,8 @@ import (
 )
 
 var (
-       newexport    int // if set, use new export format
-       Debug_export int // if set, print debugging information about export data
+       newexport    bool // if set, use new export format
+       Debug_export int  // if set, print debugging information about export data
        exportsize   int
 )
 
@@ -377,7 +377,7 @@ func dumpexport() {
        }
 
        size := 0 // size of export section without enclosing markers
-       if forceNewExport || newexport != 0 {
+       if forceNewExport || newexport {
                // binary export
                // The linker also looks for the $$ marker - use char after $$ to distinguish format.
                exportf("\n$$B\n") // indicate binary format
@@ -417,7 +417,7 @@ func dumpexport() {
                exportf("\n$$\n") // indicate textual format
                exportsize = 0
                exportf("package %s", localpkg.Name)
-               if safemode != 0 {
+               if safemode {
                        exportf(" safe")
                }
                exportf("\n")
index 7527452c93c22980a3a0e2c88ce63c9c47711a4c..cc624cce7ab3faf80cb36a92ec97ad8b0fae92e9 100644 (file)
@@ -246,7 +246,7 @@ func cgen_dcl(n *Node) {
        if n.Class&PHEAP == 0 {
                return
        }
-       if compiling_runtime != 0 {
+       if compiling_runtime {
                Yyerror("%v escapes to heap, not allowed in runtime.", n)
        }
        if prealloc[n] == nil {
index 8411d2d0ac04d361e053cf5b2c2098859a3aa50e..af9aaf0dae76b15a73aa0d637d6d01295581c0b9 100644 (file)
@@ -144,9 +144,9 @@ var nsyntaxerrors int
 
 var decldepth int32
 
-var safemode int
+var safemode bool
 
-var nolocalimports int
+var nolocalimports bool
 
 var Debug [256]int
 
@@ -261,21 +261,21 @@ var Funcdepth int32
 
 var typecheckok bool
 
-var compiling_runtime int
+var compiling_runtime bool
 
 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_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
 // when the race detector is enabled.
@@ -285,7 +285,7 @@ var debuglive int
 
 var Ctxt *obj.Link
 
-var writearchive int
+var writearchive bool
 
 var bstdout *bufio.Writer
 
index ea2394e7f9eda3d40b69edb67a67eaa63bb422ad..f9e425618baed3443af9ba69fa68d6a6a5ec5e94 100644 (file)
@@ -71,7 +71,7 @@ func typecheckinl(fn *Node) {
        }
 
        save_safemode := safemode
-       safemode = 0
+       safemode = false
 
        savefn := Curfn
        Curfn = fn
@@ -492,7 +492,7 @@ func mkinlcall(n *Node, fn *Node, isddd bool) *Node {
        pkg := fnpkg(fn)
 
        if pkg != localpkg && pkg != nil {
-               safemode = 0
+               safemode = false
        }
        n = mkinlcall1(n, fn, isddd)
        safemode = save_safemode
index 4b95bb712458b98f3bfeff48a415698f4045ae33..09fed98985d392f5ea312870bd4da5288d9b2696 100644 (file)
@@ -914,17 +914,17 @@ func (l *lexer) getlinepragma() rune {
                case "go:noinline":
                        l.pragma |= Noinline
                case "go:systemstack":
-                       if compiling_runtime == 0 {
+                       if !compiling_runtime {
                                Yyerror("//go:systemstack only allowed in runtime")
                        }
                        l.pragma |= Systemstack
                case "go:nowritebarrier":
-                       if compiling_runtime == 0 {
+                       if !compiling_runtime {
                                Yyerror("//go:nowritebarrier only allowed in runtime")
                        }
                        l.pragma |= Nowritebarrier
                case "go:nowritebarrierrec":
-                       if compiling_runtime == 0 {
+                       if !compiling_runtime {
                                Yyerror("//go:nowritebarrierrec only allowed in runtime")
                        }
                        l.pragma |= Nowritebarrierrec | Nowritebarrier // implies Nowritebarrier
index 45a510d577d9432aeb00eee0bd8bce7bf36e058a..f41097b83b10deda7483c1dda0526d24fbca3d0b 100644 (file)
@@ -142,15 +142,14 @@ func Main() {
 
        Nacl = goos == "nacl"
        if Nacl {
-               flag_largemodel = 1
+               flag_largemodel = true
        }
 
-       outfile = ""
-       obj.Flagcount("+", "compiling runtime", &compiling_runtime)
+       flag.BoolVar(&compiling_runtime, "+", false, "compiling runtime")
        obj.Flagcount("%", "debug non-static initializers", &Debug['%'])
        obj.Flagcount("A", "for bootstrapping, allow 'any' type", &Debug['A'])
        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.Flagfn1("I", "add `directory` to import search path", addidir)
        obj.Flagcount("K", "debug missing line numbers", &Debug['K'])
@@ -162,57 +161,59 @@ func Main() {
        obj.Flagcount("S", "print assembly listing", &Debug['S'])
        obj.Flagfn0("V", "print compiler version", doversion)
        obj.Flagcount("W", "debug parse tree after type checking", &Debug['W'])
-       obj.Flagstr("asmhdr", "write assembly header to `file`", &asmhdr)
-       obj.Flagstr("buildid", "record `id` as the build id in the export metadata", &buildid)
-       obj.Flagcount("complete", "compiling complete package (no C or assembly)", &pure_go)
-       obj.Flagstr("d", "print debug information about items in `list`", &debugstr)
+       flag.StringVar(&asmhdr, "asmhdr", "", "write assembly header to `file`")
+       flag.StringVar(&buildid, "buildid", "", "record `id` as the build id in the export metadata")
+       flag.BoolVar(&pure_go, "complete", false, "compiling complete package (no C or assembly)")
+       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("f", "debug stack frames", &Debug['f'])
        obj.Flagcount("g", "debug code generation", &Debug['g'])
        obj.Flagcount("h", "halt on error", &Debug['h'])
        obj.Flagcount("i", "debug line number stack", &Debug['i'])
        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("l", "disable inlining", &Debug['l'])
        obj.Flagcount("live", "debug liveness analysis", &debuglive)
        obj.Flagcount("m", "print optimization decisions", &Debug['m'])
-       obj.Flagcount("msan", "build code compatible with C/C++ memory sanitizer", &flag_msan)
-       obj.Flagcount("newexport", "use new export format", &newexport) // TODO(gri) remove eventually (issue 13241)
-       obj.Flagcount("nolocalimports", "reject local (relative) imports", &nolocalimports)
-       obj.Flagstr("o", "write output to `file`", &outfile)
-       obj.Flagstr("p", "set expected package import `path`", &myimportpath)
-       obj.Flagcount("pack", "write package file instead of object file", &writearchive)
+       flag.BoolVar(&flag_msan, "msan", false, "build code compatible with C/C++ memory sanitizer")
+       flag.BoolVar(&newexport, "newexport", false, "use new export format") // TODO(gri) remove eventually (issue 13241)
+       flag.BoolVar(&nolocalimports, "nolocalimports", false, "reject local (relative) imports")
+       flag.StringVar(&outfile, "o", "", "write output to `file`")
+       flag.StringVar(&myimportpath, "p", "", "set expected package import `path`")
+       flag.BoolVar(&writearchive, "pack", false, "write package file instead of object file")
        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.Flagstr("trimpath", "remove `prefix` from recorded source file paths", &Ctxt.LineHist.TrimPathPrefix)
-       obj.Flagcount("u", "reject unsafe code", &safemode)
+       flag.StringVar(&Ctxt.LineHist.TrimPathPrefix, "trimpath", "", "remove `prefix` from recorded source file paths")
+       flag.BoolVar(&safemode, "u", false, "reject unsafe code")
        obj.Flagcount("v", "increase debug verbosity", &Debug['v'])
        obj.Flagcount("w", "debug type checking", &Debug['w'])
-       use_writebarrier = 1
-       obj.Flagcount("wb", "enable write barrier", &use_writebarrier)
+       flag.BoolVar(&use_writebarrier, "wb", true, "enable write barrier")
        obj.Flagcount("x", "debug lexer", &Debug['x'])
        obj.Flagcount("y", "debug declarations in canned imports (with -d)", &Debug['y'])
-       var flag_shared int
+       var flag_shared bool
        var flag_dynlink bool
        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")
        }
        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)
-       obj.Flagstr("memprofile", "write memory profile to `file`", &memprofile)
-       obj.Flagint64("memprofilerate", "set runtime.MemProfileRate to `rate`", &memprofilerate)
+       flag.StringVar(&cpuprofile, "cpuprofile", "", "write cpu profile to `file`")
+       flag.StringVar(&memprofile, "memprofile", "", "write memory profile to `file`")
+       flag.Int64Var(&memprofilerate, "memprofilerate", 0, "set runtime.MemProfileRate to `rate`")
        flag.BoolVar(&ssaEnabled, "ssa", true, "use SSA backend to generate code")
        obj.Flagparse(usage)
 
        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_optimize = Debug['N'] == 0
 
@@ -225,17 +226,17 @@ func Main() {
 
        startProfile()
 
-       if flag_race != 0 {
+       if flag_race {
                racepkg = mkpkg("runtime/race")
                racepkg.Name = "race"
        }
-       if flag_msan != 0 {
+       if flag_msan {
                msanpkg = mkpkg("runtime/msan")
                msanpkg.Name = "msan"
        }
-       if flag_race != 0 && flag_msan != 0 {
+       if flag_race && flag_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
        }
 
@@ -471,7 +472,7 @@ func Main() {
                fninit(xtop)
        }
 
-       if compiling_runtime != 0 {
+       if compiling_runtime {
                checknowritebarrierrec()
        }
 
@@ -569,7 +570,7 @@ func islocalname(name string) bool {
 
 func findpkg(name string) (file string, ok bool) {
        if islocalname(name) {
-               if safemode != 0 || nolocalimports != 0 {
+               if safemode || nolocalimports {
                        return "", false
                }
 
@@ -612,10 +613,10 @@ func findpkg(name string) (file string, ok bool) {
                if flag_installsuffix != "" {
                        suffixsep = "_"
                        suffix = flag_installsuffix
-               } else if flag_race != 0 {
+               } else if flag_race {
                        suffixsep = "_"
                        suffix = "race"
-               } else if flag_msan != 0 {
+               } else if flag_msan {
                        suffixsep = "_"
                        suffix = "msan"
                }
@@ -694,7 +695,7 @@ func importfile(f *Val, indent []byte) {
        }
 
        if path_ == "unsafe" {
-               if safemode != 0 {
+               if safemode {
                        Yyerror("cannot import package unsafe")
                        errorexit()
                }
@@ -818,7 +819,7 @@ func importfile(f *Val, indent []byte) {
                errorexit()
        }
 
-       if safemode != 0 && !importpkg.Safe {
+       if safemode && !importpkg.Safe {
                Yyerror("cannot import unsafe package %q", importpkg.Path)
        }
 }
@@ -896,7 +897,7 @@ func mkpackage(pkgname string) {
                        p = p[:i]
                }
                suffix := ".o"
-               if writearchive > 0 {
+               if writearchive {
                        suffix = ".a"
                }
                outfile = p + suffix
index eed0ed6e24a830ae3464badb8054978493afdfb3..59ce0547c80bb1baebb417dc80b62945c24292be 100644 (file)
@@ -33,7 +33,7 @@ func dumpobj() {
 
        startobj := int64(0)
        var arhdr [ArhdrSize]byte
-       if writearchive != 0 {
+       if writearchive {
                bout.WriteString("!<arch>\n")
                arhdr = [ArhdrSize]byte{}
                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())
        dumpexport()
 
-       if writearchive != 0 {
+       if writearchive {
                bout.Flush()
                size := bout.Offset() - startobj
                if size&1 != 0 {
@@ -62,7 +62,7 @@ func dumpobj() {
        }
 
        if pragcgobuf != "" {
-               if writearchive != 0 {
+               if writearchive {
                        // write empty export section; must be before cgo section
                        fmt.Fprintf(bout, "\n$$\n\n$$\n\n")
                }
@@ -90,7 +90,7 @@ func dumpobj() {
        dumpdata()
        obj.Writeobjdirect(Ctxt, bout)
 
-       if writearchive != 0 {
+       if writearchive {
                bout.Flush()
                size := bout.Offset() - startobj
                if size&1 != 0 {
index baa960bf75fdf4bab1c6d07b056a088434069179..7b9b91e7b071d2dbc2e8247385275e74ccb7982b 100644 (file)
@@ -364,7 +364,7 @@ func compile(fn *Node) {
        dowidth(Curfn.Type)
 
        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)
                        return
                }
index f6e65146d669382b4ccd68835ecab3b59ce1a3ad..a8a5e92485a8626e8114daca5cf42f487f3ecd37 100644 (file)
@@ -54,14 +54,14 @@ func instrument(fn *Node) {
                return
        }
 
-       if flag_race == 0 || !ispkgin(norace_inst_pkgs) {
+       if !flag_race || !ispkgin(norace_inst_pkgs) {
                instrumentlist(fn.Nbody, nil)
 
                // nothing interesting for race detector in fn->enter
                instrumentlist(fn.Func.Exit, nil)
        }
 
-       if flag_race != 0 {
+       if flag_race {
                // nodpc is the PC of the caller as extracted by
                // getcallerpc. We use -widthptr(FP) for x86.
                // 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)
                makeaddable(n)
                var f *Node
-               if flag_msan != 0 {
+               if flag_msan {
                        name := "msanread"
                        if wr != 0 {
                                name = "msanwrite"
@@ -515,7 +515,7 @@ func callinstr(np **Node, init *Nodes, wr int, skip int) bool {
                                Fatalf("instrument: %v badwidth", t)
                        }
                        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"
                        if wr != 0 {
                                name = "racewriterange"
@@ -527,7 +527,7 @@ func callinstr(np **Node, init *Nodes, wr int, skip int) bool {
                                Fatalf("instrument: %v badwidth", t)
                        }
                        f = mkcall(name, nil, init, uintptraddr(n), Nodintconst(w))
-               } else if flag_race != 0 {
+               } else if flag_race {
                        name := "raceread"
                        if wr != 0 {
                                name = "racewrite"
index 70a75f93249d9545375e38b58fb085fbf5078807..df68f46d4cb9c978a9f6102073e6742d245c7589 100644 (file)
@@ -1424,10 +1424,10 @@ func dumptypestructs() {
                // add paths for runtime and main, which 6l imports implicitly.
                dimportpath(Runtimepkg)
 
-               if flag_race != 0 {
+               if flag_race {
                        dimportpath(racepkg)
                }
-               if flag_msan != 0 {
+               if flag_msan {
                        dimportpath(msanpkg)
                }
                dimportpath(mkpkg("main"))
index fdd14953e6bd0a1ea12a140dd72d760f910ad2b4..4a93dc1087504aba9718a3d0d83e168a1958e1ca 100644 (file)
@@ -554,7 +554,7 @@ func (s *state) stmt(n *Node) {
        case OCALLFUNC, OCALLMETH, OCALLINTER:
                s.call(n, callNormal)
                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")) {
                        m := s.mem()
                        b := s.endBlock()
@@ -579,7 +579,7 @@ func (s *state) stmt(n *Node) {
                if n.Left.Class&PHEAP == 0 {
                        return
                }
-               if compiling_runtime != 0 {
+               if compiling_runtime {
                        Fatalf("%v escapes to heap, not allowed in runtime.", n)
                }
 
index 776eb9c64e5cc5cbde8a383df4a3dae959c41214..f6af11adbad4812edb89a46582fdb1277d08f67a 100644 (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.
        // 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")
                errorexit()
        }
index 7089d7de7252e2a07a8fa68af3ac682149b114b9..6067677738f6787ab2c633538f7ab96ab24cbba8 100644 (file)
@@ -1354,7 +1354,7 @@ OpSwitch:
                if t.Results().NumFields() == 1 {
                        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.
                                // 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
@@ -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")
        }
 
index 338f3c0eae379f947056633aa83deb877ae361e5..e1d3b40098721c395cc6b5e51d20a4a3c34f6aaa 100644 (file)
@@ -9,7 +9,7 @@ func unsafenmagic(nn *Node) *Node {
        fn := nn.Left
        args := nn.List
 
-       if safemode != 0 || fn == nil || fn.Op != ONAME {
+       if safemode || fn == nil || fn.Op != ONAME {
                return nil
        }
        s := fn.Sym
index 3e5f5161db09afc5aa00baec2c54baf77f7d157b..78bad8d348786f80ba99e8e63a68eae18e536295 100644 (file)
@@ -594,8 +594,7 @@ opswitch:
                // for a struct containing a reflect.Value, which itself has
                // an unexported field of type unsafe.Pointer.
                old_safemode := safemode
-
-               safemode = 0
+               safemode = false
                n = walkcompare(n, init)
                safemode = old_safemode
 
@@ -1938,7 +1937,7 @@ func walkprint(nn *Node, init *Nodes) *Node {
                        on = substArgTypes(on, n.Type) // any-1
                } else if Isint[et] {
                        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")
                                } else {
                                        on = syslook("printuint")
@@ -2041,7 +2040,7 @@ func isglobal(n *Node) bool {
 
 // Do we need a write barrier for the assignment l = r?
 func needwritebarrier(l *Node, r *Node) bool {
-       if use_writebarrier == 0 {
+       if !use_writebarrier {
                return false
        }
 
@@ -2550,7 +2549,7 @@ func paramstoheap(params *Type, out bool) []*Node {
                }
 
                // generate allocation & copying code
-               if compiling_runtime != 0 {
+               if compiling_runtime {
                        Yyerror("%v escapes to heap, not allowed in runtime.", v)
                }
                if prealloc[v] == nil {