diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a12ae4e1dc7..ed251d2cdc3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2016-04-27 Nick Clifton + + 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. + 2016-04-27 Prathamesh Kulkarni * params.def (MAX_PARTITION_SIZE): New param. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6fd6cfa6669..4752a4cb069 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-04-27 Nick Clifton + + PR middle-end/49889 + * gcc.dg/pr49889.c: New test. + 2016-04-27 Bernd Schmidt * c-c++-common/memset-array.c: New test. diff --git a/gcc/testsuite/gcc.dg/pr49899.c b/gcc/testsuite/gcc.dg/pr49899.c new file mode 100644 index 00000000000..b5b32591ac7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr49899.c @@ -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)); + diff --git a/gcc/varasm.c b/gcc/varasm.c index c7ed06e549a..4a7124e73be 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -5371,6 +5371,11 @@ merge_weak (tree newdecl, tree olddecl) 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.