aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorZack Weinberg <zack@codesourcery.com>2003-08-30 21:24:19 +0000
committerZack Weinberg <zack@gcc.gnu.org>2003-08-30 21:24:19 +0000
commit766beae18707b9c9918bac392c8340d84aceffd1 (patch)
tree224ec6b140b0764f4f59fa98e93fdcd681438b8c /gcc
parentbf7a697f0ad4399b6ef6abc542520c9be858356e (diff)
downloadgcc-766beae18707b9c9918bac392c8340d84aceffd1.zip
gcc-766beae18707b9c9918bac392c8340d84aceffd1.tar.gz
gcc-766beae18707b9c9918bac392c8340d84aceffd1.tar.bz2
c-tree.h: Delete COMPARE_DIFFERENT_TU from enumeration.
* 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. From-SVN: r70953
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog11
-rw-r--r--gcc/c-decl.c13
-rw-r--r--gcc/c-tree.h3
-rw-r--r--gcc/c-typeck.c31
4 files changed, 48 insertions, 10 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index acec8f5..4856f1d 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,16 @@
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
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index a346516..20b9b67 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -775,10 +775,8 @@ static int
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);
@@ -897,7 +895,7 @@ duplicate_decls (tree newdecl, tree olddecl, int different_binding_level,
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)
@@ -983,7 +981,7 @@ duplicate_decls (tree newdecl, tree olddecl, int 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'",
@@ -992,7 +990,7 @@ duplicate_decls (tree newdecl, tree olddecl, int different_binding_level,
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)
||
@@ -1135,7 +1133,7 @@ duplicate_decls (tree newdecl, tree olddecl, int different_binding_level,
/* 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 "
@@ -6701,6 +6699,7 @@ c_reset_state (void)
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. */
diff --git a/gcc/c-tree.h b/gcc/c-tree.h
index f692f73..f85e5d0 100644
--- a/gcc/c-tree.h
+++ b/gcc/c-tree.h
@@ -244,8 +244,7 @@ extern bool c_warn_unused_global_decl (tree);
/* For use with comptypes. */
enum {
- COMPARE_STRICT = 0,
- COMPARE_DIFFERENT_TU = 1
+ COMPARE_STRICT = 0
};
extern tree require_complete_type (tree);
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 2dfce9e..530ac75 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -50,6 +50,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
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);
@@ -564,7 +565,7 @@ comptypes (tree type1, tree type2, int flags)
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;
@@ -606,6 +607,34 @@ comp_target_types (tree ttl, tree ttr, int reflexive)
/* 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