2003-08-30 Zack Weinberg <zack@codesourcery.com>
+ * c-tree.h: Delete COMPARE_DIFFERENT_TU from enumeration.
+ * c-typeck.c (same_translation_unit_p): New function.
+ (comptypes): Use it instead of flags parameter to identify
+ structure types from different translation units.
+ * c-decl.c (duplicate_decls): Always call comptypes with
+ COMPTYPE_STRICT flags argument.
+ (c_reset_state): Set BLOCK_SUPERCONTEXT of the block formed
+ to file_scope_decl.
+
+2003-08-30 Zack Weinberg <zack@codesourcery.com>
+
* c-tree.h (C_TYPE_INCOMPLETE_VARS): New macro.
* c-decl.c (struct c_scope): Remove "incomplete" field.
(pushdecl): Attach variables with incomplete types to
duplicate_decls (tree newdecl, tree olddecl, int different_binding_level,
int different_tu)
{
- int comptype_flags = (different_tu ? COMPARE_DIFFERENT_TU
- : COMPARE_STRICT);
int types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl),
- comptype_flags);
+ COMPARE_STRICT);
int new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
&& DECL_INITIAL (newdecl) != 0);
tree oldtype = TREE_TYPE (olddecl);
if (trytype)
{
- types_match = comptypes (newtype, trytype, comptype_flags);
+ types_match = comptypes (newtype, trytype, COMPARE_STRICT);
if (types_match)
oldtype = trytype;
if (! different_binding_level)
&& ! pedantic
/* Return types must still match. */
&& comptypes (TREE_TYPE (oldtype),
- TREE_TYPE (newtype), comptype_flags)
+ TREE_TYPE (newtype), COMPARE_STRICT)
&& TYPE_ARG_TYPES (newtype) == 0))
{
error ("%Hconflicting types for '%D'",
involving an empty arglist vs a nonempty one. */
if (TREE_CODE (olddecl) == FUNCTION_DECL
&& comptypes (TREE_TYPE (oldtype),
- TREE_TYPE (newtype), comptype_flags)
+ TREE_TYPE (newtype), COMPARE_STRICT)
&& ((TYPE_ARG_TYPES (oldtype) == 0
&& DECL_INITIAL (olddecl) == 0)
||
/* Type for passing arg must be consistent
with that declared for the arg. */
if (! comptypes (TREE_VALUE (parm), TREE_VALUE (type),
- comptype_flags))
+ COMPARE_STRICT))
{
const location_t *locus = &DECL_SOURCE_LOCATION (newdecl);
error ("%Hprototype for '%D' follows and argument %d "
current_scope = global_scope;
file_scope_decl = current_file_decl;
DECL_INITIAL (file_scope_decl) = poplevel (1, 0, 0);
+ BLOCK_SUPERCONTEXT (DECL_INITIAL (file_scope_decl)) = file_scope_decl;
truly_local_externals = NULL_TREE;
/* Start a new global binding level. */
/* For use with comptypes. */
enum {
- COMPARE_STRICT = 0,
- COMPARE_DIFFERENT_TU = 1
+ COMPARE_STRICT = 0
};
extern tree require_complete_type (tree);
static int missing_braces_mentioned;
static tree qualify_type (tree, tree);
+static int same_translation_unit_p (tree, tree);
static int tagged_types_tu_compatible_p (tree, tree, int);
static int comp_target_types (tree, tree, int);
static int function_types_compatible_p (tree, tree, int);
case ENUMERAL_TYPE:
case UNION_TYPE:
- if (val != 1 && (flags & COMPARE_DIFFERENT_TU))
+ if (val != 1 && !same_translation_unit_p (t1, t2))
val = tagged_types_tu_compatible_p (t1, t2, flags);
break;
\f
/* Subroutines of `comptypes'. */
+/* Determine whether two types derive from the same translation unit.
+ If the CONTEXT chain ends in a null, that type's context is still
+ being parsed, so if two types have context chains ending in null,
+ they're in the same translation unit. */
+static int
+same_translation_unit_p (tree t1, tree t2)
+{
+ while (t1 && TREE_CODE (t1) != TRANSLATION_UNIT_DECL)
+ switch (TREE_CODE_CLASS (TREE_CODE (t1)))
+ {
+ case 'd': t1 = DECL_CONTEXT (t1); break;
+ case 't': t1 = TYPE_CONTEXT (t1); break;
+ case 'b': t1 = BLOCK_SUPERCONTEXT (t1); break;
+ default: abort ();
+ }
+
+ while (t2 && TREE_CODE (t2) != TRANSLATION_UNIT_DECL)
+ switch (TREE_CODE_CLASS (TREE_CODE (t2)))
+ {
+ case 'd': t2 = DECL_CONTEXT (t1); break;
+ case 't': t2 = TYPE_CONTEXT (t2); break;
+ case 'b': t2 = BLOCK_SUPERCONTEXT (t2); break;
+ default: abort ();
+ }
+
+ return t1 == t2;
+}
+
/* The C standard says that two structures in different translation
units are compatible with each other only if the types of their
fields are compatible (among other things). So, consider two copies