re PR middle-end/67330 (ICE handling weak attributes)
authorMarek Polacek <polacek@redhat.com>
Tue, 25 Aug 2015 20:28:59 +0000 (20:28 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Tue, 25 Aug 2015 20:28:59 +0000 (20:28 +0000)
PR middle-end/67330
* varasm.c (declare_weak): Return after giving an error.

* c-common.c (handle_weak_attribute): Don't check whether the
visibility can be changed here.

* gcc.dg/weak/weak-18.c: New test.

From-SVN: r227190

gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/weak/weak-18.c [new file with mode: 0644]
gcc/varasm.c

index c79fb4870f7db963da74732ca5e370cd0a5e6b45..fd4ade37af3fbde214e9add4b4f18e8697deca9d 100644 (file)
@@ -1,3 +1,8 @@
+2015-08-25  Marek Polacek  <polacek@redhat.com>
+
+       PR middle-end/67330
+       * varasm.c (declare_weak): Return after giving an error.
+
 2015-08-25  David Malcolm  <dmalcolm@redhat.com>
 
        * gcc-main.c (main): Add params to driver ctor.
index 2a5758aac59d5505aeacd55d4bc542cc1eb9c711..8b4009e85fddd08cd84c8fdb05131ffc5de1d8c4 100644 (file)
@@ -1,3 +1,9 @@
+2015-08-25  Marek Polacek  <polacek@redhat.com>
+
+       PR middle-end/67330
+       * c-common.c (handle_weak_attribute): Don't check whether the
+       visibility can be changed here.
+
 2015-08-22  Manuel López-Ibáñez  <manu@gcc.gnu.org>
 
        * c-lex.c (c_lex_with_flags): Use explicit locations.
index ff502e56dbb82db1444094303528358b9284dcfa..7691035c7f840ad01d5bb2e3a60a5ff4403c978a 100644 (file)
@@ -8328,12 +8328,7 @@ handle_weak_attribute (tree *node, tree name,
       return NULL_TREE;
     }
   else if (VAR_OR_FUNCTION_DECL_P (*node))
-    {
-      struct symtab_node *n = symtab_node::get (*node);
-      if (n && n->refuse_visibility_changes)
-       error ("%+D declared weak after being used", *node);
-      declare_weak (*node);
-    }
+    declare_weak (*node);
   else
     warning (OPT_Wattributes, "%qE attribute ignored", name);
 
index 7deb14776ca993b48b293eb4ad6ce6c35f1acb18..e8365be37f08bffc10c07fe28d3217dc3610f236 100644 (file)
@@ -1,3 +1,8 @@
+2015-08-25  Marek Polacek  <polacek@redhat.com>
+
+       PR middle-end/67330
+       * gcc.dg/weak/weak-18.c: New test.
+
 2015-08-25  David Malcolm  <dmalcolm@redhat.com>
 
        * jit.dg/test-error-pr63969-missing-driver.c: Add call to
diff --git a/gcc/testsuite/gcc.dg/weak/weak-18.c b/gcc/testsuite/gcc.dg/weak/weak-18.c
new file mode 100644 (file)
index 0000000..ebeb4d5
--- /dev/null
@@ -0,0 +1,9 @@
+/* PR middle-end/67330 */
+/* { dg-do compile } */
+/* { dg-require-weak "" } */
+
+void
+f (void)
+{
+  __attribute__ ((weak)) int a; /* { dg-error "weak declaration of .a. must be public" } */
+}
index 7fa2e7be8e41f91358a548675fdf35d8c83011e7..d9290a17cbbc244c31859b795ffc00ac2d4e389d 100644 (file)
@@ -5403,7 +5403,10 @@ declare_weak (tree decl)
 {
   gcc_assert (TREE_CODE (decl) != FUNCTION_DECL || !TREE_ASM_WRITTEN (decl));
   if (! TREE_PUBLIC (decl))
-    error ("weak declaration of %q+D must be public", decl);
+    {
+      error ("weak declaration of %q+D must be public", decl);
+      return;
+    }
   else if (!TARGET_SUPPORTS_WEAK)
     warning (0, "weak declaration of %q+D not supported", decl);