]> Cypherpunks repositories - gostls13.git/commitdiff
misc/cgo/testsanitizers: accept compilers that don't report location
authorIan Lance Taylor <iant@golang.org>
Wed, 29 Dec 2021 19:19:13 +0000 (11:19 -0800)
committerIan Lance Taylor <iant@golang.org>
Wed, 29 Dec 2021 20:20:32 +0000 (20:20 +0000)
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 <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

misc/cgo/testsanitizers/asan_test.go
misc/cgo/testsanitizers/cc_test.go

index ed58e5a183fc365f1427bd285ee634c8fcc67045..27bd8a5b1f37aef7eaffe3d615991344a0bc19c0 100644 (file)
@@ -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
index 0ce4f75935ec4671ac14c36beb6109948be5c57c..05b77932b4cbab8cd7fc36fc34a27e60a3af26da 100644 (file)
@@ -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