diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 0c9d2010e3777d..64d838d2cd74f4 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -14477,7 +14477,8 @@ static getBaseAlignmentAndOffsetFromLValue(const Expr *E, ASTContext &Ctx) { case Stmt::MemberExprClass: { auto *ME = cast(E); auto *FD = dyn_cast(ME->getMemberDecl()); - if (!FD || FD->getType()->isReferenceType()) + if (!FD || FD->getType()->isReferenceType() || + FD->getParent()->isInvalidDecl()) break; Optional> P; if (ME->isArrow()) diff --git a/clang/test/Sema/warn-cast-align.c b/clang/test/Sema/warn-cast-align.c index 389c0c17d2f7da..7df71997bf3e2e 100644 --- a/clang/test/Sema/warn-cast-align.c +++ b/clang/test/Sema/warn-cast-align.c @@ -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}} +}