diff mbox

Add error message for mismatched parentheses in reservation string

Message ID 51B1DC52.9000604@mentor.com
State New
Headers show

Commit Message

Tom de Vries June 7, 2013, 1:12 p.m. UTC
Vladimir,

If I introduce an unbalanced parentheses error in a reservation string, f.i. in
athlon.md using the following patch:
...

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.

Comments

Vladimir Makarov June 11, 2013, 12:49 a.m. UTC | #1
On 13-06-07 9:12 AM, Tom de Vries wrote:
> 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?
>
>
Yes.  Thank you for fixing that, Tom.
diff mbox

Patch

diff --git a/gcc/genautomata.c b/gcc/genautomata.c
index 3665d95..add4624 100644
--- a/gcc/genautomata.c
+++ b/gcc/genautomata.c
@@ -1672,6 +1672,10 @@  gen_regexp_sequence (const char *str)
   int i;
 
   sequence_vect = get_str_vect (str, &els_num, ',', TRUE);
+  if (els_num == -1)
+    fatal ("unbalanced parentheses in reservation `%s'", str);
+  if (sequence_vect == NULL)
+    fatal ("invalid reservation `%s'", str);
   if (els_num > 1)
     {
       sequence = XCREATENODEVAR (struct regexp, sizeof (struct regexp)