[PATCH] D71329: [CodeComplete] Fix a crash in preferred type and signature help
Ilya Biryukov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 11 00:31:35 PST 2019
ilya-biryukov created this revision.
ilya-biryukov added a reviewer: kadircet.
Herald added a project: clang.
sammccall accepted this revision.
This revision is now accepted and ready to land.
Null type pointers could be dereferenced in some cases.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D71329
Files:
clang/lib/Parse/ParseExprCXX.cpp
clang/unittests/Sema/CodeCompleteTest.cpp
Index: clang/unittests/Sema/CodeCompleteTest.cpp
===================================================================
--- clang/unittests/Sema/CodeCompleteTest.cpp
+++ clang/unittests/Sema/CodeCompleteTest.cpp
@@ -481,4 +481,12 @@
)cpp";
EXPECT_THAT(collectPreferredTypes(Code), Each("vector<int>"));
}
+
+TEST(PreferredTypeTest, NoCrashOnInvalidFunctionCasts) {
+ StringRef Code = R"cpp(
+ auto x = decltype(&1)(^);
+ auto y = new decltype(&1)(^);
+ )cpp";
+ EXPECT_THAT(collectPreferredTypes(Code), Each("NULL TYPE"));
+}
} // namespace
Index: clang/lib/Parse/ParseExprCXX.cpp
===================================================================
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -1862,9 +1862,11 @@
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,9 +3040,10 @@
auto RunSignatureHelp = [&]() {
ParsedType TypeRep =
Actions.ActOnTypeName(getCurScope(), DeclaratorInfo).get();
+ assert(TypeRep && "invalid types should be handled by that point");
QualType PreferredType = Actions.ProduceConstructorSignatureHelp(
- getCurScope(), TypeRep.get()->getCanonicalTypeInternal(),
- DeclaratorInfo.getEndLoc(), ConstructorArgs, ConstructorLParen);
+ getCurScope(), TypeRep.get()->getCanonicalTypeInternal(),
+ DeclaratorInfo.getEndLoc(), ConstructorArgs, ConstructorLParen);
CalledSignatureHelp = true;
return PreferredType;
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71329.233264.patch
Type: text/x-patch
Size: 2040 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191211/013a8ffb/attachment.bin>
More information about the cfe-commits
mailing list