forked from OSchip/llvm-project
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:
parent
a7b98a772c
commit
64fc3c68e5
|
@ -4636,10 +4636,15 @@ Sema::OwningExprResult Sema::ActOnBuiltinOffsetOf(Scope *S,
|
||||||
|
|
||||||
// FIXME: C++: Verify that MemberDecl isn't a static field.
|
// FIXME: C++: Verify that MemberDecl isn't a static field.
|
||||||
// FIXME: Verify that MemberDecl isn't a bitfield.
|
// FIXME: Verify that MemberDecl isn't a bitfield.
|
||||||
// MemberDecl->getType() doesn't get the right qualifiers, but it doesn't
|
if (cast<RecordDecl>(MemberDecl->getDeclContext())->isAnonymousStructOrUnion()) {
|
||||||
// matter here.
|
Res = static_cast<Expr*>(BuildAnonymousStructUnionMemberReference(
|
||||||
Res = new (Context) MemberExpr(Res, false, MemberDecl, OC.LocEnd,
|
SourceLocation(), MemberDecl, Res, SourceLocation()).release());
|
||||||
MemberDecl->getType().getNonReferenceType());
|
} 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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,3 +45,6 @@ int a(int len) {
|
||||||
int a[__builtin_offsetof(struct sockaddr_un, sun_path[len+1])];
|
int a[__builtin_offsetof(struct sockaddr_un, sun_path[len+1])];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PR4079
|
||||||
|
union x {struct {int x;};};
|
||||||
|
int x[__builtin_offsetof(union x, x)];
|
||||||
|
|
Loading…
Reference in New Issue