r221641 - [libclang] When initializing an ObjC object via the "[[ClassName alloc] init*]" pattern,
Argyrios Kyrtzidis
akyrtzi at gmail.com
Mon Nov 10 15:21:35 PST 2014
Author: akirtzidis
Date: Mon Nov 10 17:21:35 2014
New Revision: 221641
URL: http://llvm.org/viewvc/llvm-project?rev=221641&view=rev
Log:
[libclang] When initializing an ObjC object via the "[[ClassName alloc] init*]" pattern,
report the 'init*' invocation as non-dynamic via clang_Cursor_isDynamicCall.
Of course it is dynamic at runtime, but for purposes of indexing we can treat as an invocation to ClassName's init*.
Addresses rdar://18916871.
Modified:
cfe/trunk/test/Index/cursor-dynamic-call.mm
cfe/trunk/tools/libclang/CXCursor.cpp
Modified: cfe/trunk/test/Index/cursor-dynamic-call.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/cursor-dynamic-call.mm?rev=221641&r1=221640&r2=221641&view=diff
==============================================================================
--- cfe/trunk/test/Index/cursor-dynamic-call.mm (original)
+++ cfe/trunk/test/Index/cursor-dynamic-call.mm Mon Nov 10 17:21:35 2014
@@ -37,6 +37,18 @@ void foo(SS *ss, IS* is, Class cls) {
[cls ClsMeth];
}
+ at interface NSObject
++(id)alloc;
+-(id)init;
+ at end
+
+ at interface Test : NSObject
+ at end
+
+void test2() {
+ id o = [[Test alloc] init];
+}
+
// RUN: c-index-test -cursor-at=%s:8:11 \
// RUN: -cursor-at=%s:9:11 \
// RUN: -cursor-at=%s:25:11 \
@@ -46,6 +58,7 @@ void foo(SS *ss, IS* is, Class cls) {
// RUN: -cursor-at=%s:35:9 \
// RUN: -cursor-at=%s:36:9 \
// RUN: -cursor-at=%s:37:9 \
+// RUN: -cursor-at=%s:49:26 \
// RUN: %s | FileCheck %s
// CHECK: 8:11 MemberRefExpr=meth:3:16 {{.*}} Dynamic-call
@@ -59,3 +72,4 @@ void foo(SS *ss, IS* is, Class cls) {
// CHECK-NOT: 36:3 {{.*}} Dynamic-call
// CHECK: 36:3 {{.*}} Receiver-type=ObjCInterface
// CHECK: 37:3 ObjCMessageExpr=ClsMeth:15:8 {{.*}} Dynamic-call Receiver-type=ObjCClass
+// CHECK-NOT: 49:10 {{.*}} Dynamic-call
Modified: cfe/trunk/tools/libclang/CXCursor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXCursor.cpp?rev=221641&r1=221640&r2=221641&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXCursor.cpp (original)
+++ cfe/trunk/tools/libclang/CXCursor.cpp Mon Nov 10 17:21:35 2014
@@ -1417,8 +1417,16 @@ int clang_Cursor_isDynamicCall(CXCursor
if (!E)
return 0;
- if (const ObjCMessageExpr *MsgE = dyn_cast<ObjCMessageExpr>(E))
- return MsgE->getReceiverKind() == ObjCMessageExpr::Instance;
+ if (const ObjCMessageExpr *MsgE = dyn_cast<ObjCMessageExpr>(E)) {
+ if (MsgE->getReceiverKind() != ObjCMessageExpr::Instance)
+ return false;
+ if (auto *RecE = dyn_cast<ObjCMessageExpr>(
+ MsgE->getInstanceReceiver()->IgnoreParenCasts())) {
+ if (RecE->getMethodFamily() == OMF_alloc)
+ return false;
+ }
+ return true;
+ }
const MemberExpr *ME = nullptr;
if (isa<MemberExpr>(E))
More information about the cfe-commits
mailing list