[AST][RecoveryExpr] Fix a crash on a field decl with invalid type.

Summary:
The field decl (in the testcase) was still valid, which results in a
valid RecordDecl, it led to crash when performing struct layout,
and computing struct size etc.

Reviewers: sammccall

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D81913
This commit is contained in:
Haojian Wu 2020-06-16 09:25:17 +02:00
parent b7084d8ede
commit 28923dc2dd
2 changed files with 7 additions and 1 deletions

View File

@ -16479,7 +16479,7 @@ FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T,
// If we receive a broken type, recover by assuming 'int' and
// marking this declaration as invalid.
if (T.isNull()) {
if (T.isNull() || T->containsErrors()) {
InvalidDecl = true;
T = Context.IntTy;
}

View File

@ -13,3 +13,9 @@ class Y {
};
// Should be able to evaluate sizeof without crashing.
static_assert(sizeof(Y) == 1, "No valid members");
class Z {
int array[sizeof(invalid())]; // expected-error {{use of undeclared identifier}}
};
// Should be able to evaluate sizeof without crashing.
static_assert(sizeof(Z) == 1, "No valid members");