[cfe-commits] r82114 - in /cfe/trunk: lib/CodeGen/Mangle.cpp test/CodeGenCXX/function-template-specialization.cpp test/CodeGenCXX/mangle.cpp

Anders Carlsson andersca at mac.com
Wed Sep 16 20:46:47 PDT 2009


Author: andersca
Date: Wed Sep 16 22:46:43 2009
New Revision: 82114

URL: http://llvm.org/viewvc/llvm-project?rev=82114&view=rev
Log:
When mangling function template specialization, mangle the type encoding of the original function template. Also, port mangle.cpp and function-template-specialization.cpp over to using FileCheck.

Modified:
    cfe/trunk/lib/CodeGen/Mangle.cpp
    cfe/trunk/test/CodeGenCXX/function-template-specialization.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=82114&r1=82113&r2=82114&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.cpp (original)
+++ cfe/trunk/lib/CodeGen/Mangle.cpp Wed Sep 16 22:46:43 2009
@@ -216,10 +216,15 @@
   //   2. Destructors.
   //   3. Conversion operator functions, e.g. operator int.
   bool MangleReturnType = false;
-  if (FD->getPrimaryTemplate() &&
-      !(isa<CXXConstructorDecl>(FD) || isa<CXXDestructorDecl>(FD) ||
-        isa<CXXConversionDecl>(FD)))
-    MangleReturnType = true;
+  if (FunctionTemplateDecl *PrimaryTemplate = FD->getPrimaryTemplate()) {
+    if (!(isa<CXXConstructorDecl>(FD) || isa<CXXDestructorDecl>(FD) ||
+          isa<CXXConversionDecl>(FD)))
+      MangleReturnType = true;
+    
+    // Mangle the type of the primary template.
+    FD = PrimaryTemplate->getTemplatedDecl();
+  }
+
   mangleBareFunctionType(FD->getType()->getAsFunctionType(), MangleReturnType);
 }
 
@@ -744,7 +749,6 @@
 }
 
 // FIXME: <type> ::= <template-template-param> <template-args>
