public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Joern Rennecke <joern.rennecke@embecosm.com>
To: Jeff Law <jeffreyalaw@gmail.com>
Cc: Vineet Gupta <vineetg@rivosinc.com>,
	GCC Patches <gcc-patches@gcc.gnu.org>
Subject: RFA: make scan-assembler* ignore LTO sections (Was: Re: committed [RISC-V]: Harden test scan patterns)
Date: Wed, 8 Nov 2023 16:00:58 +0000	[thread overview]
Message-ID: <CAMqJFCohe0qW4BGjbXSvBauJeAzkqoNNbSU+rCZV-jJgo+uAKg@mail.gmail.com> (raw)
In-Reply-To: <de80edfb-caa2-45d2-b67b-9f421a5421de@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 677 bytes --]

On Fri, 29 Sept 2023 at 14:54, Jeff Law <jeffreyalaw@gmail.com> wrote:
> ...  Joern  can you post a follow-up manual twiddle so
> that other ports can follow your example and avoid this problem?
>
> THanks,
>
> jeff

The attached patch makes the scan-assembler* directives ignore the LTO
sections.

Regression tested (using QEMU) for
    riscv-sim
    riscv-sim/-march=rv32gcv_zfh/-mabi=ilp32d/-ftree-vectorize/--param=riscv-autovec-preference=scalable
    riscv-sim/-march=rv32imac/-mabi=ilp32
    riscv-sim/-march=rv64gcv_zfh_zvfh_zba_zbb_zbc_zicond_zicboz_zawrs/-mabi=lp64d/-ftree-vectorize/--param=riscv-autovec-preference=scalable
    riscv-sim/-march=rv64imac/-mabi=lp64

[-- Attachment #2: scanasm-diff-5.txt --]
[-- Type: text/plain, Size: 5605 bytes --]

2023-11-08  Joern Rennecke  <joern.rennecke@embecosm.com>

gcc/testsuite/
	* lib/scanasm.exp (scan-assembler-times): Disregard LTO sections.
	(scan-assembler-dem, scan-assembler-dem-not): Likewise.
	(dg-scan): Likewise, if name starts with scan-assembler.
	(scan-raw-assembler): New proc.
	* gcc.dg/pr61868.c: Use scan-raw-assembler.
	* gcc.dg/scantest-lto.c: New test.
gcc/
	* doc/sourcebuild.texi (Scan the assembly output): Document change.

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index 8bf701461ec..5a34a10e6c2 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -3276,21 +3276,28 @@ Passes if @var{regexp} does not match text in the file generated by
 
 @table @code
 @item scan-assembler @var{regex} [@{ target/xfail @var{selector} @}]
-Passes if @var{regex} matches text in the test's assembler output.
+Passes if @var{regex} matches text in the test's assembler output,
+excluding LTO sections.
+
+@item scan-raw-assembler @var{regex} [@{ target/xfail @var{selector} @}]
+Passes if @var{regex} matches text in the test's assembler output,
+including LTO sections.
 
 @item scan-assembler-not @var{regex} [@{ target/xfail @var{selector} @}]
-Passes if @var{regex} does not match text in the test's assembler output.
+Passes if @var{regex} does not match text in the test's assembler output,
+excluding LTO sections.
 
 @item scan-assembler-times @var{regex} @var{num} [@{ target/xfail @var{selector} @}]
 Passes if @var{regex} is matched exactly @var{num} times in the test's
-assembler output.
+assembler output, excluding LTO sections.
 
 @item scan-assembler-dem @var{regex} [@{ target/xfail @var{selector} @}]
-Passes if @var{regex} matches text in the test's demangled assembler output.
+Passes if @var{regex} matches text in the test's demangled assembler output,
+excluding LTO sections.
 
 @item scan-assembler-dem-not @var{regex} [@{ target/xfail @var{selector} @}]
 Passes if @var{regex} does not match text in the test's demangled assembler
-output.
+output, excluding LTO sections.
 
 @item scan-assembler-symbol-section @var{functions} @var{section} [@{ target/xfail @var{selector} @}]
 Passes if @var{functions} are all in @var{section}.  The caller needs to
diff --git a/gcc/testsuite/gcc.dg/pr61868.c b/gcc/testsuite/gcc.dg/pr61868.c
index 4a7e8f6ae2d..52ab7838643 100644
--- a/gcc/testsuite/gcc.dg/pr61868.c
+++ b/gcc/testsuite/gcc.dg/pr61868.c
@@ -7,4 +7,4 @@ int main ()
   foo (100);
   return 0;
 }
-/* { dg-final { scan-assembler "\.gnu\.lto.*.12345" } } */
+/* { dg-final { scan-raw-assembler "\.gnu\.lto.*.12345" } } */
diff --git a/gcc/testsuite/lib/scanasm.exp b/gcc/testsuite/lib/scanasm.exp
index 5df80325dff..16b5198d38b 100644
--- a/gcc/testsuite/lib/scanasm.exp
+++ b/gcc/testsuite/lib/scanasm.exp
@@ -79,6 +79,12 @@ proc dg-scan { name positive testcase output_file orig_args } {
     }
     set text [read $fd]
     close $fd
