Skip to content

Commit f5b5426

Browse files
committed
[clang] Fix a crash on CheckArgAlignment.
We might encounter an undeduced type before calling getTypeAlignInChars. NOTE: this retrieves the fix from 8f80c66, which was removed in Adam's followup fix fbfcfdb. 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
1 parent 222314d commit f5b5426

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

clang/lib/Sema/SemaChecking.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4571,7 +4571,8 @@ void Sema::CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl,
45714571

45724572
// Find expected alignment, and the actual alignment of the passed object.
45734573
// getTypeAlignInChars requires complete types
4574-
if (ParamTy->isIncompleteType() || ArgTy->isIncompleteType())
4574+
if (ParamTy->isIncompleteType() || ArgTy->isIncompleteType() ||
4575+
ParamTy->isUndeducedType() || ArgTy->isUndeducedType())
45754576
return;
45764577

45774578
CharUnits ParamAlign = Context.getTypeAlignInChars(ParamTy);

clang/test/SemaCXX/typo-correction-crash.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,12 @@ class S {
4242
}
4343
};
4444
}
45+
46+
namespace NoCrashOnCheckArgAlignment {
47+
template <typename a> void b(a &);
48+
void test() {
49+
for (auto file_data :b(files_db_data)); // expected-error {{use of undeclared identifier 'files_db_data'; did you mean 'file_data'?}} \
50+
// expected-note {{'file_data' declared here}} \
51+
// expected-error {{cannot use type 'void' as a range}}
52+
}
53+
}

0 commit comments

Comments
 (0)