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]

Fix PR 14734/11944 ; small cleanups


This patch does two things.  It fixes PR 14734/11944 (duplicates); it
adds chain_next markers to structs c_binding and c_scope for added
efficiency (the documentation should make clear that chain_next can be
used safely without chain_prev, for singly linked lists); and it moves
the C front end's definition of struct lang_identifier into the only
file that should know what it is (c-decl.c).

This last causes a minor headache with the definition of
LANG_HOOKS_IDENTIFIER_SIZE.  I have chosen to add a small bit of
ugliness in the service of the greater good - c-tree.h provides an
indication of the size of C's struct lang_identifier, without
reference to the actual type.  The indication is checked in c-decl.c
with a compile-time assertion.  I think this is an acceptable bandage
especially considering that my long-term goal is to make struct
tree_identifier go away (the entire concept of a symbol table will be
private to the front end).

Bootstrapped i686-linux.

zw

        * c-decl.c: Verify that C_SIZEOF_STRUCT_LANG_IDENTIFIER is correct.
        (struct c_binding, struct c_scope): Add chain_next
        attributes to GTY markers.
        (struct lang_identifier, struct lang_tree_node): Define
        here...
        * c-tree.h: ... not here.  No longer need to declare struct
        c_binding either.  Do define C_SIZEOF_STRUCT_LANG_IDENTIFIER.
        * c-lang.c, objc/objc-lang.c: Set LANG_HOOKS_IDENTIFIER_SIZE
        to C_SIZEOF_STRUCT_LANG_IDENTIFIER.

        PR 14734, 11944
        * c-decl.c (get_parm_info): If error_mark_node is encountered
        in the bindings chain, unbind and discard it; don't abort.
        * testsuite/gcc.dg/noncompile/undeclared-2.c: New test.
                        

===================================================================
Index: c-decl.c
--- c-decl.c	28 Mar 2004 00:31:38 -0000	1.490
+++ c-decl.c	28 Mar 2004 17:26:03 -0000
@@ -160,7 +160,7 @@ bool c_override_global_bindings_to_false
    suppress further errors about that identifier in the current
    function.  */
 
-struct c_binding GTY(())
+struct c_binding GTY((chain_next ("%h.prev")))
 {
   tree decl;			/* the decl bound */
   tree id;			/* the identifier it's bound to */
@@ -184,6 +184,34 @@ struct c_binding GTY(())
 #define I_LABEL_DECL(node) \
  (I_LABEL_BINDING(node) ? I_LABEL_BINDING(node)->decl : 0)
 
+/* Each C symbol points to three linked lists of c_binding structures.
+   These describe the values of the identifier in the three different
+   namespaces defined by the language.  */
+
+struct lang_identifier GTY(())
+{
+  struct c_common_identifier common_id;
+  struct c_binding *symbol_binding; /* vars, funcs, constants, typedefs */
+  struct c_binding *tag_binding;    /* struct/union/enum tags */
+  struct c_binding *label_binding;  /* labels */
+};
+
+/* Validate c-lang.c's assumptions.  */
+extern char C_SIZEOF_STRUCT_LANG_IDENTIFIER_isnt_accurate
+[(sizeof(struct lang_identifier) == C_SIZEOF_STRUCT_LANG_IDENTIFIER) ? 1 : -1];
+
+/* The resulting tree type.  */
+
+union lang_tree_node
+  GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
+       chain_next ("TREE_CODE (&%h.generic) == INTEGER_TYPE ? (union lang_tree_node *)TYPE_NEXT_VARIANT (&%h.generic) : (union lang_tree_node *)TREE_CHAIN (&%h.generic)")))
+{
+  union tree_node GTY ((tag ("0"),
+			desc ("tree_node_structure (&%h)")))
+    generic;
+  struct lang_identifier GTY ((tag ("1"))) identifier;
+};
+
 /* Each c_scope structure describes the complete contents of one
    scope.  Four scopes are distinguished specially: the innermost or
    current scope, the innermost function scope, the file scope (always
@@ -229,7 +257,7 @@ struct c_binding GTY(())
    pop_scope relies on this.  */
 
 
-struct c_scope GTY(())
+struct c_scope GTY((chain_next ("%h.outer")))
 {
   /* The scope containing this one.  */
   struct c_scope *outer;
@@ -4811,6 +4839,13 @@ get_parm_info (bool ellipsis)
 	     and TYPE_DECLs appear here when we have an embedded struct
 	     or union.  No warnings for this - we already warned about the
 	     type itself.  */
+	  TREE_CHAIN (decl) = others;
+	  others = decl;
+	  /* fall through */
+
+	case ERROR_MARK:
+	  /* error_mark_node appears here when we have an undeclared
+	     variable.  Just throw it away.  */
 	  if (b->id)
 	    {
 #ifdef ENABLE_CHECKING
@@ -4818,16 +4853,12 @@ get_parm_info (bool ellipsis)
 #endif
 	      I_SYMBOL_BINDING (b->id) = b->shadowed;
 	    }
-
-	  TREE_CHAIN (decl) = others;
-	  others = decl;
 	  break;
 
 	  /* Other things that might be encountered.  */
 	case LABEL_DECL:
 	case FUNCTION_DECL:
 	case VAR_DECL:
-	case ERROR_MARK:
 	default:
 	  abort ();
 	}
===================================================================
Index: c-lang.c
--- c-lang.c	23 Mar 2004 23:47:35 -0000	1.122
+++ c-lang.c	28 Mar 2004 17:26:03 -0000
@@ -41,6 +41,8 @@ enum c_language_kind c_language = clk_c;
 
 #undef LANG_HOOKS_NAME
 #define LANG_HOOKS_NAME "GNU C"
+#undef LANG_HOOKS_IDENTIFIER_SIZE
+#define LANG_HOOKS_IDENTIFIER_SIZE C_SIZEOF_STRUCT_LANG_IDENTIFIER
 #undef LANG_HOOKS_INIT
 #define LANG_HOOKS_INIT c_objc_common_init
 #undef LANG_HOOKS_FINISH
===================================================================
Index: c-tree.h
--- c-tree.h	28 Mar 2004 00:31:38 -0000	1.143
+++ c-tree.h	28 Mar 2004 17:26:04 -0000
@@ -24,34 +24,10 @@ Software Foundation, 59 Temple Place - S
 
 #include "c-common.h"
 
-/* Each C symbol points to three linked lists of c_binding structures.
-   These describe the values of the identifier in the three different
-   namespaces defined by the language.  The contents of these lists
-   are private to c-decl.c.  */
-
-struct c_binding;
-
-/* Language-dependent contents of an identifier.  */
-
-struct lang_identifier GTY(())
-{
-  struct c_common_identifier common_id;
-  struct c_binding *symbol_binding; /* vars, funcs, constants, typedefs */
-  struct c_binding *tag_binding;    /* struct/union/enum tags */
-  struct c_binding *label_binding;  /* labels */
-};
-
-/* The resulting tree type.  */
-
-union lang_tree_node
-  GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
-       chain_next ("TREE_CODE (&%h.generic) == INTEGER_TYPE ? (union lang_tree_node *)TYPE_NEXT_VARIANT (&%h.generic) : (union lang_tree_node *)TREE_CHAIN (&%h.generic)")))
-{
-  union tree_node GTY ((tag ("0"),
-			desc ("tree_node_structure (&%h)")))
-    generic;
-  struct lang_identifier GTY ((tag ("1"))) identifier;
-};
+/* struct lang_identifier is private to c-decl.c, but langhooks.c needs to
+   know how big it is.  This is sanity-checked in c-decl.c.  */
+#define C_SIZEOF_STRUCT_LANG_IDENTIFIER \
+  (sizeof (struct c_common_identifier) + 3 * sizeof (void *))
 
 /* Language-specific declaration information.  */
 
===================================================================
Index: objc/objc-lang.c
--- objc/objc-lang.c	23 Mar 2004 23:47:50 -0000	1.41
+++ objc/objc-lang.c	28 Mar 2004 17:26:05 -0000
@@ -35,6 +35,8 @@ enum c_language_kind c_language = clk_ob
 
 #undef LANG_HOOKS_NAME
 #define LANG_HOOKS_NAME "GNU Objective-C"
+#undef LANG_HOOKS_IDENTIFIER_SIZE
+#define LANG_HOOKS_IDENTIFIER_SIZE C_SIZEOF_STRUCT_LANG_IDENTIFIER
 #undef LANG_HOOKS_INIT
 #define LANG_HOOKS_INIT objc_init
 #undef LANG_HOOKS_FINISH
===================================================================
Index: testsuite/gcc.dg/noncompile/undeclared-2.c
--- testsuite/gcc.dg/noncompile/undeclared-2.c	1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.dg/noncompile/undeclared-2.c	28 Mar 2004 17:26:09 -0000
@@ -0,0 +1,3 @@
+/* Invalid, but should not ICE.  PRs 11944, 14734.  */
+
+void foo(const int[i]);  /* { dg-error "undeclared|for each" } */


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