This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR c/28419: ICE using __FUNCTION__ in invalid code

Hello all.

We get an ICE when compiling the following invalid C code with the latest SVN 

==== cut here ====
void foo() x;
const char* p = __FUNCTION__;
==== cut here ====

pr28419.c: In function 'foo':
pr28419.c:5: error: expected declaration specifiers before 'x'
pr28419.c:7: error: parameter 'p' is initialized
pr28419.c:0: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:> for instructions.

We get in a situation where current_function_decl is not NULL, but 
current_function_scope is, because we're parsing an old-style function 
parameter declaration. Since c_make_fname_decl only checks for the non-nullity 
of current_function_decl before pushing the declaration for __FUNCTION__ into 
current_function_scope (which gets dereferenced...), we get a segmentation 
fault (I hope that my "analysis" is not completely wrong; I'm just starting to 
dig into GCC's code...).

The attached patch fixes this by also checking that current_function_scope is 
not NULL before calling "bind" in "c_make_fname_decl"; pr28419.c is a test 
case to be added to the testsuite.

Boostrapped on i686-pc-linux-gnu. I've tried to regtest this, and I got 7 
unexpected failures for gcc (none for the other default languages). I'm 
currently re-regtesting to check that those also occur with SVN head on my 

Is this patch OK? If so, could someone commit it for me since I don't have SVN
write access?

Thanks in advance.

Best regards,

Attachment: CL_pr28419
Description: Text document

/* This used to ICE in bind */

/* { dg-do compile } */

void foo(x, p) x; /* { dg-error "expected declaration specifiers before" } */

const char* p = __FUNCTION__; /* { dg-error "is initialized||at end of input" } */
Index: gcc/c-decl.c
*** gcc/c-decl.c	(revision 115623)
--- gcc/c-decl.c	(working copy)
*************** c_make_fname_decl (tree id, int type_dep
*** 2785,2791 ****
    TREE_USED (decl) = 1;
!   if (current_function_decl)
        DECL_CONTEXT (decl) = current_function_decl;
        bind (id, decl, current_function_scope,
--- 2785,2791 ----
    TREE_USED (decl) = 1;
!   if (current_function_decl && current_function_scope)
        DECL_CONTEXT (decl) = current_function_decl;
        bind (id, decl, current_function_scope,

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]