From 6178d25fc0b28724b1b5aec2b1b74fc06d9294c7 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 29 Dec 2021 11:19:13 -0800 Subject: [PATCH] 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 --- misc/cgo/testsanitizers/asan_test.go | 6 +++++- misc/cgo/testsanitizers/cc_test.go | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) 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 -- 2.50.0