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

Anders Carlsson andersca at mac.com
Sat Mar 7 15:57:04 PST 2009


Author: andersca
Date: Sat Mar  7 17:57:03 2009
New Revision: 66353

URL: http://llvm.org/viewvc/llvm-project?rev=66353&view=rev
Log:
Make mangling work with anonymous tag types. Doug, please review

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

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

==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.cpp (original)
+++ cfe/trunk/lib/CodeGen/Mangle.cpp Sat Mar  7 17:57:03 2009
@@ -43,6 +43,7 @@
     void mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity);
     void mangleCVQualifiers(unsigned Quals);
     void mangleType(QualType T);
+    void mangleType(const TypedefType *T);
     void mangleType(const BuiltinType *T);
     void mangleType(const FunctionType *T);
     void mangleBareFunctionType(const FunctionType *T, bool MangleReturnType);
@@ -329,16 +330,15 @@
 }
 
 void CXXNameMangler::mangleType(QualType T) {
-  // Only operate on the canonical type!
-  T = Context.getCanonicalType(T);
-
   // FIXME: Should we have a TypeNodes.def to make this easier? (YES!)
 
   //  <type> ::= <CV-qualifiers> <type>
   mangleCVQualifiers(T.getCVRQualifiers());
 
+  if (const TypedefType *TT = dyn_cast<TypedefType>(T.getTypePtr()))
+    mangleType(TT);
   //         ::= <builtin-type>
-  if (const BuiltinType *BT = dyn_cast<BuiltinType>(T.getTypePtr()))
+  else if (const BuiltinType *BT = dyn_cast<BuiltinType>(T.getTypePtr()))
     mangleType(BT);
   //         ::= <function-type>
   else if (const FunctionType *FT = dyn_cast<FunctionType>(T.getTypePtr()))
@@ -382,13 +382,27 @@
   } else if (const ObjCInterfaceType *IT = 
              dyn_cast<ObjCInterfaceType>(T.getTypePtr())) {
     mangleType(IT);
-  }
+  } 
   // FIXME:  ::= G <type>   # imaginary (C 2000)
   // FIXME:  ::= U <source-name> <type>     # vendor extended type qualifier
   else
     assert(false && "Cannot mangle unknown type");
 }
 
+void CXXNameMangler::mangleType(const TypedefType *T) {
+  QualType DeclTy = T->getDecl()->getUnderlyingType();
+  
+  if (const TagType *TT = dyn_cast<TagType>(DeclTy)) {
+    // If the tag type is anonymous, use the name of the typedef.
+    if (!TT->getDecl()->getIdentifier()) {
+      mangleName(T->getDecl());
+      return;
+    }
+  }
+  
+  mangleType(DeclTy);
+}
+
 void CXXNameMangler::mangleType(const BuiltinType *T) {
   //  <builtin-type> ::= v  # void
   //                 ::= w  # wchar_t

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

==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle.cpp Sat Mar  7 17:57:03 2009
@@ -1,9 +1,21 @@
-// RUN: clang -emit-llvm %s -o - | grep _ZplRK1YRA100_P1X
+// RUN: clang -emit-llvm %s -o %t &&
 
 // FIXME: This test is intentionally trivial, because we can't yet
 // CodeGen anything real in C++.
 struct X { };
 struct Y { };
-  
+
+// RUN: grep _ZplRK1YRA100_P1X %t | count 1 &&
 bool operator+(const Y&, X* (&xs)[100]) { return false; }
 
+// RUN: grep _Z1f1s %t | count 1 &&
+typedef struct { int a; } s;
+void f(s) { }
+
+// RUN: grep _Z1f1e %t| count 1 &&
+typedef enum { foo } e;
+void f(e) { }
+
+// RUN: grep _Z1f1u %t | count 1
+typedef union { int a; } u;
+void f(u) { }





More information about the cfe-commits mailing list