[cfe-dev] [PATCH] Another patch for unnamed structure/union fields

Patrick Walton pcwalton at cs.ucla.edu
Sat Nov 15 11:41:42 PST 2008


I see that Pierre d'Herbemont has created a patch for unnamed inner 
records. At the same time I've been working on one as well. I'd like to 
submit it here too, at the suggestion of Eli Friedman.

This patch causes clang to add extra MemberExpr nodes to the AST when 
fields of inner unnamed records are accessed. I first tried to implement 
the necessary logic in CodeGen, but this proved to be overly complex: 
the code generator is really welded to the idea that each MemberExpr 
denotes a single GEP instruction in either a single struct or a single 
union. In my proposed patch, the Sema module expands access to an inner 
field into the correct number of MemberExpr nodes at AST construction 
time. This approach essentially treats unnamed structs and unions as 
syntactic sugar, which seems valid to me.

The CodePrinter logic is modified to deal with this. I've tested code 
generation on x86_64 and through lli, and it seems to work.

Pierre's patch selectively turns on the extension only when -std=gnu99 
is specified. This is a good idea IMO, which I hadn't thought of. So I 
would suggest that our two patches be merged, because mine adds the code 
generation, while his has better parsing logic.

Comments would be appreciated. Thanks!

Patrick

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: clang-unnamed-union.patch
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20081115/bb3e6c7a/attachment.ksh>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3250 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20081115/bb3e6c7a/attachment.bin>


More information about the cfe-dev mailing list