Fixed source range for template implicit instantiations.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141018 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/DeclTemplate.cpp b/lib/AST/DeclTemplate.cpp
index 078869c..558a4cc 100644
--- a/lib/AST/DeclTemplate.cpp
+++ b/lib/AST/DeclTemplate.cpp
@@ -656,15 +656,27 @@
 
 SourceRange
 ClassTemplateSpecializationDecl::getSourceRange() const {
-  if (!ExplicitInfo)
-    return SourceRange();
-  SourceLocation Begin = getExternLoc();
-  if (Begin.isInvalid())
-    Begin = getTemplateKeywordLoc();
-  SourceLocation End = getRBraceLoc();
-  if (End.isInvalid())
-    End = getTypeAsWritten()->getTypeLoc().getEndLoc();
-  return SourceRange(Begin, End);
+  if (ExplicitInfo) {
+    SourceLocation Begin = getExternLoc();
+    if (Begin.isInvalid())
+      Begin = getTemplateKeywordLoc();
+    SourceLocation End = getRBraceLoc();
+    if (End.isInvalid())
+      End = getTypeAsWritten()->getTypeLoc().getEndLoc();
+    return SourceRange(Begin, End);
+  }
+  else {
+    // No explicit info available.
+    llvm::PointerUnion<ClassTemplateDecl *,
+                       ClassTemplatePartialSpecializationDecl *>
+      inst_from = getInstantiatedFrom();
+    if (inst_from.isNull())
+      return getSpecializedTemplate()->getSourceRange();
+    if (ClassTemplateDecl *ctd = inst_from.dyn_cast<ClassTemplateDecl*>())
+      return ctd->getSourceRange();
+    return inst_from.get<ClassTemplatePartialSpecializationDecl*>()
+      ->getSourceRange();
+  }
 }
 
 //===----------------------------------------------------------------------===//