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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70156 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index e789e54..f2f8ae5 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -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());
+ }
}
}