From: Ian Lance Taylor Date: Wed, 29 Dec 2021 19:19:13 +0000 (-0800) Subject: misc/cgo/testsanitizers: accept compilers that don't report location X-Git-Tag: go1.18beta2~177 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=6178d25fc0b28724b1b5aec2b1b74fc06d9294c7;p=gostls13.git misc/cgo/testsanitizers: accept compilers that don't report location It appears that GCC before version 10 doesn't report file/line location for asan errors. Change-Id: I03ee24180ba365636596aa2384961df7ce6ed71f Reviewed-on: https://go-review.googlesource.com/c/go/+/374874 Trust: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Reviewed-by: Cherry Mui TryBot-Result: Gopher Robot --- diff --git a/misc/cgo/testsanitizers/asan_test.go b/misc/cgo/testsanitizers/asan_test.go index ed58e5a183..27bd8a5b1f 100644 --- a/misc/cgo/testsanitizers/asan_test.go +++ b/misc/cgo/testsanitizers/asan_test.go @@ -63,7 +63,11 @@ func TestASAN(t *testing.T) { // symbolizer program and can't find it. const noSymbolizer = "external symbolizer" // Check if -asan option can correctly print where the error occured. - if tc.errorLocation != "" && !strings.Contains(out, tc.errorLocation) && !strings.Contains(out, noSymbolizer) { + if tc.errorLocation != "" && + !strings.Contains(out, tc.errorLocation) && + !strings.Contains(out, noSymbolizer) && + compilerSupportsLocation() { + t.Errorf("%#q exited without expected location of the error\n%s; got failure\n%s", strings.Join(cmd.Args, " "), tc.errorLocation, out) } return diff --git a/misc/cgo/testsanitizers/cc_test.go b/misc/cgo/testsanitizers/cc_test.go index 0ce4f75935..05b77932b4 100644 --- a/misc/cgo/testsanitizers/cc_test.go +++ b/misc/cgo/testsanitizers/cc_test.go @@ -218,6 +218,23 @@ func compilerVersion() (version, error) { return compiler.version, compiler.err } +// compilerSupportsLocation reports whether the compiler should be +// able to provide file/line information in backtraces. +func compilerSupportsLocation() bool { + compiler, err := compilerVersion() + if err != nil { + return false + } + switch compiler.name { + case "gcc": + return compiler.major >= 10 + case "clang": + return true + default: + return false + } +} + type compilerCheck struct { once sync.Once err error