On Mon, Sep 22, 2025 at 5:21 PM Florian Weimer <[email protected]> wrote:
>
> * H. J. Lu:
>
> > @@ -8106,6 +8109,34 @@ grokdeclarator (const struct c_declarator
> > *declarator,
> > else
> > {
> > /* It's a variable. */
> > +
> > + const char *stack_protect_guard_name
> > + = targetm.stack_protect_guard_symbol;
> > + if (stack_protect_guard_name)
> > + {
> > + /* If the variable name is the same as the stack protect
> > + guard, use the stack protect guard decl. */
> > + tree guard_decl = targetm.stack_protect_guard ();
> > + if (guard_decl
> > + && VAR_P (guard_decl)
> > + && strcmp (stack_protect_guard_name,
> > + IDENTIFIER_POINTER (declarator->u.id.id)) == 0)
> > + {
> > + /* Allow different types with the same size. */
> > + tree guard_type = TREE_TYPE (guard_decl);
> > + if (TYPE_PRECISION (type)
> > + != TYPE_PRECISION (guard_type))
> > + {
> > + error ("conflicting types for %s; have %qT, "
> > + "should be %qT",
> > + stack_protect_guard_name, type,
> > + guard_type);
> > + return error_mark_node;
> > + }
> > + return guard_decl;
> > + }
> > + }
>
> It seems to me this goes in the wrong direction: guard_decl doesn't have
> proper location information, so any subsequent diagnostics against it
> will look wrong. I would expect this to be more like the re-declaration
It looks normal to me:
[hjl@gnu-zen4-1 pr121911]$ cat bad.c
extern const int __stack_chk_guard;
[hjl@gnu-zen4-1 pr121911]$ make bad.s
/export/build/gnu/tools-build/gcc-gitlab-debug/build-x86_64-linux/gcc/xgcc
-B/export/build/gnu/tools-build/gcc-gitlab-debug/build-x86_64-linux/gcc/
-O0 -g -fPIC -fstack-protector-all -mstack-protector-guard=global -S
bad.c
bad.c:1:1: error: conflicting types for __stack_chk_guard; have ‘int’,
should be ‘long unsigned int’
1 | extern const int __stack_chk_guard;
| ^~~~~~
make: *** [Makefile:43: bad.s] Error 1
[hjl@gnu-zen4-1 pr121911]$
> of builtins.
>
> But I'm not a GCC expert.
>
> Thanks,
> Florian
>
--
H.J.