+    if { [string compare -length 14 $name scan-assembler] == 0 } {
+      # Remove LTO sections.
+      # ??? Somehow, .*? is still greedy.
+      # regsub -all {(^|\n)[[:space:]]*\.section[[:space:]]*\.gnu\.lto_.*?\n(?=[[:space:]]*\.text\n)} $text {\1} text
+      regsub -all {(^|\n)[[:space:]]*\.section[[:space:]]*\.gnu\.lto_(?:[^\n]*\n(?![[:space:]]*\.(section|text|data|bss)))*[^\n]*\n} $text {\1} text
+    }
 
     set match [regexp -- $pattern $text]
     if { $match == $positive } {
@@ -108,6 +114,16 @@ proc scan-assembler { args } {
 
 set_required_options_for scan-assembler
 
+proc scan-raw-assembler { args } {
+    set testcase [testname-for-summary]
+    # The name might include a list of options; extract the file name.
+    set filename [lindex $testcase 0]
+    set output_file "[file rootname [file tail $filename]].s"
+    dg-scan "scan-raw-assembler" 1 $testcase $output_file $args
+}
+
+set_required_options_for scan-raw-assembler
+
 # Check that a pattern is not present in the .s file produced by the
 # compiler.  See dg-scan for details.
 
@@ -487,6 +503,7 @@ proc scan-assembler-times { args } {
     set fd [open $output_file r]
     set text [read $fd]
     close $fd
+    regsub -all {(^|\n)[[:space:]]*\.section[[:space:]]*\.gnu\.lto_(?:[^\n]*\n(?![[:space:]]*\.(section|text|data|bss)))*[^\n]*\n} $text {\1} text
 
     set result_count [llength [regexp -inline -all -- $pattern $text]]
     if {$result_count == $times} {
@@ -548,6 +565,7 @@ proc scan-assembler-dem { args } {
 
     set output [remote_exec host "$cxxfilt" "" "$output_file"]
     set text [lindex $output 1]
+    regsub -all {(^|\n)[[:space:]]*\.section[[:space:]]*\.gnu\.lto_(?:[^\n]*\n(?![[:space:]]*\.(section|text|data|bss)))*[^\n]*\n} $text {\1} text
 
     if [regexp -- $pattern $text] {
 	pass "$testcase scan-assembler-dem $pp_pattern"
@@ -604,6 +622,7 @@ proc scan-assembler-dem-not { args } {
 
     set output [remote_exec host "$cxxfilt" "" "$output_file"]
     set text [lindex $output 1]
+    regsub -all {(^|\n)[[:space:]]*\.section[[:space:]]*\.gnu\.lto_(?:[^\n]*\n(?![[:space:]]*\.(section|text|data|bss)))*[^\n]*\n} $text {\1} text
 
     if ![regexp -- $pattern $text] {
 	pass "$testcase scan-assembler-dem-not $pp_pattern"
diff --git a/gcc/testsuite/gcc.dg/scantest-lto.c b/gcc/testsuite/gcc.dg/scantest-lto.c
new file mode 100644
index 00000000000..5f8abaf77f3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/scantest-lto.c
@@ -0,0 +1,9 @@
+/* { dg-options "-O2 -flto" } */
+
+void foo ()
+{
+}
+
+/* Check that scan-assembler* directives skip the LTO section.  */
+/* { dg-final { scan-assembler-not "ascii" } } */
+/* { dg-final { scan-assembler-times "ascii" 0 } } */

  parent reply	other threads:[~2023-11-08 16:01 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-27  9:26 committed [RISC-V]: Harden test scan patterns Joern Rennecke
2023-09-27 17:22 ` Jeff Law
2023-09-27 18:22   ` Joern Rennecke
2023-09-27 20:14     ` Jeff Law
2023-09-27 22:12       ` Andrew Pinski
2023-09-27 23:21       ` Vineet Gupta
2023-09-29 13:54         ` Jeff Law
2023-09-30 21:12           ` Joern Rennecke
2023-10-11  4:48             ` Joern Rennecke
2023-10-11  7:12               ` Joern Rennecke
2023-11-08 15:14               ` Joern Rennecke
2023-11-08 16:00           ` Joern Rennecke [this message]
2023-11-10  6:02             ` RFA: make scan-assembler* ignore LTO sections (Was: Re: committed [RISC-V]: Harden test scan patterns) Jeff Law

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMqJFCohe0qW4BGjbXSvBauJeAzkqoNNbSU+rCZV-jJgo+uAKg@mail.gmail.com \
    --to=joern.rennecke@embecosm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jeffreyalaw@gmail.com \
    --cc=vineetg@rivosinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).