https://gcc.gnu.org/g:5472ab920e3c2c16fe529b9a0bf5a2964fa856c0
commit r17-6336-g5472ab920e3c2c16fe529b9a0bf5a2964fa856c0 Author: Hans-Peter Nilsson <[email protected]> Date: Mon Nov 16 05:33:28 2026 +0000 testsuite: Correct error handling for scan-symbol-common Expose and handle the erroneous early exits. Two more-or-less dormant bugs are fixed here. The first, execution-wise, is that scan-symbol and scan-symbol-not call scan-symbol-common with $args such that all arguments are folded into one string. It can be observed with the following edit to testsuite/gcc.dg/builtin-pi-linkage.c (prefixed with "X" to avoid tripping up faulty tools): X--- builtin-pi-linkage.c.orig 2026-10-31 10:33:22.000000000 +0100 X+++ builtin-pi-linkage.c 2026-11-16 05:36:28.027800365 +0100 X@@ -57,3 +57,3 @@ X /* { dg-final { scan-symbol "acospi" } } */ X-/* { dg-final { scan-symbol "asinpi" } } */ X+/* { dg-final { scan-symbol "asinpi" { target *-*-* } } } */ X /* { dg-final { scan-symbol "atan2pi" } } */ This yields: Running /top/gcc/testsuite/gcc.dg/dg.exp ... FAIL: gcc.dg/builtin-pi-linkage.c scan-symbol asinpi { target *-*-* } The second (and 3rd and 4th) are the early exits without a return value. Because of the previous bug, the "[llength $args] >= 2" conditional was never true, but with that fixed, we can see, if we edit target above to e.g. "xyzzy-*-*", for the "N" case: ERROR: gcc.dg/builtin-pi-linkage.c: error executing dg-final: expected boolean value but got "" The error numbers were chosen because they subjectively read good enough in the calling code and I chose "fail" for consistency with the apparent intent for "output file does not exist". gcc/testsuite: * lib/gcc-dg.exp (scan-symbol-common): Return -2 for a skipped test, and -1 for a tool failure. Treat missing output file as a tool failure instead of failing with a special message. (scan-symbol): Adjust accordingly. When calling scan-symbol-common, use eval, to avoid folding arguments into one string. Include only the symbol in the pass/fail message. (scan-symbol-not): Ditto. Diff: --- gcc/testsuite/lib/gcc-dg.exp | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp index 6f8068586d1f..f0b789167329 100644 --- a/gcc/testsuite/lib/gcc-dg.exp +++ b/gcc/testsuite/lib/gcc-dg.exp @@ -1389,7 +1389,9 @@ proc gdb-exists { args } { } # Helper function for scan-symbol and scan-symbol-not. It scans a symbol in -# the final executable and return 1 if present, otherwise fail. +# the final executable and return 1 if present, 0 if it doesn't, -1 if +# scanning fails with the chosen method (suggested translation: "fail" or +# "unresolved"), and -2 if the test was skipped. # # Argument 0 is the regexp to match. # Argument 1 handles expected failures and the like @@ -1403,7 +1405,7 @@ proc scan-symbol-common { scan_directive args } { if { [llength $args] >= 2 } { switch [dg-process-target [lindex $args 1]] { "S" { } - "N" { return } + "N" { return -2 } "F" { setup_xfail "*-*-*" } "P" { } } @@ -1426,15 +1428,15 @@ proc scan-symbol-common { scan_directive args } { set output_file "[glob -nocomplain $output_file]" if { $output_file == "" } { - fail "$scan_directive $args: output file does not exist" - return + verbose -log "$scan_directive $args: output file does not exist" + return -1 } set output [remote_exec host "$nm_cmd" "$output_file"] set status [lindex $output 0] if { $status != 0 } { verbose -log "$scan_directive $args: $nm_cmd failed" - return 0 + return -1 } set text [lindex $output 1] @@ -1452,10 +1454,13 @@ proc scan-symbol-common { scan_directive args } { # Argument 1 handles expected failures and the like proc scan-symbol { args } { set testcase [testname-for-summary] - if { [scan-symbol-common "scan-symbol" $args]} { - pass "$testcase scan-symbol $args" - } else { - fail "$testcase scan-symbol $args" + set res [eval scan-symbol-common "scan-symbol" $args] + if { $res == 1 } { + pass "$testcase scan-symbol [lindex $args 0]" + } elseif { $res == 0 || $res == -1 } { + fail "$testcase scan-symbol [lindex $args 0]" + } elseif { $res != -2 } { + error "Invalid handling of scan-symbol $args in testcase $testcase" } } @@ -1466,10 +1471,13 @@ proc scan-symbol { args } { # Argument 1 handles expected failures and the like proc scan-symbol-not { args } { set testcase [testname-for-summary] - if { [scan-symbol-common "scan-symbol-not" $args]} { - fail "$testcase scan-symbol-not $args" - } else { - pass "$testcase scan-symbol-not $args" + set res [eval scan-symbol-common "scan-symbol-not" $args] + if { $res == 1 || $res == -1 } { + fail "$testcase scan-symbol-not [lindex $args 0]" + } elseif { $res == 0 } { + pass "$testcase scan-symbol-not [lindex $args 0]" + } elseif { $res != -2 } { + error "Invalid handling of scan-symbol-not $args in testcase $testcase" } }
