[cfe-commits] r82882 - in /cfe/trunk: lib/CodeGen/Mangle.cpp test/CodeGenCXX/mangle-subst-std.cpp

Anders Carlsson andersca at mac.com
Sat Sep 26 17:12:57 PDT 2009


Author: andersca
Date: Sat Sep 26 19:12:57 2009
New Revision: 82882

URL: http://llvm.org/viewvc/llvm-project?rev=82882&view=rev
Log:
Mangle std::basic_string<char, std::char_traits<char>, std::allocator<char> > as Ss.

Modified:
    cfe/trunk/lib/CodeGen/Mangle.cpp
    cfe/trunk/test/CodeGenCXX/mangle-subst-std.cpp

Modified: cfe/trunk/lib/CodeGen/Mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mangle.cpp?rev=82882&r1=82881&r2=82882&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.cpp (original)
+++ cfe/trunk/lib/CodeGen/Mangle.cpp Sat Sep 26 19:12:57 2009
@@ -1130,6 +1130,45 @@
   return true;
 }
 
+static bool isCharType(QualType T) {
+  if (T.isNull())
+    return false;
+      
+  return T->isSpecificBuiltinType(BuiltinType::Char_S) ||
+    T->isSpecificBuiltinType(BuiltinType::Char_U);
+}
+
+/// isCharSpecialization - Returns whether a given type is a template 
+/// specialization of a given name with a single argument of type char.
+static bool isCharSpecialization(QualType T, const char *Name) {
+  if (T.isNull())
+    return false;
+  
+  const RecordType *RT = T->getAs<RecordType>();
+  if (!RT)
+    return false;
+  
+  const ClassTemplateSpecializationDecl *SD = 
+    dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl());
+  if (!SD)
+    return false;
+
+  if (!isStdNamespace(SD->getDeclContext()))
+    return false;
+  
+  const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs();
+  if (TemplateArgs.size() != 1)
+    return false;
+  
+  if (!isCharType(TemplateArgs[0].getAsType()))
+    return false;
+  
+  if (strcmp(SD->getIdentifier()->getName(), Name) != 0)
+    return false;
+
+  return true;
+}
+
 bool CXXNameMangler::mangleStandardSubstitution(const NamedDecl *ND) {
   // <substitution> ::= St # ::std::
   if (const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
@@ -1157,6 +1196,30 @@
     }
   }
   
+  if (const ClassTemplateSpecializationDecl *SD = 
+        dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
+    //    <substitution> ::= Ss # ::std::basic_string<char,
+    //                            ::std::char_traits<char>,
+    //                            ::std::allocator<char> >
+    if (SD->getIdentifier()->isStr("basic_string")) {
+      const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs();
+      
+      if (TemplateArgs.size() != 3)
+        return false;
+      
+      if (!isCharType(TemplateArgs[0].getAsType()))
+        return false;
+      
+      if (!isCharSpecialization(TemplateArgs[1].getAsType(), "char_traits"))
+        return false;
+      
+      if (!isCharSpecialization(TemplateArgs[2].getAsType(), "allocator"))
+        return false;
+
+      Out << "Ss";
+      return true;
+    }
+  }
   return false;
 }
 

Modified: cfe/trunk/test/CodeGenCXX/mangle-subst-std.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-subst-std.cpp?rev=82882&r1=82881&r2=82882&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle-subst-std.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-subst-std.cpp Sat Sep 26 19:12:57 2009
@@ -18,10 +18,19 @@
 void f(typename std::allocator<char>, typename std::allocator<int>) { }
 
 namespace std {
-  template<typename T> struct basic_string { };
+  template<typename T, typename U, typename V> struct basic_string { };
 }
 
 // FIXME: typename is really not allowed here, but it's kept 
 // as a workaround for PR5061.
-// CHECK: define void @_Z1fSbIcESbIiE
-void f(typename std::basic_string<char>, typename std::basic_string<int>) { }
+// CHECK: define void @_Z1fSbIcciE
+void f(typename std::basic_string<char, char, int>) { }
+
+namespace std {
+  template<typename T> struct char_traits { };
+  
+  typedef std::basic_string<char, std::char_traits<char>, std::allocator<char> > string;
+}
+
+// CHECK: _Z1fSs
+void f(std::string) { }





More information about the cfe-commits mailing list