Find references inside blocks.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77540 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Index/ASTLocation.cpp b/lib/Index/ASTLocation.cpp
index d528c5a..f010a2b 100644
--- a/lib/Index/ASTLocation.cpp
+++ b/lib/Index/ASTLocation.cpp
@@ -103,6 +103,18 @@
return isContainedInStatement(Node, MD->getBody()) ? D : 0;
}
+ if (BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
+ for (DeclContext::decl_iterator
+ I = BD->decls_begin(), E = BD->decls_end(); I != E; ++I) {
+ Decl *Child = FindImmediateParent(*I, Node);
+ if (Child)
+ return Child;
+ }
+
+ assert(BD->getBody() && "BlockDecl without body ?");
+ return isContainedInStatement(Node, BD->getBody()) ? D : 0;
+ }
+
return 0;
}
diff --git a/lib/Index/ASTVisitor.h b/lib/Index/ASTVisitor.h
index 330bf01..11089f0 100644
--- a/lib/Index/ASTVisitor.h
+++ b/lib/Index/ASTVisitor.h
@@ -94,6 +94,10 @@
Visit(*I);
}
+ void VisitBlockExpr(BlockExpr *Node) {
+ Visit(Node->getBlockDecl());
+ }
+
void VisitStmt(Stmt *Node) {
for (Stmt::child_iterator
I = Node->child_begin(), E = Node->child_end(); I != E; ++I)
diff --git a/test/Index/find-refs.c b/test/Index/find-refs.c
index 741f840..8090e67 100644
--- a/test/Index/find-refs.c
+++ b/test/Index/find-refs.c
@@ -2,8 +2,9 @@
// RUN: clang-cc -emit-pch %S/t2.c -o %t2.ast &&
// RUN: index-test %t1.ast %t2.ast -point-at %S/foo.h:1:14 -print-refs > %t &&
-// RUN: cat %t | count 3 &&
+// RUN: cat %t | count 4 &&
// RUN: grep 't1.c:4:19,' %t &&
+// RUN: grep 't1.c:28:40,' %t &&
// RUN: grep 't2.c:6:3,' %t &&
// RUN: grep 't2.c:7:12,' %t &&
diff --git a/test/Index/t1.c b/test/Index/t1.c
index 8b57a58..45e0488 100644
--- a/test/Index/t1.c
+++ b/test/Index/t1.c
@@ -25,5 +25,7 @@
ms.field_var = 10;
}
+int (^CP)(int) = ^(int x) { return x * global_var; };
+
// Suppress 'no run line' failure.
// RUN: true