Patchwork Fix PR c/43384: Segmentation fault with invalid K&R-like code

login
register
mail settings
Submitter Simon Martin
Date Oct. 31, 2010, 6:07 a.m.
Message ID <4CCD079D.9040107@users.sourceforge.net>
Download mbox | patch
Permalink /patch/69698/
State New
Headers show

Comments

Simon Martin - Oct. 31, 2010, 6:07 a.m.
Hello all,

The cases in that PR are all linked to an invalid initialization of some 
K&R style function argument:

====
void c_direct(par)
      void *par = &&lab;
{}
void foo(p, q)
      int *p = &q;
{}
void bar(i)
      int j = i;
{}
====

There are two problems:
    1. ICE when initializing the argument with the address of a label
    2. ICE when initializing it with error_mark_node

The attached patch fixes both cases, by respectively (1) handling 
invalid references to labels in cases we have 'current_function_decl' 
but not 'current_function_scope' and (2) skipping erroneous parameters 
in 'store_parm_decls_oldstyle'

I've successfully bootstrapped and tested this on x86_64-apple-darwin-9. 
Is it OK for trunk?

Best regards,
     Simon
2010-11-01  Simon Martin  <simartin@users.sourceforge.net>

	PR c/43384
	* c-decl.c (lookup_label): Labels can only be referenced in a
	function's scope. 
	(store_parm_decls_oldstyle): Skip erroneous parameters.

2010-11-01  Simon Martin  <simartin@users.sourceforge.net>

	PR c/43384
	* gcc.dg/parser-error-3.c: New test.
/* PR c/43384 */
/* { dg-do "compile" } */

void c_direct(par)
     void *par = &&lab; /* { dg-error "is initialized|non-standard|outside of" } */
{}

void foo(p, q)
     int *p = &q; /* { dg-error "initialized|undeclared" } */
{}

void bar(i)
     int j = i; /* { dg-error "initialized|undeclared|no such parameter" } */
{}
Joseph S. Myers - Nov. 6, 2010, 5:29 p.m.
On Sun, 31 Oct 2010, Simon Martin wrote:

> There are two problems:
>    1. ICE when initializing the argument with the address of a label
>    2. ICE when initializing it with error_mark_node
> 
> The attached patch fixes both cases, by respectively (1) handling invalid
> references to labels in cases we have 'current_function_decl' but not
> 'current_function_scope' and (2) skipping erroneous parameters in
> 'store_parm_decls_oldstyle'
> 
> I've successfully bootstrapped and tested this on x86_64-apple-darwin-9. Is it
> OK for trunk?

OK.

Patch

Index: gcc/c-decl.c
===================================================================
--- gcc/c-decl.c	(revision 166064)
+++ gcc/c-decl.c	(working copy)
@@ -3013,7 +3013,7 @@ 
   tree label;
   struct c_label_vars *label_vars;
 
-  if (current_function_decl == 0)
+  if (current_function_scope == 0)
     {
       error ("label %qE referenced outside of any function", name);
       return 0;
@@ -7847,6 +7847,9 @@ 
       if (b && B_IN_CURRENT_SCOPE (b))
 	{
 	  decl = b->decl;
+	  /* Skip erroneous parameters.  */
+	  if (decl == error_mark_node)
+	    continue;
 	  /* If we got something other than a PARM_DECL it is an error.  */
 	  if (TREE_CODE (decl) != PARM_DECL)
 	    error_at (DECL_SOURCE_LOCATION (decl),