Add error message for mismatched parentheses in reservation string

Tom de Vries Tom_deVries@mentor.com
Fri Jun 7 13:13:00 GMT 2013


Vladimir,

If I introduce an unbalanced parentheses error in a reservation string, f.i. in
athlon.md using the following patch:
...
diff --git a/gcc/config/i386/athlon.md b/gcc/config/i386/athlon.md
index d872b8f..b1ed5cd 100644
--- a/gcc/config/i386/athlon.md
+++ b/gcc/config/i386/athlon.md
@@ -90,7 +90,7 @@
 				     (athlon-decode0 | athlon-decode1
 				     | athlon-decode2)")
 ;; Double instructions behaves like two direct instructions.
-(define_reservation "athlon-double" "((athlon-decode2, athlon-decode0)
+(define_reservation "athlon-double" "(athlon-decode2, athlon-decode0)
 				     | (nothing,(athlon-decode0 + athlon-decode1))
 				     | (nothing,(athlon-decode1 + athlon-decode2)))")
...

and rebuild cc1, I get a segmentation fault:
...
build/genautomata gcc/config/i386/i386.md \
	  insn-conditions.md > tmp-automata.c
/bin/bash: line 1: 18077 Segmentation fault      (core dumped) build/genautomata
gcc/config/i386/i386.md insn-conditions.md > tmp-automata.c
make: *** [s-automata] Error 139
...

The segmentation fault happens because sequence_vect is set to NULL here in
gen_regexp_sequence in genautomata.c:
...
  sequence_vect = get_str_vect (str, &els_num, ',', TRUE);
  if (els_num > 1)
...

and sequence_vect is dereferenced here:
...
  else
    return gen_regexp_oneof (sequence_vect[0]);
...

The patch adds error checking for the specific case of unbalanced parentheses,
and for sequence_vect == NULL in general.

Using the patch the error message becomes:
...
genautomata: unbalanced parentheses in reservation `(athlon-decode2, athlon-decode0)
				     | (nothing,(athlon-decode0 + athlon-decode1))
				     | (nothing,(athlon-decode1 + athlon-decode2)))'
...

Tested by completing a non-bootstrap build.

OK for trunk?

Thanks,
- Tom

2013-06-07  Tom de Vries  <tom@codesourcery.com>

	* genautomata.c (gen_regexp_sequence): Handle els_num == -1.  Handle
	sequence_vect == NULL.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: reservation-unbalanced-parentheses.patch
Type: text/x-patch
Size: 523 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20130607/7ee92801/attachment.bin>


More information about the Gcc-patches mailing list