My FE change from 2 years ago uses TREE_ASM_WRITTEN in -fsyntax-only
mode more aggressively to avoid "expanding" functions multiple times.
With -fsyntax-only nothing is really expanded, so I think it is acceptable
to adjust the assert and allow declare_weak at any time, with -fsyntax-only
we know it is during parsing only anyway.
2021-02-10 Jakub Jelinek <jakub@redhat.com>
PR c++/99035
* varasm.c (declare_weak): For -fsyntax-only, allow even
TREE_ASM_WRITTEN function decls.
* g++.dg/ext/weak6.C: New test.
--- /dev/null
+// PR c++/99035
+// { dg-do compile }
+// { dg-require-weak "" }
+// { dg-options "-fsyntax-only" }
+
+extern void * foo (void);
+void * foo (void) { return (void *)foo; }
+#pragma weak foo
void
declare_weak (tree decl)
{
- gcc_assert (TREE_CODE (decl) != FUNCTION_DECL || !TREE_ASM_WRITTEN (decl));
+ /* With -fsyntax-only, TREE_ASM_WRITTEN might be set on certain function
+ decls earlier than normally, but as with -fsyntax-only nothing is really
+ emitted, there is no harm in marking it weak later. */
+ gcc_assert (TREE_CODE (decl) != FUNCTION_DECL
+ || !TREE_ASM_WRITTEN (decl)
+ || flag_syntax_only);
if (! TREE_PUBLIC (decl))
{
error ("weak declaration of %q+D must be public", decl);