https://gcc.gnu.org/g:eb9cbd22f917aaa522bdb1d825ad6119e0ab196d

commit eb9cbd22f917aaa522bdb1d825ad6119e0ab196d
Author: Thomas Schwinge <tschwi...@baylibre.com>
Date:   Fri Feb 21 21:54:59 2025 +0100

    Gracefully handle the case that 
'gcc/testsuite/lib/gcc-dg.exp:find-dg-do-what' has not been called (indirectly) 
from 'dg-test'
    
    No change in behavior intended.
    
            gcc/testsuite/
            * lib/gcc-dg.exp (find-dg-do-what): Gracefully handle the case
            that we've not be called (indirectly) from 'dg-test'.
            * lib/target-supports.exp (check_effective_target_stack_size)
            (check_effective_target_alloca): Catch this.
    
    (cherry picked from commit e8e228acffe382f003a7f2ca37c068a5e0c74df4)

Diff:
---
 gcc/testsuite/ChangeLog.omp           | 8 ++++++++
 gcc/testsuite/lib/gcc-dg.exp          | 6 +++++-
 gcc/testsuite/lib/target-supports.exp | 6 ++++++
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index d416d476a6d3..1316b67196ad 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -3,6 +3,14 @@
        Backported from trunk:
        2025-02-22  Thomas Schwinge  <tschwi...@baylibre.com>
 
+       * lib/gcc-dg.exp (find-dg-do-what): Gracefully handle the case
+       that we've not be called (indirectly) from 'dg-test'.
+       * lib/target-supports.exp (check_effective_target_stack_size)
+       (check_effective_target_alloca): Catch this.
+
+       Backported from trunk:
+       2025-02-22  Thomas Schwinge  <tschwi...@baylibre.com>
+
        * lib/gcc-dg.exp (proc find-dg-do-what): New.
        * lib/target-supports.exp (check_effective_target_stack_size)
        (check_effective_target_alloca): Use it.
diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp
index ffb596d80b88..87c263900ce5 100644
--- a/gcc/testsuite/lib/gcc-dg.exp
+++ b/gcc/testsuite/lib/gcc-dg.exp
@@ -1457,8 +1457,9 @@ set dg_runtest_extra_prunes ""
 # the caller of 'find-dg-do-what' may maintain a local 'dg-do-what' variable
 # without interfering with this search.
 proc find-dg-do-what { } {
+    set level [info level]
     set lookup_level 2
-    while true {
+    while { $lookup_level <= $level } {
        upvar $lookup_level dg-do-what dg-do-what
        if { [info exists dg-do-what] } {
            verbose "find-dg-do-what: found 'dg-do-what' at level 
$lookup_level: ${dg-do-what}" 2
@@ -1466,4 +1467,7 @@ proc find-dg-do-what { } {
        }
        incr lookup_level
     }
+    # We've not be called (indirectly) from 'dg-test'.
+    verbose "find-dg-do-what: have not found 'dg-do-what'" 2
+    return [list]
 }
diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp
index 803a26b334cf..8518909e5167 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -652,6 +652,9 @@ proc check_effective_target_stack_size { } {
     # For nvptx target, stack size limits are relevant for execution only.
     if { [istarget nvptx-*-*] } {
        set dg-do-what [find-dg-do-what]
+       if { ![llength ${dg-do-what}] } {
+           error "unexpected call stack"
+       }
        if { ![string equal [lindex ${dg-do-what} 0] run] } {
            return 0
        }
@@ -999,6 +1002,9 @@ proc check_effective_target_alloca {} {
            }
 
            set dg-do-what [find-dg-do-what]
+           if { ![llength ${dg-do-what}] } {
+               error "unexpected call stack"
+           }
            if { [string equal [lindex ${dg-do-what} 0] run] } {
                # For 'dg-do run', it additionally depends on runtime support.
                # (If not supported, we don't try to demote 'run' to 'link',

Reply via email to