Hi Guys,

  Redefining a previously defined static function as both public and
  weak triggers an ICE in ipa-visibility.c:

internal compiler error: in function_and_variable_visibility, at 
ipa-visibility.c:518

  This bug has been discussed and patch proposed here:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49899

  This submission is an updated version of that patch, made against
  the latest gcc sources.  It still chooses to generate an error message
  and disallow the conversion, which I hope is the correct action.

  OK to apply ?

Cheers
  Nick

gcc/ChangeLog
2016-02-17  Nick Clifton  <ni...@redhat.com>

        PR middle-end/49889
        * varasm.c (merge_weak): Generate an error if an attempt is made
        to convert a non-weak static function into a weak, public function.

gcc/testsuite/ChangeLog
2016-02-17  Nick Clifton  <ni...@redhat.com>

        PR middle-end/49889
        * gcc.dg/pr49889.c: New test.

Index: gcc/varasm.c
===================================================================
--- gcc/varasm.c        (revision 233486)
+++ gcc/varasm.c        (working copy)
@@ -5366,6 +5366,11 @@
       gcc_assert (!TREE_USED (olddecl)
                  || !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)));
 
+      /* PR 49899: You cannot convert a static function into a weak, public 
function.  */
+      if (! TREE_PUBLIC (olddecl) && TREE_PUBLIC (newdecl))
+       error ("weak declaration of %q+D being applied to a already "
+              "existing, static definition", newdecl);
+      
       if (TARGET_SUPPORTS_WEAK)
        {
          /* We put the NEWDECL on the weak_decls list at some point.
--- /dev/null   2016-02-17 08:13:41.436963282 +0000
+++ gcc/testsuite/gcc.dg/pr49899.c      2016-02-17 14:12:41.066733255 +0000
@@ -0,0 +1,3 @@
+static int foo (void) { return 0; } /* { dg-error "weak declaration of 'foo' 
being applied to a already existing, static definition" } */
+int foo (void)  __attribute__((weak));
+

Reply via email to