sammccall created this revision.
sammccall added a reviewer: ilya-biryukov.
Herald added subscribers: cfe-commits, arphaman, kristof.beyls, javed.absar.
Herald added a project: clang.
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.
Repository:
rC Clang
https://reviews.llvm.org/D60258
Files:
lib/Sema/SemaCodeComplete.cpp
test/Index/complete-blocks.m
Index: test/Index/complete-blocks.m
===================================================================
--- test/Index/complete-blocks.m
+++ test/Index/complete-blocks.m
@@ -50,6 +50,15 @@
[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 @@
// 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)
Index: lib/Sema/SemaCodeComplete.cpp
===================================================================
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -2605,6 +2605,11 @@
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()) {
Index: test/Index/complete-blocks.m
===================================================================
--- test/Index/complete-blocks.m
+++ test/Index/complete-blocks.m
@@ -50,6 +50,15 @@
[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 @@
// 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)
Index: lib/Sema/SemaCodeComplete.cpp
===================================================================
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -2605,6 +2605,11 @@
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()) {
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits