[cfe-commits] r70156 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/Sema/offsetof.c
Eli Friedman
eli.friedman at gmail.com
Sun Apr 26 13:50:44 PDT 2009
Author: efriedma
Date: Sun Apr 26 15:50:44 2009
New Revision: 70156
URL: http://llvm.org/viewvc/llvm-project?rev=70156&view=rev
Log:
Fix for PR4079: make sure to construct the member expressions for
offsetof correctly in the presence of anonymous structs/unions.
This could definitely use some cleanup, but I don't really want to mess
with the anonymous union/struct code.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/offsetof.c
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=70156&r1=70155&r2=70156&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun Apr 26 15:50:44 2009
@@ -4636,10 +4636,15 @@
// FIXME: C++: Verify that MemberDecl isn't a static field.
// FIXME: Verify that MemberDecl isn't a bitfield.
- // MemberDecl->getType() doesn't get the right qualifiers, but it doesn't
- // matter here.
- Res = new (Context) MemberExpr(Res, false, MemberDecl, OC.LocEnd,
- MemberDecl->getType().getNonReferenceType());
+ if (cast<RecordDecl>(MemberDecl->getDeclContext())->isAnonymousStructOrUnion()) {
+ Res = static_cast<Expr*>(BuildAnonymousStructUnionMemberReference(
+ SourceLocation(), MemberDecl, Res, SourceLocation()).release());
+ } else {
+ // MemberDecl->getType() doesn't get the right qualifiers, but it
+ // doesn't matter here.
+ Res = new (Context) MemberExpr(Res, false, MemberDecl, OC.LocEnd,
+ MemberDecl->getType().getNonReferenceType());
+ }
}
}
Modified: cfe/trunk/test/Sema/offsetof.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/offsetof.c?rev=70156&r1=70155&r2=70156&view=diff
==============================================================================
--- cfe/trunk/test/Sema/offsetof.c (original)
+++ cfe/trunk/test/Sema/offsetof.c Sun Apr 26 15:50:44 2009
@@ -45,3 +45,6 @@
int a[__builtin_offsetof(struct sockaddr_un, sun_path[len+1])];
}
+// PR4079
+union x {struct {int x;};};
+int x[__builtin_offsetof(union x, x)];
More information about the cfe-commits
mailing list