This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Don't ICE on invalid weak decl (PR middle-end/67330)
- From: Marek Polacek <polacek at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>, Jan Hubicka <hubicka at ucw dot cz>
- Date: Tue, 25 Aug 2015 17:44:16 +0200
- Subject: [PATCH] Don't ICE on invalid weak decl (PR middle-end/67330)
- Authentication-results: sourceware.org; auth=none
Here we are ICEing on an invalid code: symtab_node::get asserts that it's
dealing with a function or a static or external variable, but an invalid
decl is rejected too late. So don't try to mark_weak an invalid decl and
also don't duplicate the "declared weak after being used" check -- that is
already in mark_weak.
Perhaps we should also punt if (!TARGET_SUPPORTS_WEAK)?
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2015-08-25 Marek Polacek <polacek@redhat.com>
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.
diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c
index ff502e5..7691035 100644
--- gcc/c-family/c-common.c
+++ gcc/c-family/c-common.c
@@ -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);
diff --git gcc/testsuite/gcc.dg/weak/weak-18.c gcc/testsuite/gcc.dg/weak/weak-18.c
index e69de29..ebeb4d5 100644
--- gcc/testsuite/gcc.dg/weak/weak-18.c
+++ gcc/testsuite/gcc.dg/weak/weak-18.c
@@ -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" } */
+}
diff --git gcc/varasm.c gcc/varasm.c
index 7fa2e7b..d9290a1 100644
--- gcc/varasm.c
+++ gcc/varasm.c
@@ -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);
Marek