re PR c/28419 (ICE using __FUNCTION__ in invalid code)
authorJan Hubicka <jh@suse.cz>
Fri, 13 Oct 2006 07:41:53 +0000 (09:41 +0200)
committerJan Hubicka <hubicka@gcc.gnu.org>
Fri, 13 Oct 2006 07:41:53 +0000 (07:41 +0000)
PR c/28419
* c-decl.c (c_make_fname_decl): Do not segfault in case where
current_function_decl is set but current_function_scope is not.

* gcc.dg/pr28319.c: New test.

From-SVN: r117684

gcc/ChangeLog
gcc/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr28419.c [new file with mode: 0644]

index 4edb41e588ed18589b4270aa4d05b0a07a8f6b70..ce7336f8455b8b15f081c64ac010e5e49d4fc812 100644 (file)
@@ -1,3 +1,9 @@
+2006-10-12  Jan Hubicka  <jh@suse.cz>
+
+       PR c/28419
+       * c-decl.c (c_make_fname_decl): Do not segfault in case where
+       current_function_decl is set but current_function_scope is not.
+
 2006-10-12  Jie Zhang  <jie.zhang@analog.com>
 
        * config/bfin/bfin.md (eh_return): Call emit_jump_insn instead of
index 3897bea36b6532b96e5e17ce99b5626b6a6ef44b..4b3ee627cec1bf8656bd6fc27f07623da403e4b7 100644 (file)
@@ -2791,7 +2791,16 @@ c_make_fname_decl (tree id, int type_dep)
 
   TREE_USED (decl) = 1;
 
-  if (current_function_decl)
+  if (current_function_decl
+      /* For invalid programs like this:
+        
+         void foo()
+         const char* p = __FUNCTION__;
+        
+        the __FUNCTION__ is believed to appear in K&R style function
+        parameter declarator.  In that case we still don't have
+        function_scope.  */
+      && (!errorcount || current_function_scope))
     {
       DECL_CONTEXT (decl) = current_function_decl;
       bind (id, decl, current_function_scope,
index 7952579c81da11f4c13f777782e46053ab690638..5ce3b3872118d7cb96a74f047fb371f794c16eb7 100644 (file)
@@ -1,5 +1,9 @@
-2006-10-12  Mark Mitchell  <mark@codesourcery.com>
+2006-10-12  Jan Hubicka  <jh@suse.cz>
+
+       PR c/28419
+       * gcc.dg/pr28319.c: New test.
 
+2006-10-12  Mark Mitchell  <mark@codesourcery.com>
        PR c++/29318
        * g++.dg/ext/vla4.C: New test.
 
diff --git a/gcc/testsuite/gcc.dg/pr28419.c b/gcc/testsuite/gcc.dg/pr28419.c
new file mode 100644 (file)
index 0000000..a1aa4bf
--- /dev/null
@@ -0,0 +1,3 @@
+/* { dg-do compile } */
+void foo() 
+const char* p = __FUNCTION__; /* { dg-error "" } */