varasm.c (merge_weak): Error for any weakening after definition.
authorRichard Henderson <rth@gcc.gnu.org>
Wed, 15 May 2002 16:50:44 +0000 (09:50 -0700)
committerRichard Henderson <rth@gcc.gnu.org>
Wed, 15 May 2002 16:50:44 +0000 (09:50 -0700)
        * varasm.c (merge_weak): Error for any weakening after definition.
        Adjust weakening after use warning to catch more cases.
        (assemble_alias): Set TREE_USED and TREE_ASM_WRITTEN consistently.
        * config/alpha/alpha.c (alpha_encode_section_info): Do not abort.

        * gcc.dg/weak-5.c (vfoo1c): No warning here.
        (vfoo1f): Warning here.
        (vfoo1l): Don't redefine the alias.

From-SVN: r53491

gcc/ChangeLog
gcc/config/alpha/alpha.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/weak-5.c
gcc/varasm.c

index f543a744a91ec9de395b9197300a237ebc1728f2..9b74f2cc298d4af79061e9034b74d72f75036191 100644 (file)
@@ -1,3 +1,10 @@
+2002-05-15  Richard Henderson  <rth@redhat.com>
+
+       * varasm.c (merge_weak): Error for any weakening after definition.
+       Adjust weakening after use warning to catch more cases.
+       (assemble_alias): Set TREE_USED and TREE_ASM_WRITTEN consistently.
+       * config/alpha/alpha.c (alpha_encode_section_info): Do not abort.
+
 Wed May 15 10:38:27 CEST 2002  Jan Hubicka  <jh@suse.cz>
 
        * invoke.texi (-malign-double): Re-add lost warning.
@@ -11,7 +18,7 @@ Wed May 15 10:38:27 CEST 2002  Jan Hubicka  <jh@suse.cz>
 
        * flags.h (flag_reorder_functions): Declare.
        * function.c (prepare_function_start): Initialize frequnecy.
-       * params.def (HOT_BB_COUNT_FRACTION, HOT_BB_FREQUENCY_FRACTION): New paramters.
+       * params.def (HOT_BB_COUNT_FRACTION, HOT_BB_FREQUENCY_FRACTION): New.
        * Makefile.in (predict.o): Add dependency on target.h and params.h
        * defaults.h (HOT_TEXT_SECTION_NAME,
        UNLIKELY_EXECUTED_TEXT_SECTION_NAME): New macros.
index c40636a4bb13225ef869414a9166bafbac0b4085..281e526cfe6afae50eaaac00fe30f1ab420be192 100644 (file)
@@ -1678,7 +1678,11 @@ alpha_encode_section_info (decl, first)
       XSTR (XEXP (DECL_RTL (decl), 0), 0) = string;
     }
   else if (symbol_str[0] == '@')
-    abort ();
+    {
+      /* We're hosed.  This can happen when the user adds a weak
+        attribute after rtl generation.  They should have gotten
+        a warning about unspecified behaviour from varasm.c.  */
+    }
 }
 
 /* legitimate_address_p recognizes an RTL expression that is a valid
index 9602bf0742d06078df16f358c1d46a69994ac2e3..5676c95265e30dffe3afff7905d5b5bd5eff71c5 100644 (file)
@@ -1,3 +1,9 @@
+2002-05-15  Richard Henderson  <rth@redhat.com>
+
+       * gcc.dg/weak-5.c (vfoo1c): No warning here.
+       (vfoo1f): Warning here.
+       (vfoo1l): Don't redefine the alias.
+
 2002-05-14  Jason Merrill  <jason@redhat.com>, Alexandre Oliva  <aoliva@redhat.com>
 
        * g++.dg/init/pm1.C: New test.
index eec210992f455201c65cde1892563379a763e97b..e531b27beebcc658a05b794cc7f94b795e52e45a 100644 (file)
@@ -44,7 +44,7 @@ void * foo1c (void)
 {
   return (void *)&vfoo1c;
 }
-extern int vfoo1c __attribute__((weak)); /* { dg-warning "weak declaration" "weak declaration" } */
+extern int vfoo1c __attribute__((weak));
 
 
 extern int vfoo1d __attribute__((weak));
@@ -68,7 +68,7 @@ void * foo1f (void)
 {
   return (void *)&vfoo1f;
 }
-extern int vfoo1f __attribute__((weak));
+extern int vfoo1f __attribute__((weak)); /* { dg-warning "weak declaration" "weak declaration" } */
 
 
 extern int vfoo1g;
@@ -111,6 +111,4 @@ int vfoo1k = 1;
 
 
 int vfoox1l = 1;
-extern int vfoo1l __attribute__((alias ("vfoox1l")));
 extern int vfoo1l __attribute__((weak, alias ("vfoox1l")));
-
index 6fb663e4e886322efaa384450ecd1665990dc41a..05a8ada095b35d8ae30366a07a5a10358fa86999 100644 (file)
@@ -4830,14 +4830,6 @@ merge_weak (newdecl, olddecl)
   if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
     return;
 
-  if (SUPPORTS_WEAK
-      && DECL_WEAK (newdecl) 
-      && DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)
-      && (TREE_CODE (olddecl) != VAR_DECL || ! TREE_STATIC (olddecl))
-      && TREE_USED (olddecl)
-      && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
-    warning_with_decl (newdecl, "weak declaration of `%s' after first use results in unspecified behavior");
-
   if (DECL_WEAK (newdecl))
     {
       tree wd;
@@ -4848,10 +4840,26 @@ merge_weak (newdecl, olddecl)
         go back and make it weak.  This error cannot caught in
         declare_weak because the NEWDECL and OLDDECL was not yet
         been merged; therefore, TREE_ASM_WRITTEN was not set.  */
-      if (TREE_CODE (olddecl) == FUNCTION_DECL && TREE_ASM_WRITTEN (olddecl))
+      if (TREE_ASM_WRITTEN (olddecl))
        error_with_decl (newdecl, 
                         "weak declaration of `%s' must precede definition");
-      
+
+      /* If we've already generated rtl referencing OLDDECL, we may
+        have done so in a way that will not function properly with
+        a weak symbol.  */
+      else if (TREE_USED (olddecl)
+              && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl))
+              /* ??? Not impossible that some platform may generate code
+                 that doesn't function *at all* with incorrect declaration
+                 before use.  However, all known at present will assume
+                 exteral and common symbols are not "local".  */
+              /* ??? Probably these exceptions to the rule will just
+                 confuse users about the true nature of the problem and
+                 we should warn for *any* use before weakening.  */
+              && ! (DECL_EXTERNAL (olddecl)
+                    || DECL_COMMON (olddecl)))
+       warning_with_decl (newdecl, "weak declaration of `%s' after first use results in unspecified behavior");
+
       if (SUPPORTS_WEAK)
        {
          /* We put the NEWDECL on the weak_decls list at some point.
@@ -4992,7 +5000,6 @@ assemble_alias (decl, target)
 #else
   ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
 #endif
-  TREE_ASM_WRITTEN (decl) = 1;
 #else /* !ASM_OUTPUT_DEF */
 #if defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
   if (! DECL_WEAK (decl))
@@ -5003,11 +5010,14 @@ assemble_alias (decl, target)
 #else
   ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
 #endif
-  TREE_ASM_WRITTEN (decl) = 1;
 #else
   warning ("alias definitions not supported in this configuration; ignored");
 #endif
 #endif
+
+  TREE_USED (decl) = 1;
+  TREE_ASM_WRITTEN (decl) = 1;
+  TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
 }
 
 /* Emit an assembler directive to set symbol for DECL visibility to