]> granicus.if.org Git - clang/commitdiff
Substitute "::std::" as "St".
authorAnders Carlsson <andersca@mac.com>
Sat, 26 Sep 2009 20:53:44 +0000 (20:53 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 26 Sep 2009 20:53:44 +0000 (20:53 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82874 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/Mangle.cpp
test/CodeGenCXX/mangle-subst-std.cpp [new file with mode: 0644]

index e07c38fd11b70dacddb6665e2cdd6f2bce5e57e7..c07d9039c014d9fd1609dce76f52467d3cf77280 100644 (file)
@@ -59,6 +59,8 @@ namespace {
     bool mangleSubstitution(QualType T);
     bool mangleSubstitution(uintptr_t Ptr);
     
+    bool mangleStandardSubstitution(const NamedDecl *ND);
+    
     void addSubstitution(const NamedDecl *ND) {
       addSubstitution(reinterpret_cast<uintptr_t>(ND));
     }
@@ -1070,8 +1072,11 @@ void CXXNameMangler::mangleTemplateArgument(const TemplateArgument &A) {
 
 // <substitution> ::= S <seq-id> _
 //                ::= S_
-
 bool CXXNameMangler::mangleSubstitution(const NamedDecl *ND) {
+  // Try one of the standard substitutions first.
+  if (mangleStandardSubstitution(ND))
+    return true;
+  
   return mangleSubstitution(reinterpret_cast<uintptr_t>(ND));
 }
 
@@ -1120,6 +1125,22 @@ bool CXXNameMangler::mangleSubstitution(uintptr_t Ptr) {
   return true;
 }
 
+bool CXXNameMangler::mangleStandardSubstitution(const NamedDecl *ND) {
+  // <substitution> ::= St # ::std::
+  
+  const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND);
+  if (!NS)
+    return false;
+  if (!NS->getParent()->isTranslationUnit())
+    return false;
+  
+  if (!NS->getOriginalNamespace()->getIdentifier()->isStr("std"))
+    return false;
+  
+  Out << "St";
+  return true;
+}
+
 void CXXNameMangler::addSubstitution(QualType T) {
   if (!T.getCVRQualifiers()) {
     if (const RecordType *RT = T->getAs<RecordType>()) {
diff --git a/test/CodeGenCXX/mangle-subst-std.cpp b/test/CodeGenCXX/mangle-subst-std.cpp
new file mode 100644 (file)
index 0000000..a5ba3ab
--- /dev/null
@@ -0,0 +1,9 @@
+// RUN: clang-cc -emit-llvm %s -o - -triple=x86_64-apple-darwin9 | FileCheck %s
+
+namespace std {
+  struct A { A(); };
+  
+  // CHECK: define void @_ZNSt1AC1Ev
+  // CHECK: define void @_ZNSt1AC2Ev
+  A::A() { }
+};