[clang] Fix a crash on CheckArgAlignment.

We might encounter an undeduced type before calling getTypeAlignInChars.

NOTE: this retrieves the fix from
8f80c66bd2, which was removed in Adam's
followup fix fbfcfdbf68. We originally
thought the crash was caused by recovery-ast, but it turns out it can
occur for other cases, e.g. typo-correction.

Differential Revision: https://reviews.llvm.org/D102750
This commit is contained in:
Haojian Wu 2021-05-19 10:26:03 +02:00
parent 222314d8b0
commit f5b5426433
2 changed files with 11 additions and 1 deletions

View File

@ -4571,7 +4571,8 @@ void Sema::CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl,
// Find expected alignment, and the actual alignment of the passed object.
// getTypeAlignInChars requires complete types
if (ParamTy->isIncompleteType() || ArgTy->isIncompleteType())
if (ParamTy->isIncompleteType() || ArgTy->isIncompleteType() ||
ParamTy->isUndeducedType() || ArgTy->isUndeducedType())
return;
CharUnits ParamAlign = Context.getTypeAlignInChars(ParamTy);

View File

@ -42,3 +42,12 @@ class S {
}
};
}
namespace NoCrashOnCheckArgAlignment {
template <typename a> void b(a &);
void test() {
for (auto file_data :b(files_db_data)); // expected-error {{use of undeclared identifier 'files_db_data'; did you mean 'file_data'?}} \
// expected-note {{'file_data' declared here}} \
// expected-error {{cannot use type 'void' as a range}}
}
}