]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Avoid overly-greedy match in dejagnu regexp.
authorJeff Law <jeffreyalaw@gmail.com>
Fri, 29 Oct 2021 15:30:15 +0000 (11:30 -0400)
committerJeff Law <jeffreyalaw@gmail.com>
Fri, 29 Oct 2021 15:30:15 +0000 (11:30 -0400)
Occasionally I've been seeing failures with the multi-line diagnostics.  It's never been clear what's causing the spurious failures, though I have long suspected a greedy regexp match.

It happened again yesterday with a local change that in no way should affect diagnostics, so I finally went searching and found that sure enough the multi-line diagnostics had a ".*" in their regexp.  According to the comments, the .* is primarily to catch any dg directives that may appear -- ie it should eat to EOL, but not multiple lines.  But a .* can indeed match a newline and cause it to eat multiple lines.

The fix is simple.  [^\r\n]* will eat to EOL, but not further.

Regression tested on x86_64 and on our internal target.

gcc/testsuite

* lib/multiline.exp (_build_multiline_regex): Use a better
regexp than .* to match up to EOL.

gcc/testsuite/lib/multiline.exp

index 0e151b6d2224a0cdb13968427aef3c500de447ee..86387f8209b856a8be87891a4db3aa741b1cb5d8 100644 (file)
@@ -331,7 +331,7 @@ proc _build_multiline_regex { multiline index } {
                # Support arbitrary followup text on each non-empty line,
                # to deal with comments containing containing DejaGnu
                # directives.
-               append rexp ".*"
+               append rexp "\[^\\n\\r\]*"
            }
        }
        append rexp "\n"