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

commit r16-7636-gbf3dc8c64ad13010aa07bef132bc7b21a2e7ab64
Author: Alice Carlotti <[email protected]>
Date:   Fri Jan 2 13:59:02 2026 +0000

    testsuite: Improve check-function-bodies logging
    
    When a check-function-bodies test fails, it can sometimes be hard to
    identify which part of a large function regexp is causing the failure.
    To aid debugging these failures, find the largest initial set of lines
    that matches the function, and log this separately from the remainder of
    the regexp.
    
    Additionally, add a newline before logging the function bodies, so that
    the first line has the same indentation as the rest of that function.
    
    gcc/testsuite/ChangeLog:
    
            * lib/scanasm.exp (check_function_body): Log matching portion
            of body_regexp separately.

Diff:
---
 gcc/testsuite/lib/scanasm.exp | 34 +++++++++++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/lib/scanasm.exp b/gcc/testsuite/lib/scanasm.exp
index bcd22c2d7e4e..b0df0c6ba28c 100644
--- a/gcc/testsuite/lib/scanasm.exp
+++ b/gcc/testsuite/lib/scanasm.exp
@@ -981,10 +981,38 @@ proc check_function_body { functions name body_regexp } {
     if { ![info exists up_functions($name)] } {
        return 0
     }
-    set fn_res [regexp "^$body_regexp\$" $up_functions($name)]
+    set body $up_functions($name)
+    set fn_res [regexp "^$body_regexp\$" $body]
     if { !$fn_res } {
-      verbose -log "expected: $body_regexp"
-      verbose -log "found: $up_functions($name)"
+      # Find the longest initial set of lines in body_regexp that matches the
+      # function.  We can't just use a binary search here, because adding more
+      # lines to a broken regexp might make it start to match.
+      # Unfortunately this makes runtime quadratic in the number of lines, but
+      # failures in large check-function-body regexps are hopefully rare.
+      set ok_index [string length $body_regexp]
+      incr ok_index -1
+      while { $ok_index >= 0 } {
+       set short_regexp [string range $body_regexp 0 $ok_index]
+       set match_found 0
+       # Not all initial sets of lines are valid.  Ignore any broken regexps.
+       if { ![catch { regexp "^$short_regexp" $body } res] && $res } {
+         break
+       }
+       set ok_index [string last "\n" $body_regexp $ok_index-1]
+      }
+      set head [string range $body_regexp 0 $ok_index]
+      set tail [string range $body_regexp $ok_index+1 end]
+      if { $ok_index == -1 } {
+       verbose -log "no initial matching lines"
+      } else {
+       verbose -log "initial matched regexp:\n$head"
+      }
+      if { [string length $tail] == 0 } {
+       verbose -log "excess lines found after matching regexp\n"
+      } else {
+       verbose -log "mismatch in remaining regexp:\n$tail"
+      }
+      verbose -log "compared against output:\n$body"
     }
     return $fn_res
 }

Reply via email to