diff mbox

[C] Fix ICE-on-invalid with old-style-parameter-declaration and __func__ (PR c/71265)

Message ID 20160525140127.GD17920@redhat.com
State New
Headers show

Commit Message

Marek Polacek May 25, 2016, 2:01 p.m. UTC
Another ICE on invalid with old-style-parameter-declaration, this time with
__func__.  The problem is in c_make_fname_decl:

if (current_function_decl
    && (!seen_error () || current_function_scope))
  bind (..., current_function_scope, ...)

The condition is wrong; if current_function_scope is null then we must not call
bind, otherwise we segv.  That's what happens here because seen_error () is 0
at that point.  The seen_error() check doesn't make sense to me here, so I
suggest removing it, so that we never call bind() here with a null scope.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2016-05-25  Marek Polacek  <polacek@redhat.com>

	PR c/71265
	* c-decl.c (c_make_fname_decl): Don't check seen_error.

	* gcc.dg/noncompile/pr71265.c: New test.


	Marek

Comments

Joseph Myers May 25, 2016, 2:51 p.m. UTC | #1
On Wed, 25 May 2016, Marek Polacek wrote:

> Another ICE on invalid with old-style-parameter-declaration, this time with
> __func__.  The problem is in c_make_fname_decl:
> 
> if (current_function_decl
>     && (!seen_error () || current_function_scope))
>   bind (..., current_function_scope, ...)
> 
> The condition is wrong; if current_function_scope is null then we must not call
> bind, otherwise we segv.  That's what happens here because seen_error () is 0
> at that point.  The seen_error() check doesn't make sense to me here, so I
> suggest removing it, so that we never call bind() here with a null scope.
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?

OK.
diff mbox

Patch

diff --git gcc/c/c-decl.c gcc/c/c-decl.c
index 9441fbb..d7c3783 100644
--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -3989,7 +3989,7 @@  c_make_fname_decl (location_t loc, tree id, int type_dep)
 	 the __FUNCTION__ is believed to appear in K&R style function
 	 parameter declarator.  In that case we still don't have
 	 function_scope.  */
-      && (!seen_error () || current_function_scope))
+      && current_function_scope)
     {
       DECL_CONTEXT (decl) = current_function_decl;
       bind (id, decl, current_function_scope,
diff --git gcc/testsuite/gcc.dg/noncompile/pr71265.c gcc/testsuite/gcc.dg/noncompile/pr71265.c
index e69de29..9c62aab 100644
--- gcc/testsuite/gcc.dg/noncompile/pr71265.c
+++ gcc/testsuite/gcc.dg/noncompile/pr71265.c
@@ -0,0 +1,7 @@ 
+/* PR c/71265 */
+/* { dg-do compile } */
+
+void ID (ID)
+  int ID [__func__]; /* { dg-error "size of array .ID. has non-integer type" } */
+{
+}