From 9179c9cb5c369e075a65a2a5addd4a0e0b099b16 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 26 Oct 2015 13:58:23 -0700 Subject: [PATCH] cmd/compile: make sure instrumented call has type width The width of the type of an external variable defined with a type literal may not be set when the instrumentation pass is run. There are two cases in the standard library that fail without the call to dowidth: ../../../src/encoding/base32/base32.go:322: constant -1000000000 overflows uintptr ../../../src/encoding/base32/base32.go:329: constant -1000000000 overflows uintptr ../../../src/encoding/json/encode.go:385: constant -1000000000 overflows uintptr ../../../src/encoding/json/encode.go:387: constant -1000000000 overflows uintptr Change-Id: I7c3334f7decdb7488595ffe4090cd262d7334283 Reviewed-on: https://go-review.googlesource.com/16331 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Russ Cox --- misc/cgo/testsanitizers/test.bash | 5 +++++ src/cmd/compile/internal/gc/racewalk.go | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/misc/cgo/testsanitizers/test.bash b/misc/cgo/testsanitizers/test.bash index 88c54e6173..19407b8cb2 100755 --- a/misc/cgo/testsanitizers/test.bash +++ b/misc/cgo/testsanitizers/test.bash @@ -37,6 +37,11 @@ fi status=0 +if ! go build -msan std; then + echo "FAIL: build -msan std" + status=1 +fi + if ! go run -msan msan.go; then echo "FAIL: msan" status=1 diff --git a/src/cmd/compile/internal/gc/racewalk.go b/src/cmd/compile/internal/gc/racewalk.go index 7770f741df..acebb1ac9c 100644 --- a/src/cmd/compile/internal/gc/racewalk.go +++ b/src/cmd/compile/internal/gc/racewalk.go @@ -502,13 +502,25 @@ func callinstr(np **Node, init **NodeList, wr int, skip int) bool { if wr != 0 { name = "msanwrite" } - f = mkcall(name, nil, init, uintptraddr(n), Nodintconst(t.Width)) + // dowidth may not have been called for PEXTERN. + dowidth(t) + w := t.Width + if w == BADWIDTH { + Fatalf("instrument: %v badwidth", t) + } + f = mkcall(name, nil, init, uintptraddr(n), Nodintconst(w)) } else if flag_race != 0 && (t.Etype == TSTRUCT || Isfixedarray(t)) { name := "racereadrange" if wr != 0 { name = "racewriterange" } - f = mkcall(name, nil, init, uintptraddr(n), Nodintconst(t.Width)) + // dowidth may not have been called for PEXTERN. + dowidth(t) + w := t.Width + if w == BADWIDTH { + Fatalf("instrument: %v badwidth", t) + } + f = mkcall(name, nil, init, uintptraddr(n), Nodintconst(w)) } else if flag_race != 0 { name := "raceread" if wr != 0 { -- 2.48.1