Author: arphaman
Date: Tue May 23 11:23:28 2017
New Revision: 303646

URL: http://llvm.org/viewvc/llvm-project?rev=303646&view=rev
Log:
[index] The references to records from template instantiations should refer
to the pattern records in the base templates

rdar://32325459

Modified:
    cfe/trunk/lib/Index/IndexingContext.cpp
    cfe/trunk/test/Index/Core/index-instantiated-source.cpp

Modified: cfe/trunk/lib/Index/IndexingContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingContext.cpp?rev=303646&r1=303645&r2=303646&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexingContext.cpp (original)
+++ cfe/trunk/lib/Index/IndexingContext.cpp Tue May 23 11:23:28 2017
@@ -124,6 +124,9 @@ bool IndexingContext::isTemplateImplicit
     TKind = FD->getTemplateSpecializationKind();
   } else if (auto *VD = dyn_cast<VarDecl>(D)) {
     TKind = VD->getTemplateSpecializationKind();
+  } else if (const auto *RD = dyn_cast<CXXRecordDecl>(D)) {
+    if (RD->getInstantiatedFromMemberClass())
+      TKind = RD->getTemplateSpecializationKind();
   } else if (isa<FieldDecl>(D)) {
     if (const auto *Parent =
             dyn_cast<ClassTemplateSpecializationDecl>(D->getDeclContext()))
@@ -163,6 +166,8 @@ static const Decl *adjustTemplateImplici
     return FD->getTemplateInstantiationPattern();
   } else if (auto *VD = dyn_cast<VarDecl>(D)) {
     return VD->getTemplateInstantiationPattern();
+  } else if (const auto *RD = dyn_cast<CXXRecordDecl>(D)) {
+    return RD->getInstantiatedFromMemberClass();
   } else if (const auto *FD = dyn_cast<FieldDecl>(D)) {
     if (const auto *Parent =
             dyn_cast<ClassTemplateSpecializationDecl>(D->getDeclContext())) {

Modified: cfe/trunk/test/Index/Core/index-instantiated-source.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-instantiated-source.cpp?rev=303646&r1=303645&r2=303646&view=diff
==============================================================================
--- cfe/trunk/test/Index/Core/index-instantiated-source.cpp (original)
+++ cfe/trunk/test/Index/Core/index-instantiated-source.cpp Tue May 23 11:23:28 
2017
@@ -9,6 +9,9 @@ public:
 
   T baseTemplateField;
 // CHECK: [[@LINE-1]]:5 | field/C++ | baseTemplateField | 
c:@ST>1#T@BaseTemplate@FI@baseTemplateField
+
+  struct NestedBaseType { };
+// CHECK: [[@LINE-1]]:10 | struct/C | NestedBaseType | 
c:@ST>1#T@BaseTemplate@S@NestedBaseType |
 };
 
 template<typename T, typename S>
@@ -22,6 +25,15 @@ public:
 
   T field;
 // CHECK: [[@LINE-1]]:5 | field/C++ | field | 
c:@ST>2#T#T@TemplateClass@FI@field
+
+  struct NestedType {
+// CHECK: [[@LINE-1]]:10 | struct/C++ | NestedType | 
c:@ST>2#T#T@TemplateClass@S@NestedType |
+    class SubNestedType {
+// CHECK: [[@LINE-1]]:11 | class/C++ | SubNestedType | 
c:@ST>2#T#T@TemplateClass@S@NestedType@S@SubNestedType |
+    public:
+      SubNestedType(int);
+    };
+  };
 };
 
 void canonicalizeInstaniationReferences(TemplateClass<int, float> &object) {
@@ -36,4 +48,13 @@ void canonicalizeInstaniationReferences(
 
   TemplateClass<int, float>::staticFunction();
 // CHECK: [[@LINE-1]]:30 | static-method/C++ | staticFunction | 
c:@ST>2#T#T@TemplateClass@F@staticFunction#S | <no-cgname
+
+  TemplateClass<int, float>::NestedBaseType nestedBaseType;
+// CHECK: [[@LINE-1]]:30 | struct/C | NestedBaseType | 
c:@ST>1#T@BaseTemplate@S@NestedBaseType |
+  TemplateClass<int, float>::NestedType nestedSubType;
+// CHECK: [[@LINE-1]]:30 | struct/C++ | NestedType | 
c:@ST>2#T#T@TemplateClass@S@NestedType |
+  typedef TemplateClass<int, float> TT;
+  TT::NestedType::SubNestedType subNestedType(0);
+// CHECK: [[@LINE-1]]:7 | struct/C++ | NestedType | 
c:@ST>2#T#T@TemplateClass@S@NestedType |
+// CHECK: [[@LINE-2]]:19 | class/C++ | SubNestedType | 
c:@ST>2#T#T@TemplateClass@S@NestedType@S@SubNestedType |
 }


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to