summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Liu <ioeric@google.com>2018-07-20 08:08:56 +0000
committerEric Liu <ioeric@google.com>2018-07-20 08:08:56 +0000
commit3f7d4073a85d7d8be791ca7f018bd109adda0e0f (patch)
treee02754b9f16d38f74a7a7207bea35a53eb9604c2
parent141ca05e332ab0be507a7325313fe230a9506a7a (diff)
[Index] Set OrigD before D is changed.
Reviewers: akyrtzi, arphaman Reviewed By: akyrtzi Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D49476 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337529 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Index/IndexingContext.cpp6
-rw-r--r--test/Index/index-template-specialization.cpp19
-rw-r--r--tools/c-index-test/c-index-test.c2
-rw-r--r--tools/libclang/Indexing.cpp2
4 files changed, 26 insertions, 3 deletions
diff --git a/lib/Index/IndexingContext.cpp b/lib/Index/IndexingContext.cpp
index 6c09ac7c09..80d851b43d 100644
--- a/lib/Index/IndexingContext.cpp
+++ b/lib/Index/IndexingContext.cpp
@@ -350,6 +350,9 @@ bool IndexingContext::handleDeclOccurrence(const Decl *D, SourceLocation Loc,
}
}
+ if (!OrigD)
+ OrigD = D;
+
if (isTemplateImplicitInstantiation(D)) {
if (!IsRef)
return true;
@@ -359,9 +362,6 @@ bool IndexingContext::handleDeclOccurrence(const Decl *D, SourceLocation Loc,
assert(!isTemplateImplicitInstantiation(D));
}
- if (!OrigD)
- OrigD = D;
-
if (IsRef)
Roles |= (unsigned)SymbolRole::Reference;
else if (isDeclADefinition(OrigD, ContainerDC, *Ctx))
diff --git a/test/Index/index-template-specialization.cpp b/test/Index/index-template-specialization.cpp
new file mode 100644
index 0000000000..d11754113c
--- /dev/null
+++ b/test/Index/index-template-specialization.cpp
@@ -0,0 +1,19 @@
+template <typename T>
+class Foo {
+public:
+ void f(T t) {}
+};
+
+void g() {
+ Foo<int> foo;
+ foo.f(0);
+}
+
+// FIXME: if c-index-test uses OrigD for symbol info, refererences below should
+// refer to template specialization decls.
+// RUN: env CINDEXTEST_INDEXIMPLICITTEMPLATEINSTANTIATIONS=1 c-index-test -index-file %s | FileCheck %s
+// CHECK: [indexDeclaration]: kind: c++-class-template | name: Foo
+// CHECK-NEXT: [indexDeclaration]: kind: c++-instance-method | name: f
+// CHECK-NEXT: [indexDeclaration]: kind: function | name: g
+// CHECK-NEXT: [indexEntityReference]: kind: c++-class-template | name: Foo | USR: c:@ST>1#T@Foo
+// CHECK-NEXT: [indexEntityReference]: kind: c++-instance-method | name: f | USR: c:@ST>1#T@Foo@F@f#t0.0#
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index dd1652e32c..70ab11866e 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -3652,6 +3652,8 @@ static unsigned getIndexOptions(void) {
index_opts |= CXIndexOpt_IndexFunctionLocalSymbols;
if (!getenv("CINDEXTEST_DISABLE_SKIPPARSEDBODIES"))
index_opts |= CXIndexOpt_SkipParsedBodiesInSession;
+ if (getenv("CINDEXTEST_INDEXIMPLICITTEMPLATEINSTANTIATIONS"))
+ index_opts |= CXIndexOpt_IndexImplicitTemplateInstantiations;
return index_opts;
}
diff --git a/tools/libclang/Indexing.cpp b/tools/libclang/Indexing.cpp
index 545edfbef4..4da046b282 100644
--- a/tools/libclang/Indexing.cpp
+++ b/tools/libclang/Indexing.cpp
@@ -402,6 +402,8 @@ static IndexingOptions getIndexingOptionsFromCXOptions(unsigned index_options) {
IndexingOptions IdxOpts;
if (index_options & CXIndexOpt_IndexFunctionLocalSymbols)
IdxOpts.IndexFunctionLocals = true;
+ if (index_options & CXIndexOpt_IndexImplicitTemplateInstantiations)
+ IdxOpts.IndexImplicitInstantiation = true;
return IdxOpts;
}