summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2019-04-04 11:34:18 +0000
committerSam McCall <sam.mccall@gmail.com>2019-04-04 11:34:18 +0000
commitbc7ff89964529d3d291e924886f5d2ea08541994 (patch)
tree68f6e0947b236d870761e31c5d5960abde81a583
parent937bc02fd6d68446556c074b1261447d7af737fd (diff)
downloadbcm5719-llvm-bc7ff89964529d3d291e924886f5d2ea08541994.tar.gz
bcm5719-llvm-bc7ff89964529d3d291e924886f5d2ea08541994.zip
[CodeComplete] Fix crash when completing ObjC block parameter with a broken type
Summary: The fix isn't great, but it's hard to fix properly because the completion code sensibly uses ParmVarDecl to represent parameters, but the AST-building code sensibly doesn't synthesize them if the type is broken. Also this case is apparently really rare, so it's probably not worth bending over backwards for. Reviewers: ilya-biryukov Subscribers: javed.absar, kristof.beyls, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60258 llvm-svn: 357686
-rw-r--r--clang/lib/Sema/SemaCodeComplete.cpp5
-rw-r--r--clang/test/Index/complete-blocks.m12
2 files changed, 17 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index 2412d919ec9..8d953308d81 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -2605,6 +2605,11 @@ static std::string
FormatFunctionParameter(const PrintingPolicy &Policy, const ParmVarDecl *Param,
bool SuppressName = false, bool SuppressBlock = false,
Optional<ArrayRef<QualType>> ObjCSubsts = None) {
+ // Params are unavailable in FunctionTypeLoc if the FunctionType is invalid.
+ // It would be better to pass in the param Type, which is usually avaliable.
+ // But this case is rare, so just pretend we fell back to int as elsewhere.
+ if (!Param)
+ return "int";
bool ObjCMethodParam = isa<ObjCMethodDecl>(Param->getDeclContext());
if (Param->getType()->isDependentType() ||
!Param->getType()->isBlockPointerType()) {
diff --git a/clang/test/Index/complete-blocks.m b/clang/test/Index/complete-blocks.m
index 046a08695d0..9c6c1cbf86d 100644
--- a/clang/test/Index/complete-blocks.m
+++ b/clang/test/Index/complete-blocks.m
@@ -50,6 +50,15 @@ void test_f2(I1 *o) {
[o method7:0];
}
+// Crash regression test. Param info for broken function types isn't available.
+typedef UnresolvedType *(^XXX)(float);
+@interface Foo
+-(void) foo:(XXX)arg;
+@end
+void testUnresolved(Foo* f) {
+ [f foo:0];
+}
+
// RUN: c-index-test -code-completion-at=%s:8:1 %s | FileCheck -check-prefix=CHECK-CC1 %s
// CHECK-CC1: FunctionDecl:{ResultType void}{TypedText f}{LeftParen (}{Placeholder ^int(int x, int y)block}{RightParen )} (50)
// CHECK-CC1: FunctionDecl:{ResultType void}{TypedText g}{LeftParen (}{Placeholder ^(float f, double d)b}{RightParen )} (50)
@@ -74,3 +83,6 @@ void test_f2(I1 *o) {
// CHECK-CC7: FunctionDecl:{ResultType void}{TypedText f2}{LeftParen (}{Placeholder ^int(int x, int y)block}{RightParen )} (50)
// RUN: c-index-test -code-completion-at=%s:50:6 %s | FileCheck -check-prefix=CHECK-CC8 %s
// CHECK-CC8: ObjCInstanceMethodDecl:{ResultType id}{TypedText method7:}{Placeholder ^int(int x, int y)b} (35)
+
+// RUN: c-index-test -code-completion-at=%s:59:6 %s | FileCheck -check-prefix=CHECK-CC9 %s
+// CHECK-CC9: ObjCInstanceMethodDecl:{ResultType void}{TypedText foo:}{Placeholder ^int *(int)arg} (35)
OpenPOWER on IntegriCloud