summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHaojian Wu <hokein@google.com>2018-12-19 13:44:41 +0000
committerHaojian Wu <hokein@google.com>2018-12-19 13:44:41 +0000
commite2a27b3f76f4249df786aa5b5fa0006a7f8c05a4 (patch)
treeb769d9ec2d95e9ef81ea41877843a3e5d7310fd8
parent6c95bea072a8999818c26da9fec9332cdf6d9bee (diff)
downloadbcm5719-llvm-e2a27b3f76f4249df786aa5b5fa0006a7f8c05a4.tar.gz
bcm5719-llvm-e2a27b3f76f4249df786aa5b5fa0006a7f8c05a4.zip
[Index] Index paremeters in lambda expressions.
Summary: This fixes clangd couldn't find references for lambda parameters. Reviewers: ilya-biryukov Subscribers: ioeric, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D55437 llvm-svn: 349626
-rw-r--r--clang/lib/Index/IndexBody.cpp11
-rw-r--r--clang/test/Index/cxx11-lambdas.cpp3
2 files changed, 14 insertions, 0 deletions
diff --git a/clang/lib/Index/IndexBody.cpp b/clang/lib/Index/IndexBody.cpp
index dd8a1c7b3f7..54a6df2496a 100644
--- a/clang/lib/Index/IndexBody.cpp
+++ b/clang/lib/Index/IndexBody.cpp
@@ -9,6 +9,7 @@
#include "IndexingContext.h"
#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/ASTLambda.h"
using namespace clang;
using namespace clang::index;
@@ -454,6 +455,16 @@ public:
}
return true;
}
+
+ bool VisitParmVarDecl(ParmVarDecl* D) {
+ // Index the parameters of lambda expression.
+ if (IndexCtx.shouldIndexFunctionLocalSymbols()) {
+ const auto *DC = D->getDeclContext();
+ if (DC && isLambdaCallOperator(DC))
+ IndexCtx.handleDecl(D);
+ }
+ return true;
+ }
};
} // anonymous namespace
diff --git a/clang/test/Index/cxx11-lambdas.cpp b/clang/test/Index/cxx11-lambdas.cpp
index 66df09ad294..6d6cbb63128 100644
--- a/clang/test/Index/cxx11-lambdas.cpp
+++ b/clang/test/Index/cxx11-lambdas.cpp
@@ -7,6 +7,7 @@ struct X {
auto lambda = [&localA, localB] (Integer x) -> Integer {
return localA + localB + x;
};
+ auto lambda2 = [](Integer y) {};
}
};
@@ -26,8 +27,10 @@ struct X {
// RUN: env CINDEXTEST_INDEXLOCALSYMBOLS=1 c-index-test -index-file -std=c++11 %s | FileCheck -check-prefix=CHECK-INDEX %s
// CHECK-INDEX: [indexEntityReference]: kind: variable | name: localA | USR: c:cxx11-lambdas.cpp@100@S@X@F@f#@localA | lang: C | cursor: VariableRef=localA:6:9 | loc: 7:21
// CHECK-INDEX: [indexEntityReference]: kind: variable | name: localB | USR: c:cxx11-lambdas.cpp@100@S@X@F@f#@localB | lang: C | cursor: VariableRef=localB:6:17 | loc: 7:29
+// CHECK-INDEX: [indexDeclaration]: kind: variable | name: x | USR: c:cxx11-lambdas.cpp@157@S@X@F@f#@Sa@F@operator()#I#1@x | lang: C | cursor: ParmDecl=x:7:46 (Definition) | loc: 7:46
// CHECK-INDEX: [indexEntityReference]: kind: typedef | name: Integer | USR: c:cxx11-lambdas.cpp@T@Integer | lang: C | cursor: TypeRef=Integer:3:13 | loc: 7:52
// CHECK-INDEX: [indexEntityReference]: kind: typedef | name: Integer | USR: c:cxx11-lambdas.cpp@T@Integer | lang: C | cursor: TypeRef=Integer:3:13 | loc: 7:38
// CHECK-INDEX: [indexEntityReference]: kind: variable | name: localA | USR: c:cxx11-lambdas.cpp@100@S@X@F@f#@localA | lang: C | cursor: DeclRefExpr=localA:6:9 | loc: 8:14
// CHECK-INDEX: [indexEntityReference]: kind: variable | name: localB | USR: c:cxx11-lambdas.cpp@100@S@X@F@f#@localB | lang: C | cursor: DeclRefExpr=localB:6:17 | loc: 8:23
// CHECK-INDEX: [indexEntityReference]: kind: variable | name: x | USR: c:cxx11-lambdas.cpp@157@S@X@F@f#@Sa@F@operator()#I#1@x | lang: C | cursor: DeclRefExpr=x:7:46 | loc: 8:32
+// CHECK-INDEX: [indexDeclaration]: kind: variable | name: y | USR: c:cxx11-lambdas.cpp@244@S@X@F@f#@Sa@F@operator()#I#1@y | lang: C | cursor: ParmDecl=y:10:31 (Definition) | loc: 10:31 \ No newline at end of file
OpenPOWER on IntegriCloud