Improve name mangling for dependently-scoped declaration references.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97422 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/Mangle.cpp b/lib/CodeGen/Mangle.cpp
index 55185cb..fd9a1ba 100644
--- a/lib/CodeGen/Mangle.cpp
+++ b/lib/CodeGen/Mangle.cpp
@@ -1369,7 +1369,18 @@
 
   case Expr::DependentScopeDeclRefExprClass: {
     const DependentScopeDeclRefExpr *DRE = cast<DependentScopeDeclRefExpr>(E);
-    const Type *QTy = DRE->getQualifier()->getAsType();
+    NestedNameSpecifier *NNS = DRE->getQualifier();
+    const Type *QTy = NNS->getAsType();
+
+    // When we're dealing with a nested-name-specifier that has just a
+    // dependent identifier in it, mangle that as a typename.  FIXME:
+    // It isn't clear that we ever actually want to have such a
+    // nested-name-specifier; why not just represent it as a typename type?
+    if (!QTy && NNS->getAsIdentifier() && NNS->getPrefix()) {
+      QTy = getASTContext().getTypenameType(NNS->getPrefix(),
+                                            NNS->getAsIdentifier())
+              .getTypePtr();
+    }
     assert(QTy && "Qualifier was not type!");
 
     // ::= sr <type> <unqualified-name>                   # dependent name