]> granicus.if.org Git - clang/commitdiff
When mangling function template specialization, mangle the type encoding of the origi...
authorAnders Carlsson <andersca@mac.com>
Thu, 17 Sep 2009 03:46:43 +0000 (03:46 +0000)
committerAnders Carlsson <andersca@mac.com>
Thu, 17 Sep 2009 03:46:43 +0000 (03:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82114 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/Mangle.cpp
test/CodeGenCXX/function-template-specialization.cpp
test/CodeGenCXX/mangle.cpp

index 21398677dc6f0a468c99c3e7d95ca3c6bf0d60e2..c0451bfa02c4079f58275c61c15238f5d485763a 100644 (file)
@@ -216,10 +216,15 @@ void CXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD) {
   //   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 @@ void CXXNameMangler::mangleType(const TemplateTypeParmType *T) {
 }
 
 // FIXME: <type> ::= <template-template-param> <template-args>
-// FIXME: <type> ::= <substitution> # See Compression below
 
 // <type> ::= P <type>   # pointer-to
 void CXXNameMangler::mangleType(const PointerType *T) {
index 1efb857192b228c154a113d2e9a6d902b5fd79bf..e189f5dc735a2ff9713831e7b7f5ba29a01f2659 100644 (file)
@@ -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 @@ T* next(T* ptr, const U& diff) {
 
 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 @@ T* next(T* ptr, const U& diff);
 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);
 }
index 1028defefae89faa71cde17649bffeeeaefb266d..a4c223e73fbfb8a9e41f85ad1597b21b00dba280 100644 (file)
@@ -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);
+}