This is the mail archive of the gcc-patches@gcc.gnu.org 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]

Really fix PR18596


 Hi,

  What this patch does is throw away invalid function declarations.  The
declaration is invalid so trying to use it later on in compilation is just
going to cause problems.  I removed the function foo from funcdef-storage-1.c
so that the testcase doesn't give a error about conflicting declarations of
foo.  One being external, implicit when foo is called, and the definition
being static.

 This was bootstrapped tested on sparc-linux with no regressions.  The patch
also fixes pr18596-1.c.  Ok for mainline?

-- 
Thanks,
Jim

http://www.student.cs.uwaterloo.ca/~ja2morri/
http://phython.blogspot.com
http://open.nit.ca/wiki/?page=jim

/* { dg-do compile } */
/* { dg-options "-funit-at-a-time" } */

int f(int i)
{
  static int g(); /* { dg-error "invalid storage class" } */
  static int g() { return i; } /* { dg-error "invalid storage class" } */
  return g();
}

int k (int i)
{
  static int g (); /* { dg-error "invalid storage class" } */
  int g () {
	return i;
  }

  return g ();
}

int l (int i)
{
  auto int g ();
  static int g () { /* { dg-error "invalid storage class" } */
    return i;
  }

  static int h () { /* { dg-error "invalid storage class" } */
    return 3;
  }
  return g () + h ();
}

2004-12-19  James A. Morrison  <phython@gcc.gnu.org>

	PR c/18596
	* c-parse.in (initdcl): Don't call finish decl if start_decl fails.
	* c-decl.c (start_decl): Fail if grokdeclarator fails.
	(grokdeclarator): Fail if a function definition has an invalid storage
	class.

testsuite:
	PR c/18596
	* gcc.dg/funcdec-storage-1.c (foo): Remove.
	* gcc.dg/pr18596-1.c: Use dg-error.
	(dg-options): Use -fno-unit-at-a-time.
	* gcc.dg/pr18596-2.c: New test.
	
Index: c-parse.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-parse.in,v
retrieving revision 1.255
diff -u -p -r1.255 c-parse.in
--- c-parse.in	9 Nov 2004 10:12:14 -0000	1.255
+++ c-parse.in	16 Dec 2004 12:27:43 -0000
@@ -1330,7 +1330,8 @@ initdcl:
 	| declarator maybeasm maybe_attribute
 		{ tree d = start_decl ($1, current_declspecs, false,
 				       chainon ($3, all_prefix_attributes));
-		  finish_decl (d, NULL_TREE, $2);
+		  if (d)
+		    finish_decl (d, NULL_TREE, $2);
                 }
 	;
 
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.612
diff -u -p -r1.612 c-decl.c
--- c-decl.c	30 Nov 2004 00:32:23 -0000	1.612
+++ c-decl.c	16 Dec 2004 12:27:46 -0000
@@ -2952,6 +2952,8 @@ start_decl (struct c_declarator *declara
 
   decl = grokdeclarator (declarator, declspecs,
 			 NORMAL, initialized, NULL);
+  if (!decl)
+    return 0;
 
   deprecated_state = DEPRECATED_NORMAL;
 
@@ -4428,14 +4430,9 @@ grokdeclarator (const struct c_declarato
       }
     else if (TREE_CODE (type) == FUNCTION_TYPE)
       {
-	decl = build_decl (FUNCTION_DECL, declarator->u.id, type);
-	decl = build_decl_attribute_variant (decl, decl_attr);
-
 	if (storage_class == csc_register || threadp)
 	  {
 	    error ("invalid storage class for function %qs", name);
-	    if (DECL_INITIAL (decl) != NULL_TREE)
-	      DECL_INITIAL (decl) = error_mark_node;
 	   }
 	else if (current_scope != file_scope)
 	  {
@@ -4449,14 +4446,19 @@ grokdeclarator (const struct c_declarato
 		if (pedantic)
 		  pedwarn ("invalid storage class for function %qs", name);
 	      }
-	    if (storage_class == csc_static)
+	    else if (storage_class == csc_static)
 	      {
 	        error ("invalid storage class for function %qs", name);
-		if (DECL_INITIAL (decl) != NULL_TREE)
-		  DECL_INITIAL (decl) = error_mark_node;
+	        if (funcdef_flag)
+		  storage_class = declspecs->storage_class = csc_none;
+		else
+		  return 0;
 	      }
 	  }
 
+	decl = build_decl (FUNCTION_DECL, declarator->u.id, type);
+	decl = build_decl_attribute_variant (decl, decl_attr);
+
 	DECL_LANG_SPECIFIC (decl) = GGC_CNEW (struct lang_decl);
 
 	if (pedantic && type_quals && !DECL_IN_SYSTEM_HEADER (decl))
Index: testsuite/gcc.dg/pr18596-1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/pr18596-1.c,v
retrieving revision 1.1
diff -u -r1.1 pr18596-1.c
--- testsuite/gcc.dg/pr18596-1.c	30 Nov 2004 00:32:34 -0000	1.1
+++ testsuite/gcc.dg/pr18596-1.c	19 Dec 2004 17:39:13 -0000
@@ -1,7 +1,32 @@
 /* { dg-do compile } */
+/* { dg-options "-fno-unit-at-a-time" } */
+
 int f(int i)
 {
-  static int g(); /* { dg-warning "invalid storage class" } */
-  static int g() { return i; } /* { dg-warning "invalid storage class" } */
+  static int g(); /* { dg-error "invalid storage class" } */
+  static int g() { return i; } /* { dg-error "invalid storage class" } */
   return g();
 }
+
+int k (int i)
+{
+  static int g (); /* { dg-error "invalid storage class" } */
+  int g () {
+	return i;
+  }
+
+  return g ();
+}
+
+int l (int i)
+{
+  auto int g ();
+  static int g () { /* { dg-error "invalid storage class" } */
+    return i;
+  }
+
+  static int h () { /* { dg-error "invalid storage class" } */
+    return 3;
+  }
+  return g () + h ();
+}
Index: testsuite/gcc.dg/funcdef-storage-1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/funcdef-storage-1.c,v
retrieving revision 1.2
diff -u -r1.2 funcdef-storage-1.c
--- testsuite/gcc.dg/funcdef-storage-1.c	1 Sep 2004 01:05:56 -0000	1.2
+++ testsuite/gcc.dg/funcdef-storage-1.c	19 Dec 2004 17:40:20 -0000
@@ -1,5 +1,4 @@
 /* { dg-do compile } */
-/* { dg-options "" } */
 
 void
 flarm(void)
@@ -8,8 +7,3 @@
 
   foo();
 }
-
-static void
-foo(void)
-{
-}

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