[cfe-dev] #pragma weak handling

Abramo Bagnara abramobagnara at tin.it
Wed Nov 25 23:06:20 PST 2009


Il 25/11/2009 23:39, Erik Cederstrand ha scritto:
>
> Den 25/11/2009 kl. 23.19 skrev Abramo Bagnara:
>
>> struct in6_addr
>>    {
>>      union
>>        {
>>          unsigned char __u6_addr8[16];
>>          unsigned short __u6_addr16[8];
>>          unsigned int __u6_addr32[4];
>>      } __in6_u;
>> };
>>
>> extern const struct in6_addr in6addr_any;
>>
>> static const struct in6_addr local_in6addr_any = { { {
>> 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } };
>> #pragma weak in6addr_any = local_in6addr_any
>>
>> Examining the ast generated for this snippet I note two problems:
>>
>> 1) the extra declaration generated by #pragma has the following form:
>>
>> static const struct in6_addr in6addr_any __attribute__ ((weak))
>> __attribute__ ((alias("local_in6addr_any")));
>>
>> The problem I see is that "static" should be replaced by "extern".
>>
>> I think that the bug is in Sema::DeclClonePragmaWeak(NamedDecl *ND,
>> IdentifierInfo *II) where it is copied also the storage class of VarDecl.
>>
>> 2) the extra declaration generated by #pragma seems to be not linked to
>> other declarations for the same object and then getCanonicalDecl does
>> not work as expected.
>>
>> I'd like to know if this analysis is correct and if yes, what's the
>> suggested way to fix point 2 (I think that the fix to point 1 is rather
>> obvious).
>
> Bug #3679 covers this problem, I think. Comment #32 states that "#pragma weak foo" after defining function foo() doesn't work.

Please consider that the problems I describe are not at codegen level, 
but at level of AST building.




More information about the cfe-dev mailing list