r340109 - [index] For an ObjC message call, also record as receivers the protocols if they are present in the ObjC type
Argyrios Kyrtzidis via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 17 16:50:59 PDT 2018
Author: akirtzidis
Date: Fri Aug 17 16:50:59 2018
New Revision: 340109
URL: http://llvm.org/viewvc/llvm-project?rev=340109&view=rev
Log:
[index] For an ObjC message call, also record as receivers the protocols if they are present in the ObjC type
Modified:
cfe/trunk/lib/Index/IndexBody.cpp
cfe/trunk/test/Index/Core/index-source.m
Modified: cfe/trunk/lib/Index/IndexBody.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexBody.cpp?rev=340109&r1=340108&r2=340109&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexBody.cpp (original)
+++ cfe/trunk/lib/Index/IndexBody.cpp Fri Aug 17 16:50:59 2018
@@ -259,8 +259,24 @@ public:
if (isDynamic(E)) {
Roles |= (unsigned)SymbolRole::Dynamic;
- if (auto *RecD = E->getReceiverInterface())
- Relations.emplace_back((unsigned)SymbolRole::RelationReceivedBy, RecD);
+
+ auto addReceivers = [&](const ObjCObjectType *Ty) {
+ if (!Ty)
+ return;
+ if (const auto *clsD = Ty->getInterface()) {
+ Relations.emplace_back((unsigned)SymbolRole::RelationReceivedBy,
+ clsD);
+ }
+ for (const auto *protD : Ty->quals()) {
+ Relations.emplace_back((unsigned)SymbolRole::RelationReceivedBy,
+ protD);
+ }
+ };
+ QualType recT = E->getReceiverType();
+ if (const auto *Ptr = recT->getAs<ObjCObjectPointerType>())
+ addReceivers(Ptr->getObjectType());
+ else
+ addReceivers(recT->getAs<ObjCObjectType>());
}
return IndexCtx.handleReference(MD, E->getSelectorStartLoc(),
Modified: cfe/trunk/test/Index/Core/index-source.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-source.m?rev=340109&r1=340108&r2=340109&view=diff
==============================================================================
--- cfe/trunk/test/Index/Core/index-source.m (original)
+++ cfe/trunk/test/Index/Core/index-source.m Fri Aug 17 16:50:59 2018
@@ -2,7 +2,7 @@
// RUN: c-index-test core -print-source-symbols -include-locals -- %s -target x86_64-apple-macosx10.7 | FileCheck -check-prefix=LOCAL %s
@interface Base
-// CHECK: [[@LINE-1]]:12 | class/ObjC | Base | c:objc(cs)Base | _OBJC_CLASS_$_Base | Decl | rel: 0
+// CHECK: [[@LINE-1]]:12 | class/ObjC | Base | [[BASE_USR:.*]] | _OBJC_CLASS_$_Base | Decl | rel: 0
-(void)meth;
// CHECK: [[@LINE-1]]:8 | instance-method/ObjC | meth | c:objc(cs)Base(im)meth | -[Base meth] | Decl,Dyn,RelChild | rel: 1
// CHECK-NEXT: RelChild | Base | c:objc(cs)Base
@@ -60,7 +60,7 @@ void goo(Base *b) {
Base *f = (Base *) 2;
}
-// CHECK: [[@LINE+1]]:11 | protocol/ObjC | Prot1 | c:objc(pl)Prot1 | <no-cgname> | Decl | rel: 0
+// CHECK: [[@LINE+1]]:11 | protocol/ObjC | Prot1 | [[PROT1_USR:.*]] | <no-cgname> | Decl | rel: 0
@protocol Prot1
@end
@@ -472,3 +472,21 @@ void testImplicitProperties(ImplicitProp
}
@end
+
+ at protocol Prot3 // CHECK: [[@LINE]]:11 | protocol/ObjC | Prot3 | [[PROT3_USR:.*]] | <no-cgname> | Decl |
+-(void)meth;
+ at end
+
+void test_rec1() {
+ id<Prot3, Prot1> o1;
+ [o1 meth]; // CHECK: [[@LINE]]:7 | instance-method/ObjC | meth | {{.*}} | Ref,Call,Dyn,RelRec,RelCall,RelCont | rel: 3
+ // CHECK-NEXT: RelCall,RelCont | test_rec1 |
+ // CHECK-NEXT: RelRec | Prot3 | [[PROT3_USR]]
+ // CHECK-NEXT: RelRec | Prot1 | [[PROT1_USR]]
+ Base<Prot3, Prot1> *o2;
+ [o2 meth]; // CHECK: [[@LINE]]:7 | instance-method/ObjC | meth | {{.*}} | Ref,Call,Dyn,RelRec,RelCall,RelCont | rel: 4
+ // CHECK-NEXT: RelCall,RelCont | test_rec1 |
+ // CHECK-NEXT: RelRec | Base | [[BASE_USR]]
+ // CHECK-NEXT: RelRec | Prot3 | [[PROT3_USR]]
+ // CHECK-NEXT: RelRec | Prot1 | [[PROT1_USR]]
+}
More information about the cfe-commits
mailing list