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.

llvm-svn: 70156
This commit is contained in:
Eli Friedman 2009-04-26 20:50:44 +00:00
parent a7b98a772c
commit 64fc3c68e5
2 changed files with 12 additions and 4 deletions

View File

@ -4636,10 +4636,15 @@ Sema::OwningExprResult Sema::ActOnBuiltinOffsetOf(Scope *S,
// 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());
}
}
}

View File

@ -45,3 +45,6 @@ int a(int len) {
int a[__builtin_offsetof(struct sockaddr_un, sun_path[len+1])];
}
// PR4079
union x {struct {int x;};};
int x[__builtin_offsetof(union x, x)];