]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Refactor duplicated code into 'gcc/testsuite/lib/gcc-dg.exp:find-dg-do-what'
authorThomas Schwinge <tschwinge@baylibre.com>
Fri, 21 Feb 2025 18:42:28 +0000 (19:42 +0100)
committerThomas Schwinge <tschwinge@baylibre.com>
Sat, 22 Feb 2025 21:37:50 +0000 (22:37 +0100)
No change in behavior intended.

gcc/testsuite/
* 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.

gcc/testsuite/lib/gcc-dg.exp
gcc/testsuite/lib/target-supports.exp

index 70be7a8d5fd1c2a0aa6dd1638eabce14482cc282..6e9a7b207ab83316c4adb093a7833fdc1de35134 100644 (file)
@@ -1369,3 +1369,19 @@ proc gcc-transform-out-of-tree { args } {
 
 set additional_prunes ""
 set dg_runtest_extra_prunes ""
+
+# Find the 'dg-do-what' variable living inside DejaGnu's 'dg-test' procedure,
+# as a local variable.  We start looking at the second-outer frame: this way,
+# 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 lookup_level 2
+    while true {
+       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
+           return ${dg-do-what}
+       }
+       incr lookup_level
+    }
+}
index 7eab76a7eb66b81d00a1d0f557354cff26641bab..7b3172d55b4501238de9cc97429422e6368908d6 100644 (file)
@@ -652,15 +652,7 @@ proc check_effective_target_trampolines { } {
 proc check_effective_target_stack_size { } {
     # For nvptx target, stack size limits are relevant for execution only.
     if { [istarget nvptx-*-*] } {
-       # Find 'dg-do-what' in an outer frame.
-       set level 1
-       while true {
-           upvar $level dg-do-what dg-do-what
-           if [info exists dg-do-what] then break
-           incr level
-       }
-       verbose "check_effective_target_stack_size: found dg-do-what at level $level" 2
-
+       set dg-do-what [find-dg-do-what]
        if { ![string equal [lindex ${dg-do-what} 0] run] } {
            return 0
        }
@@ -1021,15 +1013,7 @@ proc check_effective_target_alloca {} {
                return 0
            }
 
-           # Find 'dg-do-what' in an outer frame.
-           set level 1
-           while true {
-               upvar $level dg-do-what dg-do-what
-               if [info exists dg-do-what] then break
-               incr level
-           }
-           verbose "check_effective_target_alloca: found dg-do-what at level $level" 2
-
+           set dg-do-what [find-dg-do-what]
            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',