[clang] f7c8ace - [CodeComplete] Fix a crash in preferred type and signature help
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 11 00:45:53 PST 2019
Author: Ilya Biryukov
Date: 2019-12-11T09:43:28+01:00
New Revision: f7c8ace4a52acecff7cd6ab61cbeaf677da1dd86
URL: https://github.com/llvm/llvm-project/commit/f7c8ace4a52acecff7cd6ab61cbeaf677da1dd86
DIFF: https://github.com/llvm/llvm-project/commit/f7c8ace4a52acecff7cd6ab61cbeaf677da1dd86.diff
LOG: [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
Added:
Modified:
clang/lib/Parse/ParseExprCXX.cpp
clang/unittests/Sema/CodeCompleteTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 7dfe71fb9ebc..fecd70b17e5b 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -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);
diff --git a/clang/unittests/Sema/CodeCompleteTest.cpp b/clang/unittests/Sema/CodeCompleteTest.cpp
index ab1792ba6376..a9441a679cac 100644
--- a/clang/unittests/Sema/CodeCompleteTest.cpp
+++ b/clang/unittests/Sema/CodeCompleteTest.cpp
@@ -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
More information about the cfe-commits
mailing list