OSDN Git Service

Merge tree-ssa-20020619-branch into mainline.
[pf3gnuchains/gcc-fork.git] / gcc / c-pragma.c
index dc95733..31a17a1 100644 (file)
@@ -1,5 +1,5 @@
 /* Handle #pragma, system V.4 style.  Supports #pragma weak and #pragma pack.
 /* Handle #pragma, system V.4 style.  Supports #pragma weak and #pragma pack.
-   Copyright (C) 1992, 1997, 1998, 1999, 2000, 2001, 2002, 2003
+   Copyright (C) 1992, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
    Free Software Foundation, Inc.
 
 This file is part of GCC.
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -273,10 +273,10 @@ apply_pragma_weak (tree decl, tree value)
     }
 
   if (SUPPORTS_WEAK && DECL_EXTERNAL (decl) && TREE_USED (decl)
     }
 
   if (SUPPORTS_WEAK && DECL_EXTERNAL (decl) && TREE_USED (decl)
-      && !DECL_WEAK (decl) /* don't complain about a redundant #pragma */
+      && !DECL_WEAK (decl) /* Don't complain about a redundant #pragma.  */
       && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
       && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
-    warning ("%Happlying #pragma weak '%D' after first use results "
-             "in unspecified behavior", &DECL_SOURCE_LOCATION (decl), decl);
+    warning ("%Japplying #pragma weak '%D' after first use results "
+             "in unspecified behavior", decl, decl);
 
   declare_weak (decl);
 }
 
   declare_weak (decl);
 }
@@ -286,16 +286,23 @@ maybe_apply_pragma_weak (tree decl)
 {
   tree *p, t, id;
 
 {
   tree *p, t, id;
 
-  /* Copied from the check in set_decl_assembler_name.  */
-  if (TREE_CODE (decl) == FUNCTION_DECL
-      || (TREE_CODE (decl) == VAR_DECL 
-          && (TREE_STATIC (decl) 
-              || DECL_EXTERNAL (decl) 
-              || TREE_PUBLIC (decl))))
-    id = DECL_ASSEMBLER_NAME (decl);
-  else
+  /* Avoid asking for DECL_ASSEMBLER_NAME when it's not needed.  */
+
+  /* No weak symbols pending, take the short-cut.  */
+  if (!pending_weaks)
+    return;
+  /* If it's not visible outside this file, it doesn't matter whether
+     it's weak.  */
+  if (!DECL_EXTERNAL (decl) && !TREE_PUBLIC (decl))
+    return;
+  /* If it's not a function or a variable, it can't be weak.
+     FIXME: what kinds of things are visible outside this file but
+     aren't functions or variables?   Should this be an abort() instead?  */
+  if (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
     return;
 
     return;
 
+  id = DECL_ASSEMBLER_NAME (decl);
+
   for (p = &pending_weaks; (t = *p) ; p = &TREE_CHAIN (t))
     if (id == TREE_PURPOSE (t))
       {
   for (p = &pending_weaks; (t = *p) ; p = &TREE_CHAIN (t))
     if (id == TREE_PURPOSE (t))
       {
@@ -345,7 +352,6 @@ maybe_apply_pragma_weak (tree decl ATTRIBUTE_UNUSED)
 
 static GTY(()) tree pending_redefine_extname;
 
 
 static GTY(()) tree pending_redefine_extname;
 
-#ifdef HANDLE_PRAGMA_REDEFINE_EXTNAME
 static void handle_pragma_redefine_extname (cpp_reader *);
 
 /* #pragma redefined_extname oldname newname */
 static void handle_pragma_redefine_extname (cpp_reader *);
 
 /* #pragma redefined_extname oldname newname */
@@ -370,17 +376,17 @@ handle_pragma_redefine_extname (cpp_reader *dummy ATTRIBUTE_UNUSED)
     warning ("junk at end of #pragma redefine_extname");
 
   decl = identifier_global_value (oldname);
     warning ("junk at end of #pragma redefine_extname");
 
   decl = identifier_global_value (oldname);
-  if (decl && TREE_CODE_CLASS (TREE_CODE (decl)) == 'd')
+  if (decl && (TREE_CODE (decl) == FUNCTION_DECL
+              || TREE_CODE (decl) == VAR_DECL))
     {
       if (DECL_ASSEMBLER_NAME_SET_P (decl)
          && DECL_ASSEMBLER_NAME (decl) != newname)
         warning ("#pragma redefine_extname conflicts with declaration");
     {
       if (DECL_ASSEMBLER_NAME_SET_P (decl)
          && DECL_ASSEMBLER_NAME (decl) != newname)
         warning ("#pragma redefine_extname conflicts with declaration");
-      SET_DECL_ASSEMBLER_NAME (decl, newname);
+      change_decl_assembler_name (decl, newname);
     }
   else
     add_to_renaming_pragma_list(oldname, newname);
 }
     }
   else
     add_to_renaming_pragma_list(oldname, newname);
 }
-#endif
 
 void
 add_to_renaming_pragma_list (tree oldname, tree newname)
 
 void
 add_to_renaming_pragma_list (tree oldname, tree newname)
@@ -494,6 +500,9 @@ init_pragma (void)
 #endif
 #ifdef HANDLE_PRAGMA_REDEFINE_EXTNAME
   c_register_pragma (0, "redefine_extname", handle_pragma_redefine_extname);
 #endif
 #ifdef HANDLE_PRAGMA_REDEFINE_EXTNAME
   c_register_pragma (0, "redefine_extname", handle_pragma_redefine_extname);
+#else
+  if (flag_mudflap)
+    c_register_pragma (0, "redefine_extname", handle_pragma_redefine_extname);
 #endif
 #ifdef HANDLE_PRAGMA_EXTERN_PREFIX
   c_register_pragma (0, "extern_prefix", handle_pragma_extern_prefix);
 #endif
 #ifdef HANDLE_PRAGMA_EXTERN_PREFIX
   c_register_pragma (0, "extern_prefix", handle_pragma_extern_prefix);