c-pragma.c (apply_pragma_weak): Convert value identifier to string for decl_attributes.
authorRichard Henderson <rth@redhat.com>
Sun, 26 May 2002 03:38:37 +0000 (20:38 -0700)
committerRichard Henderson <rth@gcc.gnu.org>
Sun, 26 May 2002 03:38:37 +0000 (20:38 -0700)
        * c-pragma.c (apply_pragma_weak): Convert value identifier to
        string for decl_attributes.
        (handle_pragma_weak): Call assemble_alias if we're modifying
        an existing decl.

From-SVN: r53884

gcc/ChangeLog
gcc/c-pragma.c
gcc/testsuite/gcc.dg/weak-9.c [new file with mode: 0644]

index e76b87f6f0315349519d514b3f057150c8a65e22..34ab44dd5a61cbbea12e57157fd4a1f6346936e9 100644 (file)
@@ -1,3 +1,10 @@
+2002-05-25  Richard Henderson  <rth@redhat.com>
+
+       * c-pragma.c (apply_pragma_weak): Convert value identifier to
+       string for decl_attributes.
+       (handle_pragma_weak): Call assemble_alias if we're modifying
+       an existing decl.
+
 2002-05-25  Richard Henderson  <rth@redhat.com>
 
        PR target/6788
index 8801c697a8cdaf7f734c16593c31e2c060210096..1a016b8b2201982498daaf658cb5217ba73a29db 100644 (file)
@@ -283,9 +283,14 @@ apply_pragma_weak (decl, value)
      tree decl, value;
 {
   if (value)
-    decl_attributes (&decl, build_tree_list (get_identifier ("alias"),
-                                            build_tree_list (NULL, value)),
-                    0);
+    {
+      value = build_string (IDENTIFIER_LENGTH (value),
+                           IDENTIFIER_POINTER (value));
+      decl_attributes (&decl, build_tree_list (get_identifier ("alias"),
+                                              build_tree_list (NULL, value)),
+                      0);
+    }
+
   if (SUPPORTS_WEAK && DECL_EXTERNAL (decl) && TREE_USED (decl)
       && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
     warning_with_decl (decl, "applying #pragma weak `%s' after first use results in unspecified behavior");
@@ -342,7 +347,11 @@ handle_pragma_weak (dummy)
 
   decl = identifier_global_value (name);
   if (decl && TREE_CODE_CLASS (TREE_CODE (decl)) == 'd')
-    apply_pragma_weak (decl, value);
+    {
+      apply_pragma_weak (decl, value);
+      if (value)
+       assemble_alias (decl, value);
+    }
   else
     pending_weaks = tree_cons (name, value, pending_weaks);
 }
diff --git a/gcc/testsuite/gcc.dg/weak-9.c b/gcc/testsuite/gcc.dg/weak-9.c
new file mode 100644 (file)
index 0000000..dd5f625
--- /dev/null
@@ -0,0 +1,28 @@
+/* { dg-do compile } */
+/* { dg-options "-fno-common" } */
+
+/* COFF does not support weak, and dg doesn't support UNSUPPORTED.  */
+/* { dg-do compile { xfail *-*-coff i?86-pc-cygwin h8300-*-hms } } */
+
+/* { dg-final { global target_triplet } } */
+/* { dg-final { if [string match h8300-*-hms $target_triplet ] {return} } } */
+/* { dg-final { if [string match i?86-pc-cygwin $target_triplet ] {return} } } *
+/
+/* { dg-final { if [string match *-*-coff $target_triplet ] {return} } } */
+/* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?f1" } } */
+/* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?f2" } } */
+/* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?f3" } } */
+/* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?f4" } } */
+/* { dg-final { scan-assembler "notf1" } } */
+/* { dg-final { scan-assembler "notf2" } } */
+/* { dg-final { scan-assembler "notf3" } } */
+/* { dg-final { scan-assembler "notf4" } } */
+
+void f1() __attribute__((weak, alias("notf1")));
+void f2() __attribute__((alias("notf2"), weak));
+
+#pragma weak f3=notf3
+void f3();
+
+void f4();
+#pragma weak f4=notf4