On Tue, Jul 01, 2025 at 06:33:12PM +0200, Jakub Jelinek wrote:
> On Tue, Jul 01, 2025 at 03:47:53PM +0200, Stefan Schulze Frielinghaus wrote:
> > In the past years I have started to use more and more function body
> > checks whenever gcc emits optimal code for a function.  With that I
> > wanted to make sure that we do not regress like introducing unnecessary
> > extends or whatever which might not have been caught by only testing the
> > "interesting"/actual part of a patch.  Thus, as long as those function
> > body checks are stable enough, i.e., not subject to insn reordering or
> > the like, I would like to make use of them in the future, too.   That
> > being said I'm wondering whether it would make sense to automatically
> > add option -fno-stack-protector for tests which make use function-body
> > checks?  If the testsuite infrastructure doesn't provide this
> > functionality trivially, I will try to keep this in mind and always add
> > the option manually.
> 
> I think even better would be to make the check-function-body UNSUPPORTED
> if there is no explicit -f{,no-}stack-protector* among
> dg-options/dg-additional-options and the option is still used.
> Because the test can be also dg-do run and it might be useful to run the
> test.

So maybe something along the lines?

diff --git a/gcc/testsuite/lib/scanasm.exp b/gcc/testsuite/lib/scanasm.exp
index 97935cb23c3..bb16ae897c1 100644
--- a/gcc/testsuite/lib/scanasm.exp
+++ b/gcc/testsuite/lib/scanasm.exp
@@ -1042,6 +1042,15 @@ proc check-function-bodies { args } {
     # The name might include a list of options; extract the file name.
     set filename [lindex $testcase 0]

+    global compiler_flags
+    set current_compiler_flags [current_compiler_flags]
+    if { [string match "* -fstack-protector* *" " ${compiler_flags} "]
+        && ![string match "* -fstack-protector* *" " ${current_compiler_flags} 
"]
+        && ![string match "* -fno-stack-protector* *" " 
${current_compiler_flags} "] } {
+       unsupported "$testcase: skip check-function-bodies due to stack 
protector"
+       return
+    }
+
     global srcdir
     set input_filename "$srcdir/$filename"
     set output_filename "[file rootname [file tail $filename]]"

I'm pretty new to tcl and didn't do extensive testing but for my few
experiments it worked so far.  I guess `string match` uses globbing so
something like "* -f(no-)?stack-protector* *" doesn't work which is why
I used two matches.

Cheers,
Stefan

> 
> Or another way could be just add a new effective target whether any kind of
> -fstack-protector{,-strong,-all} is enabled and guard the
> check-function-body directives explicitly with negation of that effective
> target.  Or perhaps have no_stack_protection effective target and use that
> to guard some directives manually.
> 
>       Jakub
> 

Reply via email to