forked from OSchip/llvm-project
Fix a failing assertion with -Wcast-align
When there is unknown type in a struct in code compiled with -Wcast-align, the compiler crashes due to clang::ASTContext::getASTRecordLayout() failing an assert. Added check that the RecordDecl is valid before calling getASTRecordLayout().
This commit is contained in:
parent
e81ba28313
commit
3c5721d772
|
@ -14477,7 +14477,8 @@ static getBaseAlignmentAndOffsetFromLValue(const Expr *E, ASTContext &Ctx) {
|
|||
case Stmt::MemberExprClass: {
|
||||
auto *ME = cast<MemberExpr>(E);
|
||||
auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
|
||||
if (!FD || FD->getType()->isReferenceType())
|
||||
if (!FD || FD->getType()->isReferenceType() ||
|
||||
FD->getParent()->isInvalidDecl())
|
||||
break;
|
||||
Optional<std::pair<CharUnits, CharUnits>> P;
|
||||
if (ME->isArrow())
|
||||
|
|
|
@ -67,3 +67,11 @@ unsigned int func5(void);
|
|||
FnTy test5(void) {
|
||||
return (FnTy)&func5;
|
||||
}
|
||||
|
||||
void test6() {
|
||||
struct {
|
||||
int hello;
|
||||
doesnotexist world; // expected-error {{unknown type name 'doesnotexist'}}
|
||||
} foo;
|
||||
void **repro = (void **)&foo.hello; // expected-warning {{cast from 'int *' to 'void **' increases required alignment from 4 to 8}}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue