[cfe-dev] #pragma weak handling
Erik Cederstrand
erik at cederstrand.dk
Wed Nov 25 14:39:23 PST 2009
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.
Thanks,
Erik Cederstrand
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1928 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20091125/07aeb5fb/attachment.bin>
More information about the cfe-dev
mailing list