forked from OSchip/llvm-project
[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:
parent
8a7c52bc22
commit
f7c8ace4a5
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue