Commit 1ef82ef2 by Zack Weinberg

c-decl.c (merge_decls): Kill different_binding_level and different_tu arguments;…

c-decl.c (merge_decls): Kill different_binding_level and different_tu arguments; simplify throughout.

	* c-decl.c (merge_decls): Kill different_binding_level and
	different_tu arguments; simplify throughout.
	(duplicate_decls): Likewise.
	(pushdecl, merge_translation_unit_decls): Update calls to
	duplicate_decls.
testsuite:
	* gcc.dg/noncompile/20020213-1.c: Add another dg-warning line.

From-SVN: r76269
parent 4543ee47
2004-01-21 Zack Weinberg <zack@codesourcery.com>
* c-decl.c (merge_decls): Kill different_binding_level and
different_tu arguments; simplify throughout.
(duplicate_decls): Likewise.
(pushdecl, merge_translation_unit_decls): Update calls to
duplicate_decls.
2004-01-20 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> 2004-01-20 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* Makefile.in (pretty-print.o): Depend on $(CONFIG_H) and * Makefile.in (pretty-print.o): Depend on $(CONFIG_H) and
......
...@@ -1252,23 +1252,15 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl, ...@@ -1252,23 +1252,15 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
/* Subroutine of duplicate_decls. NEWDECL has been found to be /* Subroutine of duplicate_decls. NEWDECL has been found to be
consistent with OLDDECL, but carries new information. Merge the consistent with OLDDECL, but carries new information. Merge the
new information into OLDDECL. If DIFFERENT_BINDING_LEVEL or new information into OLDDECL. This function issues no
DIFFERENT_TU is true, avoid completely merging the decls, as this
will break assumptions elsewhere. This function issues no
diagnostics. */ diagnostics. */
static void static void
merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype, merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
bool different_binding_level, bool different_tu)
{ {
int new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL int new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
&& DECL_INITIAL (newdecl) != 0); && DECL_INITIAL (newdecl) != 0);
/* When copying info to olddecl, we store into write_olddecl
instead. This allows us to avoid modifying olddecl when
different_binding_level is true. */
tree write_olddecl = different_binding_level ? newdecl : olddecl;
/* For real parm decl following a forward decl, return 1 so old decl /* For real parm decl following a forward decl, return 1 so old decl
will be reused. Only allow this to happen once. */ will be reused. Only allow this to happen once. */
if (TREE_CODE (newdecl) == PARM_DECL if (TREE_CODE (newdecl) == PARM_DECL
...@@ -1282,25 +1274,9 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype, ...@@ -1282,25 +1274,9 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype,
= (*targetm.merge_decl_attributes) (olddecl, newdecl); = (*targetm.merge_decl_attributes) (olddecl, newdecl);
/* Merge the data types specified in the two decls. */ /* Merge the data types specified in the two decls. */
if (TREE_CODE (newdecl) != FUNCTION_DECL || !DECL_BUILT_IN (olddecl))
{
if (different_binding_level)
{
if (TYPE_ARG_TYPES (oldtype) != 0
&& TYPE_ARG_TYPES (newtype) == 0)
TREE_TYPE (newdecl) = common_type (newtype, oldtype);
else
TREE_TYPE (newdecl)
= build_type_attribute_variant
(newtype,
merge_attributes (TYPE_ATTRIBUTES (newtype),
TYPE_ATTRIBUTES (oldtype)));
}
else
TREE_TYPE (newdecl) TREE_TYPE (newdecl)
= TREE_TYPE (olddecl) = TREE_TYPE (olddecl)
= common_type (newtype, oldtype); = common_type (newtype, oldtype);
}
/* Lay the type out, unless already done. */ /* Lay the type out, unless already done. */
if (oldtype != TREE_TYPE (newdecl)) if (oldtype != TREE_TYPE (newdecl))
...@@ -1331,33 +1307,27 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype, ...@@ -1331,33 +1307,27 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype,
/* Merge the type qualifiers. */ /* Merge the type qualifiers. */
if (TREE_READONLY (newdecl)) if (TREE_READONLY (newdecl))
TREE_READONLY (write_olddecl) = 1; TREE_READONLY (olddecl) = 1;
if (TREE_THIS_VOLATILE (newdecl)) if (TREE_THIS_VOLATILE (newdecl))
{ {
TREE_THIS_VOLATILE (write_olddecl) = 1; TREE_THIS_VOLATILE (olddecl) = 1;
if (TREE_CODE (newdecl) == VAR_DECL) if (TREE_CODE (newdecl) == VAR_DECL)
make_var_volatile (newdecl); make_var_volatile (newdecl);
} }
/* Keep source location of definition rather than declaration. */ /* Keep source location of definition rather than declaration. */
/* When called with different_binding_level set, keep the old if (DECL_INITIAL (newdecl) == 0 && DECL_INITIAL (olddecl) != 0)
information so that meaningful diagnostics can be given. */
if (DECL_INITIAL (newdecl) == 0 && DECL_INITIAL (olddecl) != 0
&& ! different_binding_level)
DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl); DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
/* Merge the unused-warning information. */ /* Merge the unused-warning information. */
if (DECL_IN_SYSTEM_HEADER (olddecl)) if (DECL_IN_SYSTEM_HEADER (olddecl))
DECL_IN_SYSTEM_HEADER (newdecl) = 1; DECL_IN_SYSTEM_HEADER (newdecl) = 1;
else if (DECL_IN_SYSTEM_HEADER (newdecl)) else if (DECL_IN_SYSTEM_HEADER (newdecl))
DECL_IN_SYSTEM_HEADER (write_olddecl) = 1; DECL_IN_SYSTEM_HEADER (olddecl) = 1;
/* Merge the initialization information. */ /* Merge the initialization information. */
/* When called with different_binding_level set, don't copy over if (DECL_INITIAL (newdecl) == 0)
DECL_INITIAL, so that we don't accidentally change function
declarations into function definitions. */
if (DECL_INITIAL (newdecl) == 0 && ! different_binding_level)
DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
/* Merge the section attribute. /* Merge the section attribute.
...@@ -1397,8 +1367,6 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype, ...@@ -1397,8 +1367,6 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype,
TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl); TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
/* This is since we don't automatically /* This is since we don't automatically
copy the attributes of NEWDECL into OLDDECL. */ copy the attributes of NEWDECL into OLDDECL. */
/* No need to worry about different_binding_level here because
then TREE_PUBLIC (newdecl) was true. */
TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl); TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
/* If this clears `static', clear it in the identifier too. */ /* If this clears `static', clear it in the identifier too. */
if (! TREE_PUBLIC (olddecl)) if (! TREE_PUBLIC (olddecl))
...@@ -1406,24 +1374,15 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype, ...@@ -1406,24 +1374,15 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype,
} }
if (DECL_EXTERNAL (newdecl)) if (DECL_EXTERNAL (newdecl))
{ {
if (! different_binding_level || different_tu)
{
/* Don't mess with these flags on local externs; they remain
external even if there's a declaration at file scope which
isn't. */
TREE_STATIC (newdecl) = TREE_STATIC (olddecl); TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl); DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
}
/* An extern decl does not override previous storage class. */ /* An extern decl does not override previous storage class. */
TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl); TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
if (! DECL_EXTERNAL (newdecl)) if (! DECL_EXTERNAL (newdecl))
{ {
DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl); DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
DECL_COMMON (newdecl) = DECL_COMMON (olddecl); DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
/* If we have two non-EXTERNAL file-scope decls that are
the same, only one of them should be written out. */
if (different_tu)
TREE_ASM_WRITTEN (newdecl) = 1;
} }
} }
else else
...@@ -1469,12 +1428,9 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype, ...@@ -1469,12 +1428,9 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype,
definition. */ definition. */
if (new_is_definition) if (new_is_definition)
{ {
if (! different_binding_level)
{
TREE_TYPE (olddecl) = TREE_TYPE (newdecl); TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
DECL_BUILT_IN_CLASS (olddecl) = NOT_BUILT_IN; DECL_BUILT_IN_CLASS (olddecl) = NOT_BUILT_IN;
} }
}
else else
{ {
/* If redeclaring a builtin function, and not a definition, /* If redeclaring a builtin function, and not a definition,
...@@ -1488,10 +1444,6 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype, ...@@ -1488,10 +1444,6 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype,
if (! new_is_definition) if (! new_is_definition)
{ {
DECL_RESULT (newdecl) = DECL_RESULT (olddecl); DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
/* When called with different_binding_level set, don't copy over
DECL_INITIAL, so that we don't accidentally change function
declarations into function definitions. */
if (! different_binding_level)
DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl); DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl);
DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl); DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
...@@ -1504,9 +1456,7 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype, ...@@ -1504,9 +1456,7 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype,
{ {
DECL_INLINE (newdecl) = 1; DECL_INLINE (newdecl) = 1;
DECL_ABSTRACT_ORIGIN (newdecl) DECL_ABSTRACT_ORIGIN (newdecl)
= (different_binding_level = DECL_ABSTRACT_ORIGIN (olddecl);
? DECL_ORIGIN (olddecl)
: DECL_ABSTRACT_ORIGIN (olddecl));
} }
} }
else else
...@@ -1518,8 +1468,6 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype, ...@@ -1518,8 +1468,6 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype,
DECL_INLINE (newdecl) = 1; DECL_INLINE (newdecl) = 1;
} }
} }
if (different_binding_level)
return;
/* Copy most of the decl-specific fields of NEWDECL into OLDDECL. /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
But preserve OLDDECL's DECL_UID. */ But preserve OLDDECL's DECL_UID. */
...@@ -1547,24 +1495,18 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype, ...@@ -1547,24 +1495,18 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype,
if appropriate. if appropriate.
If safely possible, alter OLDDECL to look like NEWDECL, and return If safely possible, alter OLDDECL to look like NEWDECL, and return
true. Otherwise, return false. true. Otherwise, return false. */
When DIFFERENT_BINDING_LEVEL is true, NEWDECL is an external
declaration, and OLDDECL is in an outer scope and should thus not
be changed. */
static bool static bool
duplicate_decls (tree newdecl, tree olddecl, duplicate_decls (tree newdecl, tree olddecl)
bool different_binding_level, bool different_tu)
{ {
tree newtype, oldtype; tree newtype, oldtype;
if (!diagnose_mismatched_decls (newdecl, olddecl, &newtype, &oldtype)) if (!diagnose_mismatched_decls (newdecl, olddecl, &newtype, &oldtype))
return false; return false;
merge_decls (newdecl, olddecl, newtype, oldtype, merge_decls (newdecl, olddecl, newtype, oldtype);
different_binding_level, different_tu); return true;
return !different_binding_level;
} }
...@@ -1745,7 +1687,7 @@ pushdecl (tree x) ...@@ -1745,7 +1687,7 @@ pushdecl (tree x)
IDENTIFIER_POINTER (name)); IDENTIFIER_POINTER (name));
old = lookup_name_current_level (name); old = lookup_name_current_level (name);
if (old && duplicate_decls (x, old, 0, false)) if (old && duplicate_decls (x, old))
{ {
/* For PARM_DECLs, old may be a forward declaration. /* For PARM_DECLs, old may be a forward declaration.
If so, we want to remove it from its old location If so, we want to remove it from its old location
...@@ -1773,8 +1715,7 @@ pushdecl (tree x) ...@@ -1773,8 +1715,7 @@ pushdecl (tree x)
tree ext = any_external_decl (name); tree ext = any_external_decl (name);
if (ext) if (ext)
{ {
if (duplicate_decls (x, ext, scope != global_scope, if (duplicate_decls (x, ext))
false))
x = copy_node (ext); x = copy_node (ext);
} }
else else
...@@ -6606,7 +6547,7 @@ merge_translation_unit_decls (void) ...@@ -6606,7 +6547,7 @@ merge_translation_unit_decls (void)
/* Print any appropriate error messages, and partially merge /* Print any appropriate error messages, and partially merge
the decls. */ the decls. */
(void) duplicate_decls (decl, global_decl, true, true); (void) duplicate_decls (decl, global_decl);
} }
htab_delete (link_hash_table); htab_delete (link_hash_table);
......
2004-01-21 Zack Weinberg <zack@codesourcery.com>
* gcc.dg/noncompile/20020213-1.c: Add another dg-warning line.
2004-01-20 Hartmut Penner <hpenner@de.ibm.com> 2004-01-20 Hartmut Penner <hpenner@de.ibm.com>
* gcc.dg/ppc64-abi-2.c: New test. * gcc.dg/ppc64-abi-2.c: New test.
......
...@@ -24,6 +24,7 @@ int main () ...@@ -24,6 +24,7 @@ int main ()
return 0; return 0;
} }
/* { dg-warning "passing arg 2 of" "2nd incompatible" { target *-*-* } 15 } */
/* { dg-warning "passing arg 1 of" "1st incompatible" { target *-*-* } 16 } */ /* { dg-warning "passing arg 1 of" "1st incompatible" { target *-*-* } 16 } */
/* { dg-warning "passing arg 2 of" "2nd incompatible" { target *-*-* } 16 } */ /* { dg-warning "passing arg 2 of" "2nd incompatible" { target *-*-* } 16 } */
/* { dg-warning "passing arg 1 of" "1st incompatible" { target *-*-* } 18 } */ /* { dg-warning "passing arg 1 of" "1st incompatible" { target *-*-* } 18 } */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment