Under slim LTO (-flto without fat objects) a compile-only
check-function-bodies test emits only LTO bytecode in its .s file and,
because it never links, produces no LTRANS output, so the check finds
nothing to scan.  Unlike scan-assembler*, check-function-bodies had no
required-options hook to force -ffat-lto-objects.

Register a required-options hook for check-function-bodies so that LTO
runs add -ffat-lto-objects, yielding a non-empty .s to scan.  With fat
objects a compile-only test no longer produces an LTRANS file, so scan
the .ltrans0.ltrans.s output only when it actually exists and otherwise
fall back to the .s file.

gcc/testsuite/ChangeLog:

        * lib/scanasm.exp (check-function-bodies): Scan the LTRANS output
        only when it exists, otherwise fall back to the .s file.  Set the
        required options for check-function-bodies.
---
 gcc/testsuite/lib/scanasm.exp | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/lib/scanasm.exp b/gcc/testsuite/lib/scanasm.exp
index 897ce76eae5..9291735386a 100644
--- a/gcc/testsuite/lib/scanasm.exp
+++ b/gcc/testsuite/lib/scanasm.exp
@@ -1219,10 +1219,16 @@ proc check-function-bodies { args } {
     global srcdir
     set input_filename "$srcdir/$filename"
     set output_filename "[file rootname [file tail $filename]]"
+    # With slim LTO the regular .s holds no assembly, so a link test reads
+    # the post-LTO LTRANS output instead.  A compile-only test produces no
+    # LTRANS file; check-function-bodies' required-options force
+    # -ffat-lto-objects for it, so fall back to the (now non-empty) .s.
+    set lto_filename "$output_filename.ltrans0.ltrans.s"
     if { [string match "* -flto *" " ${flags} "]
         && ![string match "* -fno-use-linker-plugin *" " ${flags} "]
-        && ![string match "* -ffat-lto-objects *" " ${flags} "] } {
-       append output_filename ".ltrans0.ltrans.s"
+        && ![string match "* -ffat-lto-objects *" " ${flags} "]
+        && [file exists $lto_filename] } {
+       set output_filename $lto_filename
     } else {
        append output_filename ".s"
     }
@@ -1321,3 +1327,5 @@ proc check-function-bodies { args } {
        error "check-function-bodies: no matches found"
     }
 }
+
+set_required_options_for check-function-bodies
-- 
2.52.0

Reply via email to