[COMMITTED] testsuite: Fix dg-do-if

Message ID yddecksqnpp.fsf@CeBiTec.Uni-Bielefeld.DE
State Committed
Commit 6fe5fde6748387a74d16ac23774372b650db745e
Headers
Series [COMMITTED] testsuite: Fix dg-do-if |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply

Commit Message

Rainer Orth April 6, 2026, 12:26 p.m. UTC
  Tests that use dg-do-if ERROR when the target selector matches, e.g.

ERROR: gcc.dg/vect/vect-simd-clone-16f.c -flto -ffat-lto-objects: compile: syntax error for " dg-do-if 1 compile { target { sse2_runtime && { ! sse4_runtime } } } "

While the error message isn't particularly helpful, it's from dg.exp
(dg-do): like the other dg-* procs it expects the line number to be the
first argument.  However, dg-do-if strips that, so dg-do gets the target
selector instead of the expected action keyword.

Fixed by no longer stripping the line number.

Tested on amd64-pc-freebsd15.0 (sse2_runtime && !sse4_runtime),
i386-pc-solaris2.11 and x86_64-pc-linux-gnu (sse2_runtime &&
sse4_runtime).

Committed to trunk.


I cannot help thinking that dg-do-if is overkill: it's only used in 4
test cases and never actually worked.

	Rainer
  

Comments

Richard Sandiford April 28, 2026, 3:33 p.m. UTC | #1
Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> writes:
> Tests that use dg-do-if ERROR when the target selector matches, e.g.
>
> ERROR: gcc.dg/vect/vect-simd-clone-16f.c -flto -ffat-lto-objects:
> compile: syntax error for " dg-do-if 1 compile { target { sse2_runtime
> && { ! sse4_runtime } } } "
>
> While the error message isn't particularly helpful, it's from dg.exp
> (dg-do): like the other dg-* procs it expects the line number to be the
> first argument.  However, dg-do-if strips that, so dg-do gets the target
> selector instead of the expected action keyword.
>
> Fixed by no longer stripping the line number.
>
> Tested on amd64-pc-freebsd15.0 (sse2_runtime && !sse4_runtime),
> i386-pc-solaris2.11 and x86_64-pc-linux-gnu (sse2_runtime &&
> sse4_runtime).
>
> Committed to trunk.

Thanks for fixing this.

> I cannot help thinking that dg-do-if is overkill: it's only used in 4
> test cases and never actually worked.

The original intention might have been to support older versions of
DejaGNU, which required all dg-do lines in a testcase to specify the
same action.  Thus something like:

  /* { dg-do compile { target { ! can-assembler-this } } } */
  /* { dg-do assemble { target can-assemble-this } } */

would only work with newer DejaGNU.

Richard
  
Alexandre Oliva April 30, 2026, 2:07 a.m. UTC | #2
On Apr  6, 2026, Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> wrote:

> I cannot help thinking that dg-do-if is overkill: it's only used in 4
> test cases and never actually worked.

There are other patches pending review that add more uses.  One of them
even fixed this bug.  Someone else submitted a patch to fix it as well.
Thanks for finally getting the fix in!
  
Rainer Orth April 30, 2026, 12:26 p.m. UTC | #3
Hi Alex,

> On Apr  6, 2026, Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> wrote:
>
>> I cannot help thinking that dg-do-if is overkill: it's only used in 4
>> test cases and never actually worked.
>
> There are other patches pending review that add more uses.  One of them
> even fixed this bug.  Someone else submitted a patch to fix it as well.

I obviously missed that.  I did my patch out of pure self-preservation:
two of my test systems were affected and so I started looking into the
issue to reduce the noise.

	Rainer
  

Patch

# HG changeset patch
# Parent  eda78d3442ceaf2f46fa3d600b731501478cb561
testsuite: Fix dg-do-if

diff --git a/gcc/testsuite/lib/target-supports-dg.exp b/gcc/testsuite/lib/target-supports-dg.exp
--- a/gcc/testsuite/lib/target-supports-dg.exp
+++ b/gcc/testsuite/lib/target-supports-dg.exp
@@ -422,9 +422,8 @@  proc check-flags { args } {
 # (possibly the default) prevails.
 
 proc dg-do-if { args } {
-    set args [lreplace $args 0 0]
     # Verify the number of arguments.
-    if { [llength $args] != 2 } {
+    if { [llength $args] != 3 } {
 	error "syntax error, need a single action and target selector"
     }
 
@@ -435,7 +434,7 @@  proc dg-do-if { args } {
     }
     
     # Evaluate selector, return if it does not match.
-    switch [dg-process-target-1 [lindex $args 1]] {
+    switch [dg-process-target-1 [lindex $args 2]] {
 	"N" { return }
 	"P" { return }
     }