diff options
author | Anders Carlsson <andersca@mac.com> | 2009-09-17 03:46:43 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-09-17 03:46:43 +0000 |
commit | 9234b7ff2bb99479fb97d5faa181a55aacf28b78 (patch) | |
tree | 5efde134d40ce5556a75ebea645ca4cdcef22331 | |
parent | 201ce7485c3401adad861fd0979f1bfefc064ff7 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82114 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/Mangle.cpp | 14 | ||||
-rw-r--r-- | test/CodeGenCXX/function-template-specialization.cpp | 9 | ||||
-rw-r--r-- | test/CodeGenCXX/mangle.cpp | 62 |
3 files changed, 47 insertions, 38 deletions
diff --git a/lib/CodeGen/Mangle.cpp b/lib/CodeGen/Mangle.cpp index 21398677dc..c0451bfa02 100644 --- a/lib/CodeGen/Mangle.cpp +++ b/lib/CodeGen/Mangle.cpp @@ -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) { diff --git a/test/CodeGenCXX/function-template-specialization.cpp b/test/CodeGenCXX/function-template-specialization.cpp index 1efb857192..e189f5dc73 100644 --- a/test/CodeGenCXX/function-template-specialization.cpp +++ b/test/CodeGenCXX/function-template-specialization.cpp @@ -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); } diff --git a/test/CodeGenCXX/mangle.cpp b/test/CodeGenCXX/mangle.cpp index 1028defefa..a4c223e73f 100644 --- a/test/CodeGenCXX/mangle.cpp +++ b/test/CodeGenCXX/mangle.cpp @@ -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); +} |