From b94331d9a3f7efb451bfad9db0fda162d3c46748 Mon Sep 17 00:00:00 2001
From: Richard Sandiford <richard.sandiford@arm.com>
Date: Wed, 9 Oct 2024 13:57:36 +0100
Subject: [PATCH] testsuite: Make check-function-bodies work with LTO

This patch tries to make check-function-bodies automatically
choose between reading the regular assembly file and reading the
LTO assembly file.  There should only ever be one right answer,
since check-function-bodies doesn't make sense on slim LTO output.

Maybe this will turn out to be impossible to get right, but I'd like
to try at least.

gcc/testsuite/
	* lib/scanasm.exp (check-function-bodies): Look in ltrans0.ltrans.s
	if the test appears to be using LTO.
---
 gcc/testsuite/lib/scanasm.exp | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/gcc/testsuite/lib/scanasm.exp b/gcc/testsuite/lib/scanasm.exp
index 737eefc655e9..26504deb0e62 100644
--- a/gcc/testsuite/lib/scanasm.exp
+++ b/gcc/testsuite/lib/scanasm.exp
@@ -997,16 +997,17 @@ proc check-function-bodies { args } {
 	error "too many arguments to check-function-bodies"
     }
 
+    upvar 2 dg-extra-tool-flags extra_tool_flags
+    set flags $extra_tool_flags
+
+    global torture_current_flags
+    if { [info exists torture_current_flags] } {
+	append flags " " $torture_current_flags
+    }
+
     if { [llength $args] >= 3 } {
 	set required_flags [lindex $args 2]
 
-	upvar 2 dg-extra-tool-flags extra_tool_flags
-	set flags $extra_tool_flags
-
-	global torture_current_flags
-	if { [info exists torture_current_flags] } {
-	    append flags " " $torture_current_flags
-	}
 	foreach required_flag $required_flags {
 	    switch -- $required_flag {
 		target -
@@ -1043,7 +1044,14 @@ proc check-function-bodies { args } {
 
     global srcdir
     set input_filename "$srcdir/$filename"
-    set output_filename "[file rootname [file tail $filename]].s"
+    set output_filename "[file rootname [file tail $filename]]"
+    if { [string match "* -flto *" " ${flags} "]
+	 && ![string match "* -fno-use-linker-plugin *" " ${flags} "]
+	 && ![string match "* -ffat-lto-objects *" " ${flags} "] } {
+	append output_filename ".ltrans0.ltrans.s"
+    } else {
+	append output_filename ".s"
+    }
 
     set prefix [lindex $args 0]
     set prefix_len [string length $prefix]
-- 
GitLab