[C/C++ PATCH]fix bug 845

Nathan Sidwell nathan@codesourcery.com
Fri Nov 24 02:33:00 GMT 2000


Hi,
I've installed the attached obvious patch which fixes bug 845
(that's a C++ bug report, but applies to C as well).

__builtin_vararg was being treated in the unary exprs, rather
than the primaries (where function call is for instance). This meant
that trying to use va_arg as a primary of another primary expr
failed.

booted & tested on i686-pc-linux-gnu.

nathan
-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2000-11-24  Nathan Sidwell  <nathan@codesourcery.com>

	* c-parse.in (unary_expr): Move VA_ARG from here ...
	(primary): ... to here.

cp:
2000-11-24  Nathan Sidwell  <nathan@codesourcery.com>

	* parse.y (unary_expr): Move VA_ARG from here ...
	(primary): ... to here.

testsuite:
2000-11-24  Nathan Sidwell  <nathan@codesourcery.com>

	* g++.old-deja/g++.other/vaarg4.C: New test.
	* gcc.c-torture/compile/20001123-1.c: New test.

Index: c-parse.in
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-parse.in,v
retrieving revision 1.70
diff -c -3 -p -r1.70 c-parse.in
*** c-parse.in	2000/11/21 07:39:51	1.70
--- c-parse.in	2000/11/24 10:04:53
*************** unary_expr:
*** 514,521 ****
  		{ $$ = build_unary_op (REALPART_EXPR, $2, 0); }
  	| IMAGPART cast_expr %prec UNARY
  		{ $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
- 	| VA_ARG '(' expr_no_commas ',' typename ')'
- 		{ $$ = build_va_arg ($3, groktypename ($5)); }
  	;
  
  sizeof:
--- 514,519 ----
*************** primary:
*** 688,693 ****
--- 686,693 ----
  		}
  	| primary '(' exprlist ')'   %prec '.'
  		{ $$ = build_function_call ($1, $3); }
+ 	| VA_ARG '(' expr_no_commas ',' typename ')'
+ 		{ $$ = build_va_arg ($3, groktypename ($5)); }
  	| primary '[' expr ']'   %prec '.'
  		{ $$ = build_array_ref ($1, $3); }
  	| primary '.' identifier
Index: cp/parse.y
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/parse.y,v
retrieving revision 1.201
diff -c -3 -p -r1.201 parse.y
*** parse.y	2000/11/21 07:39:52	1.201
--- parse.y	2000/11/24 10:04:54
*************** unary_expr:
*** 1252,1260 ****
  		{ $$ = build_x_unary_op (REALPART_EXPR, $2); }
  	| IMAGPART cast_expr %prec UNARY
  		{ $$ = build_x_unary_op (IMAGPART_EXPR, $2); }
- 	| VA_ARG '(' expr_no_commas ',' type_id ')'
- 		{ $$ = build_x_va_arg ($3, groktypename ($5.t));
- 		  check_for_new_type ("__builtin_va_arg", $5); }
  	;
  
  new_placement:
--- 1252,1257 ----
*************** primary:
*** 1562,1567 ****
--- 1559,1567 ----
                 { $$ = finish_call_expr ($1, $3, 0); }
  	| primary LEFT_RIGHT
                 { $$ = finish_call_expr ($1, NULL_TREE, 0); }
+ 	| VA_ARG '(' expr_no_commas ',' type_id ')'
+ 		{ $$ = build_x_va_arg ($3, groktypename ($5.t));
+ 		  check_for_new_type ("__builtin_va_arg", $5); }
  	| primary '[' expr ']'
  		{ $$ = grok_array_decl ($$, $3); }
  	| primary PLUSPLUS
Index: testsuite/gcc.c-torture/compile/20001123-1.c
===================================================================
RCS file: 20001123-1.c
diff -N 20001123-1.c
*** /dev/null	Tue May  5 13:32:27 1998
--- 20001123-1.c	Fri Nov 24 02:04:54 2000
***************
*** 0 ****
--- 1,11 ----
+ 
+ typedef __builtin_va_list __gnuc_va_list;
+ typedef __gnuc_va_list va_list;
+ 
+ struct X { int y; };
+ 
+ void func(va_list va)
+ {
+   char* a = __builtin_va_arg(va, char**)[0];
+   int b = __builtin_va_arg(va, struct X*)->y;
+ }
Index: testsuite/g++.old-deja/g++.other/vaarg4.C
===================================================================
RCS file: vaarg4.C
diff -N vaarg4.C
*** /dev/null	Tue May  5 13:32:27 1998
--- vaarg4.C	Fri Nov 24 02:04:55 2000
***************
*** 0 ****
--- 1,15 ----
+ // Build don't link:
+ 
+ // Bug 845. We were treating __builtin_va_arg as a unary expr, not a primary,
+ // and hence getting parse errors.
+ 
+ typedef __builtin_va_list __gnuc_va_list;
+ typedef __gnuc_va_list va_list;
+ 
+ struct X { int y; };
+ 
+ void func(va_list va)
+ {
+   char* a = __builtin_va_arg(va, char**)[0];
+   int b = __builtin_va_arg(va, X*)->y;
+ }


More information about the Gcc-patches mailing list