Commit e8ba94fc by Jan Hubicka Committed by Jan Hubicka

re PR c/21659 ([unit-at-a-time] "weak declaration must precede definition" error missing at >= O1)


	PR c/21659
	* doc/extend.texi (weak pragma): Drop claim that it must
	appear before definition.
	* varasm.c (merge_weak, declare_weak): Only sanity check
	that DECL is not output at a time it is declared weak.

From-SVN: r169184
parent 71c67403
2011-01-24 Jan Hubicka <jh@suse.cz>
PR c/21659
* doc/extend.texi (weak pragma): Drop claim that it must
appear before definition.
* varasm.c (merge_weak, declare_weak): Only sanity check
that DECL is not output at a time it is declared weak.
2011-01-24 Kenneth Zadeck <zadeck@naturalbridge.com> 2011-01-24 Kenneth Zadeck <zadeck@naturalbridge.com>
* machmode.def: Fixed comments. * machmode.def: Fixed comments.
......
...@@ -13024,8 +13024,7 @@ aliases. ...@@ -13024,8 +13024,7 @@ aliases.
@cindex pragma, weak @cindex pragma, weak
This pragma declares @var{symbol} to be weak, as if the declaration This pragma declares @var{symbol} to be weak, as if the declaration
had the attribute of the same name. The pragma may appear before had the attribute of the same name. The pragma may appear before
or after the declaration of @var{symbol}, but must appear before or after the declaration of @var{symbol}. It is not an error for
either its first use or its definition. It is not an error for
@var{symbol} to never be defined at all. @var{symbol} to never be defined at all.
@item #pragma weak @var{symbol1} = @var{symbol2} @item #pragma weak @var{symbol1} = @var{symbol2}
......
...@@ -5139,20 +5139,16 @@ merge_weak (tree newdecl, tree olddecl) ...@@ -5139,20 +5139,16 @@ merge_weak (tree newdecl, tree olddecl)
/* NEWDECL is weak, but OLDDECL is not. */ /* NEWDECL is weak, but OLDDECL is not. */
/* If we already output the OLDDECL, we're in trouble; we can't /* If we already output the OLDDECL, we're in trouble; we can't
go back and make it weak. This error cannot be caught in go back and make it weak. This should never happen in
declare_weak because the NEWDECL and OLDDECL was not yet unit-at-a-time compilation. */
been merged; therefore, TREE_ASM_WRITTEN was not set. */ gcc_assert (!TREE_ASM_WRITTEN (olddecl));
if (TREE_ASM_WRITTEN (olddecl))
error ("weak declaration of %q+D must precede definition",
newdecl);
/* If we've already generated rtl referencing OLDDECL, we may /* If we've already generated rtl referencing OLDDECL, we may
have done so in a way that will not function properly with have done so in a way that will not function properly with
a weak symbol. */ a weak symbol. Again in unit-at-a-time this should be
else if (TREE_USED (olddecl) impossible. */
&& TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl))) gcc_assert (!TREE_USED (olddecl)
warning (0, "weak declaration of %q+D after first use results " || !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)));
"in unspecified behavior", newdecl);
if (TARGET_SUPPORTS_WEAK) if (TARGET_SUPPORTS_WEAK)
{ {
...@@ -5184,10 +5180,9 @@ merge_weak (tree newdecl, tree olddecl) ...@@ -5184,10 +5180,9 @@ merge_weak (tree newdecl, tree olddecl)
void void
declare_weak (tree decl) declare_weak (tree decl)
{ {
gcc_assert (TREE_CODE (decl) != FUNCTION_DECL || !TREE_ASM_WRITTEN (decl));
if (! TREE_PUBLIC (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);
else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
error ("weak declaration of %q+D must precede definition", decl);
else if (!TARGET_SUPPORTS_WEAK) else if (!TARGET_SUPPORTS_WEAK)
warning (0, "weak declaration of %q+D not supported", decl); warning (0, "weak declaration of %q+D not supported", decl);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment