blob: d952f314397dd87572488b7304e602e41ac39144 [file] [log] [blame]
Anders Carlsson9234b7f2009-09-17 03:46:43 +00001// RUN: clang-cc -emit-llvm %s -o - -triple=x86_64-apple-darwin9 | FileCheck %s
Douglas Gregor5f2bfd42009-02-13 00:10:09 +00002
Douglas Gregor5f2bfd42009-02-13 00:10:09 +00003struct X { };
4struct Y { };
Anders Carlssonb1d947b2009-03-07 23:57:03 +00005
Anders Carlsson9234b7f2009-09-17 03:46:43 +00006// CHECK: @unmangled_variable = global
7// CHECK: @_ZN1N1iE = global
8// CHECK: @_ZZN1N1fEiiE1b = internal global
9// CHECK: @_ZZN1N1gEvE1a = internal global
10// CHECK: @_ZGVZN1N1gEvE1a = internal global
11
12// CHECK: define zeroext i1 @_ZplRK1YRA100_P1X
Douglas Gregor5f2bfd42009-02-13 00:10:09 +000013bool operator+(const Y&, X* (&xs)[100]) { return false; }
14
Anders Carlsson9234b7f2009-09-17 03:46:43 +000015// CHECK: define void @_Z1f1s
Anders Carlssonb1d947b2009-03-07 23:57:03 +000016typedef struct { int a; } s;
17void f(s) { }
18
Anders Carlsson9234b7f2009-09-17 03:46:43 +000019// CHECK: define void @_Z1f1e
Anders Carlssonb1d947b2009-03-07 23:57:03 +000020typedef enum { foo } e;
21void f(e) { }
22
Anders Carlsson9234b7f2009-09-17 03:46:43 +000023// CHECK: define void @_Z1f1u
Anders Carlssonb1d947b2009-03-07 23:57:03 +000024typedef union { int a; } u;
25void f(u) { }
Anders Carlsson4843e582009-03-10 17:07:44 +000026
Anders Carlsson9234b7f2009-09-17 03:46:43 +000027// CHECK: define void @_Z1f1x
Anders Carlsson4843e582009-03-10 17:07:44 +000028typedef struct { int a; } x,y;
29void f(y) { }
30
Anders Carlsson9234b7f2009-09-17 03:46:43 +000031// CHECK: define void @_Z1fv
Anders Carlssonc6c91bc2009-04-01 00:15:23 +000032void f() { }
Anders Carlsson984e0682009-04-01 00:58:25 +000033
Anders Carlsson9234b7f2009-09-17 03:46:43 +000034// CHECK: define void @_ZN1N1fEv
Anders Carlsson984e0682009-04-01 00:58:25 +000035namespace N { void f() { } }
36
Anders Carlsson9234b7f2009-09-17 03:46:43 +000037// CHECK: define void @_ZN1N1N1fEv
Anders Carlsson984e0682009-04-01 00:58:25 +000038namespace N { namespace N { void f() { } } }
Anders Carlsson91e20dd2009-04-02 05:55:18 +000039
Anders Carlsson9234b7f2009-09-17 03:46:43 +000040// CHECK: define void @unmangled_function
Anders Carlsson91e20dd2009-04-02 05:55:18 +000041extern "C" { namespace N { void unmangled_function() { } } }
42
Anders Carlsson2928c212009-05-16 21:02:39 +000043extern "C" { namespace N { int unmangled_variable = 10; } }
Anders Carlsson91e20dd2009-04-02 05:55:18 +000044
Anders Carlsson329749c2009-04-02 16:05:20 +000045namespace N { int i; }
Anders Carlsson1b42c792009-04-02 16:24:45 +000046
Anders Carlsson1b42c792009-04-02 16:24:45 +000047namespace N { int f(int, int) { static int b; return b; } }
Anders Carlsson283a0622009-04-13 18:03:33 +000048
Anders Carlsson283a0622009-04-13 18:03:33 +000049namespace N { int h(); void g() { static int a = h(); } }
Chris Lattner2df9ced2009-04-30 02:43:43 +000050
Anders Carlsson9234b7f2009-09-17 03:46:43 +000051// CHECK: define void @_Z1fno
Chris Lattner2df9ced2009-04-30 02:43:43 +000052void f(__int128_t, __uint128_t) { }
Anders Carlsson7a0ba872009-05-15 16:09:15 +000053
54template <typename T> struct S1 {};
55
Anders Carlsson9234b7f2009-09-17 03:46:43 +000056// CHECK: define void @_Z1f2S1IiE
Anders Carlsson7a0ba872009-05-15 16:09:15 +000057void f(S1<int>) {}
58
Anders Carlsson9234b7f2009-09-17 03:46:43 +000059// CHECK: define void @_Z1f2S1IdE
Anders Carlsson7a0ba872009-05-15 16:09:15 +000060void f(S1<double>) {}
61
62template <int N> struct S2 {};
Anders Carlsson9234b7f2009-09-17 03:46:43 +000063// CHECK: define void @_Z1f2S2ILi100EE
Anders Carlsson7a0ba872009-05-15 16:09:15 +000064void f(S2<100>) {}
65
Anders Carlsson9234b7f2009-09-17 03:46:43 +000066// CHECK: define void @_Z1f2S2ILin100EE
Anders Carlsson7a0ba872009-05-15 16:09:15 +000067void f(S2<-100>) {}
68
69template <bool B> struct S3 {};
70
Anders Carlsson9234b7f2009-09-17 03:46:43 +000071// CHECK: define void @_Z1f2S3ILb1EE
Anders Carlsson7a0ba872009-05-15 16:09:15 +000072void f(S3<true>) {}
73
Anders Carlsson9234b7f2009-09-17 03:46:43 +000074// CHECK: define void @_Z1f2S3ILb0EE
Anders Carlsson7a0ba872009-05-15 16:09:15 +000075void f(S3<false>) {}
76
Anders Carlsson9234b7f2009-09-17 03:46:43 +000077// CHECK: define void @_Z2f22S3ILb1EE
Anders Carlsson7a0ba872009-05-15 16:09:15 +000078void f2(S3<100>) {}
Anders Carlsson0e650012009-05-17 17:41:20 +000079
80struct S;
81
Anders Carlsson9234b7f2009-09-17 03:46:43 +000082// CHECK: define void @_Z1fM1SKFvvE
Anders Carlsson0e650012009-05-17 17:41:20 +000083void f(void (S::*)() const) {}
84
Anders Carlsson9234b7f2009-09-17 03:46:43 +000085// CHECK: define void @_Z1fM1SFvvE
Anders Carlsson0e650012009-05-17 17:41:20 +000086void f(void (S::*)()) {}
Anders Carlssoncf85b932009-09-16 23:53:19 +000087
Anders Carlsson9234b7f2009-09-17 03:46:43 +000088// CHECK: define void @_Z1fi
Anders Carlssoncf85b932009-09-16 23:53:19 +000089void f(const int) { }
90
Anders Carlsson03c9d532009-09-17 04:02:31 +000091template<typename T, typename U> void ft1(U u, T t) { }
92
93template<typename T> void ft2(T t, void (*)(T), void (*)(T)) { }
Anders Carlsson9234b7f2009-09-17 03:46:43 +000094
Anders Carlsson7624f212009-09-18 02:42:01 +000095template<typename T, typename U = S1<T> > struct S4 { };
96template<typename T> void ft3(S4<T>*) { }
97
Anders Carlsson7482e242009-09-18 04:29:09 +000098namespace NS {
99 template<typename T> void ft1(T) { }
Anders Carlsson7624f212009-09-18 02:42:01 +0000100}
101
Anders Carlssond553f8c2009-09-21 01:21:10 +0000102void g1() {
Anders Carlsson03c9d532009-09-17 04:02:31 +0000103 // CHECK: @_Z3ft1IidEvT0_T_
104 ft1<int, double>(1, 0);
105
106 // CHECK: @_Z3ft2IcEvT_PFvS0_ES2_
107 ft2<char>(1, 0, 0);
Anders Carlsson7624f212009-09-18 02:42:01 +0000108
109 // CHECK: @_Z3ft3IiEvP2S4IT_2S1IS1_EE
110 ft3<int>(0);
Anders Carlsson7482e242009-09-18 04:29:09 +0000111
112 // CHECK: @_ZN2NS3ft1IiEEvT_
113 NS::ft1<int>(1);
Anders Carlssond58d6f72009-09-17 16:12:20 +0000114}
Anders Carlsson7482e242009-09-18 04:29:09 +0000115
Anders Carlssond553f8c2009-09-21 01:21:10 +0000116// Expressions
117template<int I> struct S5 { };
118
119template<int I> void ft4(S5<I>) { }
120void g2() {
121 // CHECK: @_Z3ft4ILi10EEv2S5IXT_EE
122 ft4(S5<10>());
123
124 // CHECK: @_Z3ft4ILi20EEv2S5IXT_EE
125 ft4(S5<20>());
126}
127
Anders Carlsson7482e242009-09-18 04:29:09 +0000128extern "C++" {
129 // CHECK: @_Z1hv
130 void h() { }
131}
132