From 1a15a9dbd8cfc3c2f5df72653614c5c70a0c6018 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Mon, 4 Sep 2023 22:28:12 +0200
Subject: [PATCH] [WIP] testsuite: Port 'check-function-bodies' to nvptx
This extends commit 4d706ff86ea86868615558e92407674a4f4b4af9
"Add dg test for matching function bodies" for nvptx.
---
gcc/doc/sourcebuild.texi | 2 ++
gcc/testsuite/gcc.target/nvptx/abort.c | 19 +++++++++++++++++--
gcc/testsuite/lib/scanasm.exp | 21 +++++++++++++++++----
3 files changed, 36 insertions(+), 6 deletions(-)
@@ -3319,6 +3319,7 @@ function body for unoptimized code.
The first line of the expected output for a function @var{fn} has the form:
+@c TODO
@smallexample
@var{prefix} @var{fn}: [@{ target/xfail @var{selector} @}]
@end smallexample
@@ -3326,6 +3327,7 @@ The first line of the expected output for a function @var{fn} has the form:
Subsequent lines of the expected output also start with @var{prefix}.
In both cases, whitespace after @var{prefix} is not significant.
+@c TODO
The test discards assembly directives such as @code{.cfi_startproc}
and local label definitions such as @code{.LFB0} from the compiler's
assembly output. It then matches the result against the expected
@@ -1,4 +1,6 @@
/* { dg-do compile} */
+/* { dg-final { check-function-bodies {**} {} } } */
+
/* Annotate no return functions with a trailing 'trap'. */
extern void abort ();
@@ -9,5 +11,18 @@ int main (int argc, char **argv)
abort ();
return 0;
}
-
-/* { dg-final { scan-assembler "call abort;\[\r\n\t \]+trap;" } } */
+/*
+** // BEGIN GLOBAL FUNCTION DEF: main
+** ...
+** \.reg\.pred (%r[0-9]+);
+** ...
+** @\1 bra (\$L[0-9]+);
+** {
+** \tcall abort;
+** \ttrap; // \(noreturn\)
+** \texit; // \(noreturn\)
+** }
+TODO** \2:
+TODO This label currently cannot be matched.
+** ...
+*/
@@ -785,13 +785,16 @@ proc parse_function_bodies { filename result } {
upvar $result up_result
# Regexp for the start of a function definition (name in \1).
- set label {^([a-zA-Z_]\S+):$}
+ #TODO
+ set label {^// BEGIN GLOBAL FUNCTION DEF: ([a-zA-Z_]\S+)$}
# Regexp for the end of a function definition.
- set terminator {^\s*\.size}
+ #TODO
+ set terminator {^\}$}
# Regexp for lines that aren't interesting.
- set fluff {^\s*(?:\.|//|@|$)}
+ #TODO n/a -- or still TODO
+ set fluff {^\s*$}
set fd [open $filename r]
set in_function 0
@@ -801,6 +804,7 @@ proc parse_function_bodies { filename result } {
set function_body ""
} elseif { $in_function } {
if { [regexp $terminator $line] } {
+ #verbose -log "parse_function_bodies: $function_name\n$function_body"
set up_result($function_name) $function_body
set in_function 0
} elseif { ![regexp $fluff $line] } {
@@ -907,7 +911,8 @@ proc check-function-bodies { args } {
set count 0
set function_regexp ""
- set label {^(\S+):$}
+ #TODO
+ set label {^// BEGIN GLOBAL FUNCTION DEF: ([a-zA-Z_]\S+)$}
set lineno 1
set fd [open $input_filename r]
@@ -937,7 +942,15 @@ proc check-function-bodies { args } {
} elseif { [string equal $line "..."] } {
append function_regexp ".*"
} else {
+ #TODO
+ # Certain (predicable) nvptx instructions are emitted with additional whitespace prefixed.
+ # Prune that here, or include in expected output lines?
+ # On the other hand, labels are emitted in column zero (for no particular reason as far as I can tell; could be changed).
+ # (Whitespace is not significant there.)
+ # But: labels are also in column zero for x86_64 assembly, for example, so that's a pre-existing issue, to be solved generally.
+ # Actually, they're filtered out as "fluff", so that's generally a non-issue vs. TODO item.
append function_regexp "\t" $line "\n"
+ #append function_regexp {\s*} $line {\n}
}
} elseif { [string equal -length $terminator_len $line $terminator] } {
if { ![string equal $selector "N"] } {
--
2.34.1