Substitution for prefixes.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82122 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/Mangle.cpp b/lib/CodeGen/Mangle.cpp
index 9b5fd74..8241ad6 100644
--- a/lib/CodeGen/Mangle.cpp
+++ b/lib/CodeGen/Mangle.cpp
@@ -55,9 +55,7 @@
     void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type);
 
   private:
-    bool mangleSubstitution(const NamedDecl *ND) {
-      return mangleSubstitution(reinterpret_cast<uintptr_t>(ND));
-    }
+    bool mangleSubstitution(const NamedDecl *ND);
     bool mangleSubstitution(QualType T);
     bool mangleSubstitution(uintptr_t Ptr);
     
@@ -432,6 +430,10 @@
   //           ::= # empty
   //           ::= <substitution>
   // FIXME: We only handle mangling of namespaces and classes at the moment.
+
+  if (mangleSubstitution(cast<NamedDecl>(DC)))
+    return;
+  
   if (!DC->getParent()->isTranslationUnit())
     manglePrefix(DC->getParent());
 
@@ -444,6 +446,8 @@
     } else
       mangleSourceName(Record->getIdentifier());
   }
+  
+  addSubstitution(cast<NamedDecl>(DC));
 }
 
 void
@@ -922,6 +926,11 @@
 
 // <substitution> ::= S <seq-id> _
 //                ::= S_
+
+bool CXXNameMangler::mangleSubstitution(const NamedDecl *ND) {
+  return mangleSubstitution(reinterpret_cast<uintptr_t>(ND));
+}
+
 bool CXXNameMangler::mangleSubstitution(QualType T) {
   uintptr_t TypePtr = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr());