[CodeComplete] Fix a crash in preferred type and signature help

Summary: Null type pointers could be dereferenced in some cases.

Reviewers: kadircet, sammccall

Reviewed By: sammccall

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71329
This commit is contained in:
Ilya Biryukov 2019-12-11 09:38:14 +01:00
parent 8a7c52bc22
commit f7c8ace4a5
2 changed files with 14 additions and 3 deletions

View File

@ -1862,9 +1862,11 @@ Parser::ParseCXXTypeConstructExpression(const DeclSpec &DS) {
CommaLocsTy CommaLocs;
auto RunSignatureHelp = [&]() {
QualType PreferredType = Actions.ProduceConstructorSignatureHelp(
getCurScope(), TypeRep.get()->getCanonicalTypeInternal(),
DS.getEndLoc(), Exprs, T.getOpenLocation());
QualType PreferredType;
if (TypeRep)
PreferredType = Actions.ProduceConstructorSignatureHelp(
getCurScope(), TypeRep.get()->getCanonicalTypeInternal(),
DS.getEndLoc(), Exprs, T.getOpenLocation());
CalledSignatureHelp = true;
return PreferredType;
};
@ -3038,6 +3040,7 @@ Parser::ParseCXXNewExpression(bool UseGlobal, SourceLocation Start) {
auto RunSignatureHelp = [&]() {
ParsedType TypeRep =
Actions.ActOnTypeName(getCurScope(), DeclaratorInfo).get();
assert(TypeRep && "invalid types should be handled before");
QualType PreferredType = Actions.ProduceConstructorSignatureHelp(
getCurScope(), TypeRep.get()->getCanonicalTypeInternal(),
DeclaratorInfo.getEndLoc(), ConstructorArgs, ConstructorLParen);

View File

@ -481,4 +481,12 @@ TEST(PreferredTypeTest, FunctionArguments) {
)cpp";
EXPECT_THAT(collectPreferredTypes(Code), Each("vector<int>"));
}
TEST(PreferredTypeTest, NoCrashOnInvalidTypes) {
StringRef Code = R"cpp(
auto x = decltype(&1)(^);
auto y = new decltype(&1)(^);
)cpp";
EXPECT_THAT(collectPreferredTypes(Code), Each("NULL TYPE"));
}
} // namespace