-// FIXME: <type> ::= <substitution> # See Compression below
 
 // <type> ::= P <type>   # pointer-to
 void CXXNameMangler::mangleType(const PointerType *T) {

Modified: cfe/trunk/test/CodeGenCXX/function-template-specialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/function-template-specialization.cpp?rev=82114&r1=82113&r2=82114&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/function-template-specialization.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/function-template-specialization.cpp Wed Sep 16 22:46:43 2009
@@ -1,4 +1,4 @@
-// RUN: clang-cc -emit-llvm %s -o %t &&
+// RUN: clang-cc -emit-llvm %s -o %t && FileCheck %s --input-file=%t
 template<typename T, typename U>
 T* next(T* ptr, const U& diff);
 
@@ -9,10 +9,11 @@
 
 void test(int *iptr, float *fptr, int diff) {
   // FIXME: should be "_Z4nextIiiEPT_S1_RKT0_"
-  // RUN: grep "_Z4nextIiiEPiS_RKi" %t &&
+  // CHECK: _Z4nextIiiEPT_S0_RKT0_
   iptr = next(iptr, diff);
   // FIXME: should be "_Z4nextIfiEPT_S1_RKT0_"
-  // RUN: grep "_Z4nextIfiEPfS_RKi" %t &&
+  // CHECK: _Z4nextIfiEPT_S0_RKT0_
+  
   fptr = next(fptr, diff);
 }
 
@@ -22,6 +23,6 @@
 void test2(int *iptr, double *dptr, int diff) {
   iptr = next(iptr, diff);
   // FIXME: should be "_Z4nextIdiEPT_S1_RKT0_"
-  // RUN: grep "_Z4nextIdiEPdS_RKi" %t
+  // RUN: grep "_Z4nextIiiEPT_S0_RKT0_" %t
   dptr = next(dptr, diff);
 }

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

==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle.cpp Wed Sep 16 22:46:43 2009
@@ -1,92 +1,96 @@
-// RUN: clang-cc -emit-llvm %s -o %t -triple=x86_64-apple-darwin9 && 
+// RUN: clang-cc -emit-llvm %s -o - -triple=x86_64-apple-darwin9 | FileCheck %s
 
-// 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 &&
+// CHECK: @unmangled_variable = global
+// CHECK: @_ZN1N1iE = global
+// CHECK: @_ZZN1N1fEiiE1b = internal global
+// CHECK: @_ZZN1N1gEvE1a = internal global
+// CHECK: @_ZGVZN1N1gEvE1a = internal global
+
+// CHECK: define zeroext i1 @_ZplRK1YRA100_P1X
 bool operator+(const Y&, X* (&xs)[100]) { return false; }
 
-// RUN: grep _Z1f1s %t | count 1 &&
+// CHECK: define void @_Z1f1s
 typedef struct { int a; } s;
 void f(s) { }
 
-// RUN: grep _Z1f1e %t| count 1 &&
+// CHECK: define void @_Z1f1e
 typedef enum { foo } e;
 void f(e) { }
 
-// RUN: grep _Z1f1u %t | count 1 &&
+// CHECK: define void @_Z1f1u
 typedef union { int a; } u;
 void f(u) { }
 
-// RUN: grep _Z1f1x %t | count 1 &&
+// CHECK: define void @_Z1f1x
 typedef struct { int a; } x,y;
 void f(y) { }
 
-// RUN: grep _Z1fv %t | count 1 &&
+// CHECK: define void @_Z1fv
 void f() { }
 
-// RUN: grep _ZN1N1fEv %t | count 1 &&
+// CHECK: define void @_ZN1N1fEv
 namespace N { void f() { } }
 
-// RUN: grep _ZN1N1N1fEv %t | count 1 &&
+// CHECK: define void @_ZN1N1N1fEv
 namespace N { namespace N { void f() { } } }
 
-// RUN: grep unmangled_function %t | count 1 &&
+// CHECK: define void @unmangled_function
 extern "C" { namespace N { void unmangled_function() { } } }
 
-// RUN: grep unmangled_variable %t | count 1 &&
 extern "C" { namespace N { int unmangled_variable = 10; } }
 
-// RUN: grep _ZN1N1iE %t | count 1 &&
 namespace N { int i; }
 
-// RUN: grep _ZZN1N1fEiiE1b %t | count 2 &&
 namespace N { int f(int, int) { static int b; return b; } }
 
-// RUN: grep "_ZZN1N1gEvE1a =" %t | count 1 &&
-// RUN: grep "_ZGVZN1N1gEvE1a =" %t | count 1 &&
 namespace N { int h(); void g() { static int a = h(); } }
 
-// RUN: grep "_Z1fno" %t | count 1 &&
+// CHECK: define void @_Z1fno
 void f(__int128_t, __uint128_t) { } 
 
 template <typename T> struct S1 {};
 
-// RUN: grep "_Z1f2S1IiE" %t | count 1 &&
+// CHECK: define void @_Z1f2S1IiE
 void f(S1<int>) {}
 
-// RUN: grep "_Z1f2S1IdE" %t | count 1 &&
+// CHECK: define void @_Z1f2S1IdE
 void f(S1<double>) {}
 
 template <int N> struct S2 {};
-// RUN: grep "_Z1f2S2ILi100EE" %t | count 1 &&
+// CHECK: define void @_Z1f2S2ILi100EE
 void f(S2<100>) {}
 
-// RUN: grep "_Z1f2S2ILin100EE" %t | count 1 &&
+// CHECK: define void @_Z1f2S2ILin100EE
 void f(S2<-100>) {}
 
 template <bool B> struct S3 {};
 
-// RUN: grep "_Z1f2S3ILb1EE" %t | count 1 &&
+// CHECK: define void @_Z1f2S3ILb1EE
 void f(S3<true>) {}
 
-// RUN: grep "_Z1f2S3ILb0EE" %t | count 1 &&
+// CHECK: define void @_Z1f2S3ILb0EE
 void f(S3<false>) {}
 
-// RUN: grep "_Z2f22S3ILb1EE" %t | count 1 &&
+// CHECK: define void @_Z2f22S3ILb1EE
 void f2(S3<100>) {}
 
 struct S;
 
-// RUN: grep "_Z1fM1SKFvvE" %t | count 1 &&
+// CHECK: define void @_Z1fM1SKFvvE
 void f(void (S::*)() const) {}
 
-// RUN: grep "_Z1fM1SFvvE" %t | count 1 &&
+// CHECK: define void @_Z1fM1SFvvE
 void f(void (S::*)()) {}
 
-// RUN: grep "_Z1fi" %t | count 1 &&
+// CHECK: define void @_Z1fi
 void f(const int) { }
 
-// RUN: true
+// CHECK: define linkonce_odr void @_Z2tfIidEvT0_T_
+template<typename T, typename U> void tf(U u, T t) { }
+
+void g() {
+  tf<int, double>(1, 0);
+}





More information about the cfe-commits mailing list