github.com/bir3/gocompiler@v0.3.205/src/cmd/compile/internal/walk/race.go (about) 1 // Copyright 2012 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package walk 6 7 import ( 8 "github.com/bir3/gocompiler/src/cmd/compile/internal/base" 9 "github.com/bir3/gocompiler/src/cmd/compile/internal/ir" 10 "github.com/bir3/gocompiler/src/cmd/compile/internal/types" 11 "github.com/bir3/gocompiler/src/cmd/internal/src" 12 ) 13 14 func instrument(fn *ir.Func) { 15 if fn.Pragma&ir.Norace != 0 || (fn.Linksym() != nil && fn.Linksym().ABIWrapper()) { 16 return 17 } 18 19 if !base.Flag.Race || !base.Compiling(base.NoRacePkgs) { 20 fn.SetInstrumentBody(true) 21 } 22 23 if base.Flag.Race { 24 lno := base.Pos 25 base.Pos = src.NoXPos 26 var init ir.Nodes 27 fn.Enter.Prepend(mkcallstmt("racefuncenter", mkcall("getcallerpc", types.Types[types.TUINTPTR], &init))) 28 if len(init) != 0 { 29 base.Fatalf("race walk: unexpected init for getcallerpc") 30 } 31 fn.Exit.Append(mkcallstmt("racefuncexit")) 32 base.Pos = lno 33 } 34 }