On Thu, Jan 22, 2026 at 04:33:18PM +0100, Michal Jires wrote:
> --- a/gcc/c/c-decl.cc
> +++ b/gcc/c/c-decl.cc
> @@ -13669,7 +13669,9 @@ c_write_global_declarations_1 (tree globals)
> if (TREE_CODE (decl) == FUNCTION_DECL
> && DECL_INITIAL (decl) == NULL_TREE
> && DECL_EXTERNAL (decl)
> - && !TREE_PUBLIC (decl))
> + && !TREE_PUBLIC (decl)
> + /* Symbols defined in assembly. */
> + && !TREE_ASM_WRITTEN (decl))
I must say I'm not sure if using TREE_ASM_WRITTEN for this is safe, it means
what it is documented for:
/* Nonzero in a VAR_DECL or STRING_CST means assembler code has been written.
Nonzero in a FUNCTION_DECL means that the function has been compiled.
This is interesting in an inline function, since it might not need
to be compiled separately.
E.g. I wonder if it won't change behavior for (questionable and perhaps
invalid)
extern int a;
asm("" :: ":" (&a));
int a = 42;
because assemble_variable just punts on TREE_ASM_WRITTEN VAR_DECLs.
Anyway, even if it is valid, comment like the above doesn't seem
appropriate, because TREE_ASM_WRITTEN (decl) doesn't mean symbol defined in
assembly. It means in your patch that or cfgexpand has been done on
a definition of the function already or (if it would also allow VAR_DECLs)
that a var definition has been emitted into assembly or that a
function/variable alias has been emitted etc.
If all you test is TREE_ASM_WRITTEN on are FUNCTION_DECLs, perhaps the
flag should be set solely on ":" with FUNCTION_DECLs.
Jakub