[patch][pr22217] Use the most recent decl for mangling

Richard Smith richard at metafoo.co.uk
Wed Jan 21 14:24:52 PST 2015

On Wed, Jan 21, 2015 at 1:52 PM, Rafael EspĂ­ndola
<rafael.espindola at gmail.com> wrote:
> On 21 January 2015 at 16:30, Richard Smith <richard at metafoo.co.uk> wrote:
>> On Tue, Jan 20, 2015 at 9:42 AM, David Majnemer
>> <david.majnemer at gmail.com> wrote:
>>> I don't think this approach would handle things like:
>>> int pr22217_foo;
>>> int *b = &pr22217_foo;
>>> extern int pr22217_foo __asm__("pr22217_bar");
>> I think we should either reject this code, or ignore the __asm__ with
>> a warning. __asm__ is effectively an attribute, and we don't support
>> adding attributes after we've seen the definition of an entity, for
>> exactly this reason. For instance:
> In here int is a tentative definition (C code).

It is also a tentative definition in the corresponding case with
__attribute__((section)). In that case, both GCC and Clang silently
ignore the attribute.

> It was also first noticed when building glibc, so it is both support
> by gcc and used in at least one location.
> I can add an error/warning for now. To be clear, you want to error/warn on
> int pr22217_foo;
> extern int pr22217_foo __asm__("pr22217_bar");
> Even when pr22217_foo is not used in between the two lines?

Yes, for now. If we find that breaks too much stuff (or the glibc
folks aren't prepared to change their code) then we can reconsider
whether we want to support this for tentative definitions. (The other
option is what I think you were suggesting before -- defer emitting
tentative definitions more aggressively. I'm OK with doing that too,
since that better matches the model espoused by the C standard, but I
think we should at least reject this for a non-tentative definition
followed by a declaration with an asm label.)

More information about the cfe-commits mailing list