1 // RUN: %clang_cc1 -std=c++98 -triple x86_64-linux-gnu -fenable-matrix -fclang-abi-compat=3.0 %s -emit-llvm -o - -Wno-c++11-extensions \
2 // RUN:     | FileCheck --check-prefixes=CHECK,PRE39,PRE5,PRE12 %s
3 // RUN: %clang_cc1 -std=c++17 -triple x86_64-linux-gnu -fenable-matrix -fclang-abi-compat=3.0 %s -emit-llvm -o - \
4 // RUN:     | FileCheck --check-prefixes=CHECK,PRE39,PRE5,PRE12 %s
5 // RUN: %clang_cc1 -std=c++17 -triple x86_64-linux-gnu -fenable-matrix -fclang-abi-compat=3.8 %s -emit-llvm -o - \
6 // RUN:     | FileCheck --check-prefixes=CHECK,PRE39,PRE5,PRE12 %s
7 // RUN: %clang_cc1 -std=c++17 -triple x86_64-linux-gnu -fenable-matrix -fclang-abi-compat=3.9 %s -emit-llvm -o - \
8 // RUN:     | FileCheck --check-prefixes=CHECK,V39,PRE5,PRE12 %s
9 // RUN: %clang_cc1 -std=c++17 -triple x86_64-linux-gnu -fenable-matrix -fclang-abi-compat=4.0 %s -emit-llvm -o - \
10 // RUN:     | FileCheck --check-prefixes=CHECK,V39,PRE5,PRE12 %s
11 // RUN: %clang_cc1 -std=c++17 -triple x86_64-linux-gnu -fenable-matrix -fclang-abi-compat=5 %s -emit-llvm -o - \
12 // RUN:     | FileCheck --check-prefixes=CHECK,V39,V5,PRE12,PRE12-CXX17 %s
13 // RUN: %clang_cc1 -std=c++17 -triple x86_64-linux-gnu -fenable-matrix -fclang-abi-compat=11 %s -emit-llvm -o - \
14 // RUN:     | FileCheck --check-prefixes=CHECK,V39,V5,PRE12,PRE12-CXX17 %s
15 // RUN: %clang_cc1 -std=c++20 -triple x86_64-linux-gnu -fenable-matrix -fclang-abi-compat=11 %s -emit-llvm -o - \
16 // RUN:     | FileCheck --check-prefixes=CHECK,V39,V5,PRE12,PRE12-CXX17,PRE12-CXX20,PRE13-CXX20 %s
17 // RUN: %clang_cc1 -std=c++20 -triple x86_64-linux-gnu -fenable-matrix -fclang-abi-compat=12 %s -emit-llvm -o - \
18 // RUN:     | FileCheck --check-prefixes=CHECK,V39,V5,V12,V12-CXX17,V12-CXX20,PRE13-CXX20 %s
19 // RUN: %clang_cc1 -std=c++98 -triple x86_64-linux-gnu -fenable-matrix -fclang-abi-compat=latest %s -emit-llvm -o - -Wno-c++11-extensions \
20 // RUN:     | FileCheck --check-prefixes=CHECK,V39,V5,V12 %s
21 // RUN: %clang_cc1 -std=c++20 -triple x86_64-linux-gnu -fenable-matrix -fclang-abi-compat=latest %s -emit-llvm -o - \
22 // RUN:     | FileCheck --check-prefixes=CHECK,V39,V5,V12,V12-CXX17,V12-CXX20,V13-CXX20 %s
23 
24 typedef __attribute__((vector_size(8))) long long v1xi64;
clang39(v1xi64)25 void clang39(v1xi64) {}
26 // PRE39: @_Z7clang39Dv1_x(i64
27 // V39: @_Z7clang39Dv1_x(double
28 
29 struct A {
30   A(const A&) = default;
31   A(A&&);
32 };
clang5(A)33 void clang5(A) {}
34 // PRE5: @_Z6clang51A()
35 // V5: @_Z6clang51A(%{{.*}}*
36 
37 namespace mangle_template_prefix {
38   // PRE12: @_ZN22mangle_template_prefix1fINS_1TEEEvNT_1UIiE1VIiEENS4_S5_IfEE(
39   // V12: @_ZN22mangle_template_prefix1fINS_1TEEEvNT_1UIiE1VIiEENS5_IfEE(
40   template<typename T> void f(typename T::template U<int>::template V<int>, typename T::template U<int>::template V<float>);
41   struct T { template<typename I> struct U { template<typename J> using V = int; }; };
g()42   void g() { f<T>(1, 2); }
43 }
44 
45 int arg;
46 template<const int *> struct clang12_unchanged {};
47 // CHECK: @_Z4test17clang12_unchangedIXadL_Z3argEEE
test(clang12_unchanged<& arg>)48 void test(clang12_unchanged<&arg>) {}
49 
50 #if __cplusplus >= 201703L
51 // PRE12-CXX17: @_Z4test15clang12_changedIXadL_Z3argEEE
52 // V12-CXX17: @_Z4test15clang12_changedIXcvPKiadL_Z3argEEE
53 template<auto> struct clang12_changed {};
test(clang12_changed<(const int *)& arg>)54 void test(clang12_changed<(const int*)&arg>) {}
55 #endif
56 
57 // PRE12: @_Z9clang12_aIXadL_Z3argEEEvv
58 // V12: @_Z9clang12_aIXcvPKiadL_Z3argEEEvv
clang12_a()59 template<const int *> void clang12_a() {}
60 template void clang12_a<&arg>();
61 
62 // PRE12: @_Z9clang12_bIXadL_Z3arrEEEvv
63 // V12: @_Z9clang12_bIXadsoKcL_Z3arrEEEEvv
64 extern const char arr[6] = "hello";
clang12_b()65 template<const char *> void clang12_b() {}
66 template void clang12_b<arr>();
67 
68 // CHECK: @_Z9clang12_cIXadL_Z3arrEEEvv
clang12_c()69 template<const char (*)[6]> void clang12_c() {}
70 template void clang12_c<&arr>();
71 
72 
73 /// Tests for <template-arg> <expr-primary> changes in clang12:
74 namespace expr_primary {
75 struct A {
76   template<int N> struct Int {};
77   template<int& N> struct Ref {};
78 };
79 
80 /// Check various DeclRefExpr manglings
81 
82 // PRE12: @_ZN12expr_primary5test1INS_1AEEEvNT_3IntIXLi1EEEE
83 // V12:   @_ZN12expr_primary5test1INS_1AEEEvNT_3IntILi1EEE
test1(typename T::template Int<1> a)84 template <typename T> void test1(typename T::template Int<1> a) {}
85 template void test1<A>(typename A::template Int<1> a);
86 
87 enum Enum { EnumVal = 4 };
88 int Global;
89 
90 // PRE12: @_ZN12expr_primary5test2INS_1AEEEvNT_3IntIXLNS_4EnumE4EEEE
91 // V12:   @_ZN12expr_primary5test2INS_1AEEEvNT_3IntILNS_4EnumE4EEE
test2(typename T::template Int<EnumVal> a)92 template <typename T> void test2(typename T::template Int<EnumVal> a) {}
93 template void test2<A>(typename A::template Int<4> a);
94 
95 // CHECK: @_ZN12expr_primary5test3ILi3EEEvNS_1A3IntIXT_EEE
test3(typename A::template Int<X> a)96 template <int X> void test3(typename A::template Int<X> a) {}
97 template void test3<3>(A::Int<3> a);
98 
99 #if __cplusplus >= 202002L
100 // CHECK-CXX20: @_ZN12expr_primary5test4INS_1AEEEvNT_3RefIL_ZNS_6GlobalEEEE
test4(typename T::template Ref<(Global)> a)101 template <typename T> void test4(typename T::template Ref<(Global)> a) {}
102 template void test4<A>(typename A::template Ref<Global> a);
103 
104 struct B {
105   struct X {
Xexpr_primary::B::X106     constexpr X(double) {}
Xexpr_primary::B::X107     constexpr X(int&) {}
108   };
109   template<X> struct Y {};
110 };
111 
112 // PRE12-CXX20: _ZN12expr_primary5test5INS_1BEEEvNT_1YIXLd3ff0000000000000EEEE
113 // V12-CXX20: _ZN12expr_primary5test5INS_1BEEEvNT_1YILd3ff0000000000000EEE
test5(typename T::template Y<1.0>)114 template<typename T> void test5(typename T::template Y<1.0>) { }
115 template void test5<B>(typename B::Y<1.0>);
116 
117 // PRE12-CXX20: @_ZN12expr_primary5test6INS_1BEEENT_1YIL_ZZNS_5test6EiE1bEEEi
118 // V12-CXX20:   @_ZN12expr_primary5test6INS_1BEEENT_1YIXfp_EEEi
test6(int b)119 template<typename T> auto test6(int b) -> typename T::template Y<b> { return {}; }
120 template auto test6<B>(int b) -> B::Y<b>;
121 #endif
122 
123 /// Verify non-dependent type-traits within a dependent template arg.
124 
125 // PRE12: @_ZN12expr_primary5test7INS_1AEEEvNT_3IntIXLm1EEEE
126 // V12:   @_ZN12expr_primary5test7INS_1AEEEvNT_3IntILm1EEE
test7(typename T::template Int<sizeof (char)> a)127 template <class T> void test7(typename T::template Int<sizeof(char)> a) {}
128 template void test7<A>(A::Int<1>);
129 
130 // PRE12: @_ZN12expr_primary5test8ILi2EEEvu11matrix_typeIXLi1EEXT_EiE
131 // V12:   @_ZN12expr_primary5test8ILi2EEEvu11matrix_typeILi1EXT_EiE
132 template<int N> using matrix1xN = int __attribute__((matrix_type(1, N)));
test8(matrix1xN<N> a)133 template<int N> void test8(matrix1xN<N> a) {}
134 template void test8<2>(matrix1xN<2> a);
135 
136 // PRE12: @_ZN12expr_primary5test9EUa9enable_ifIXLi1EEEv
137 // V12:   @_ZN12expr_primary5test9EUa9enable_ifILi1EEv
test9(void)138 void test9(void) __attribute__((enable_if(1, ""))) {}
139 
140 }
141 
142 #if __cplusplus >= 202002L
143 // PRE13-CXX20: @_Z15observe_lambdasI17inline_var_lambdaMUlvE_17inline_var_lambdaMUlvE0_PiS2_S0_S1_EiT_T0_T1_T2_
144 // V13-CXX20: @_Z15observe_lambdasIN17inline_var_lambdaMUlvE_ENS0_UlvE0_EPiS3_S1_S2_EiT_T0_T1_T2_
145 template <typename T, typename U, typename V, typename W, typename = T, typename = U>
observe_lambdas(T,U,V,W)146 int observe_lambdas(T, U, V, W) { return 0; }
__anon072942b70202null147 inline auto inline_var_lambda = observe_lambdas([]{}, []{}, (int*)0, (int*)0);
use_inline_var_lambda()148 int use_inline_var_lambda() { return inline_var_lambda; }
149 #endif
150