On Wed, Dec 9, 2020 at 2:39 AM Andreas Schwab <sch...@linux-m68k.org> wrote:
>
> This breaks make -C gcc check-go RUNTESTFLAGS="go-test.exp=chan.go":
>
> ERROR: tcl error sourcing 
> /opt/gcc/gcc-20201209/gcc/testsuite/go.test/go-test.exp.
> ERROR: couldn't compile regular expression pattern: parentheses () not 
> balanced
>     while executing
> "regsub -all "(^|\n)(\[^\n\]+$line\[^\n\]*($pattern)\[^\n\]*\n?)+" 
> $comp_output "\n" comp_output"
>     (procedure "saved-dg-test" line 125)
>     invoked from within
> "saved-dg-test chan.go {  -O } {-fno-show-column  -pedantic-errors }"
>     ("eval" body line 1)
>     invoked from within
> "eval saved-dg-test $args "
>     (procedure "dg-test" line 1)
>     invoked from within
> "dg-test $test "$flags $flags_t" ${default-extra-flags}"
>     (procedure "go-dg-runtest" line 24)
>     invoked from within
> "go-dg-runtest $filename "" "-fno-show-column $DEFAULT_GOCFLAGS $opts""
>     (procedure "errchk" line 83)
>     invoked from within
> "errchk $test """
>     (procedure "go-gc-tests" line 309)
>     invoked from within
> "go-gc-tests"
>     (file "/opt/gcc/gcc-20201209/gcc/testsuite/go.test/go-test.exp" line 1217)
>     invoked from within
> "source /opt/gcc/gcc-20201209/gcc/testsuite/go.test/go-test.exp"
>     ("uplevel" body line 1)
>     invoked from within
> "uplevel #0 source /opt/gcc/gcc-20201209/gcc/testsuite/go.test/go-test.exp"
>     invoked from within
> "catch "uplevel #0 source $test_file_name""


Thanks.  I managed to miss that.

I read up on TCL syntax, and rewrote the regexp quoting to use curly
braces instead of double quotes, which makes it much simpler.  This
version fixes that problem and should hopefully work going forward.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian

* go.test/go-test.exp (errchk): Rewrite regexp quoting to use
curly braces, making it much simpler.
7c1feeb579c4d0cc3c8e633360eb77754bc70fa7
diff --git a/gcc/testsuite/go.test/go-test.exp 
b/gcc/testsuite/go.test/go-test.exp
index d129e1c65da..d11a2c2bba4 100644
--- a/gcc/testsuite/go.test/go-test.exp
+++ b/gcc/testsuite/go.test/go-test.exp
@@ -101,50 +101,32 @@ proc errchk { test opts } {
        set changed ""
        while { $changed != $copy_line } {
            set changed $copy_line
-           regsub "\(// \[^\"\]*\"\[^\"\]*\)\" \"" $copy_line "\\1|" out_line
+           regsub {(// [^"]*"[^"]*)" "} $copy_line {\1|} out_line
            set copy_line $out_line
        }
 
-       regsub "// \(GCCGO_\)?ERROR \"\(\[^\"\]*\)\" *\(\\*/\)?$" $copy_line 
"// \{ dg-error \"\\2\" \}\\3" out_line
-       if [string match "*dg-error*\\\[*" $out_line] {
-           set index [string first "dg-error" $out_line]
-           regsub -start $index -all "\\\\\\\[" $out_line "\\\\\\\\\\\[" 
out_line
-       }
-       if [string match "*dg-error*\\\]*" $out_line] {
-           set index [string first "dg-error" $out_line]
-           regsub -start $index -all "\\\\\\\]" $out_line "\\\\\\\\\\\]" 
out_line
-       }
-       if [string match "*dg-error*.\**" $out_line] {
-           # I worked out the right number of backslashes by
-           # experimentation, not analysis.
-           regsub -all "\\.\\*" $out_line "\\\\\[ -~\\\\\]*" out_line
-       }
-       if [string match "*dg-error*\\\[?\\\]*" $out_line] {
-           set index [string first "dg-error" $out_line]
-           regsub -all "\\\[\(.\)\\\]" $out_line "\\\\\[\\1\\\\\]" out_line
-       }
-       if [string match "*dg-error*\{*" $out_line] {
-           set index [string first "dg-error" $out_line]
-           regsub -start $index -all "\(\[^\\\\]\)\{" $out_line 
"\\1\\\\\[\\\{\\\\\]" out_line
-       }
-       if [string match "*dg-error*\}*\}" $out_line] {
-           set index [string first "dg-error" $out_line]
-           regsub -start $index -all "\(\[^\\\\]\)\}\(.\)" $out_line 
"\\1\\\\\[\\\}\\\\\]\\2" out_line
-       }
-       if [string match "*dg-error*\\\[^\\\\\]\(*" $out_line] {
-           set index [string first "dg-error" $out_line]
-           regsub -start $index -all "\\\\\\\(" $out_line "\\\\\[\\\(\\\\\]" 
out_line
-       }
-       if [string match "*dg-error*\\\[^\\\\\]\)*\}" $out_line] {
-           set index [string first "dg-error" $out_line]
-           regsub -start $index -all "\\\\\\\)\(.\)" $out_line 
"\\\\\[\\\)\\\\\]\\1" out_line
-       }
-       # Special case for bug332, in which the error message wants to
-       # match the file name, which is not what dg-error expects.
-       if [string match "*dg-error*bug332*" $out_line] {
-           set index [string first "dg-error" $out_line]
-           regsub -start $index "bug332" $out_line "undefined type" out_line
+       set index [string first // $copy_line]
+       set eindex [string first ERROR $copy_line]
+       if { $index >= 0 && $eindex > $index } {
+           # We're putting the regexp in curly braces, so replace any
+           # curly braces in the regexp with hex escapes.
+           regsub -start $index -all "\{" $copy_line {\x7b} copy_line
+           regsub -start $index -all "\}" $copy_line {\x7d} copy_line
+
+           # Replace .* with [ -~]* because .* will eat newlines.
+           # We can't easily use (?n) because this regexp will appear
+           # in the middle of a large regexp.
+           regsub -all {\.\*} $copy_line {[ -~]*} copy_line
        }
+
+       # Change
+       #   // ERROR "string"
+       # to
+       #   // { dg-error {string} }
+       # The latter is what go-dg-runtest expects.
+       # Retain an optional trailing */, for syntax/semi6.go.
+       regsub {// (GCCGO_)?ERROR "([^"]*)" *(\*/)?$} $copy_line "// \{ 
dg-error \{\\2\} \}\\3" out_line
+
        puts $fdout $out_line
     }
     close $fdin

Reply via email to