1 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -disable-O0-optnone -emit-llvm -o - | FileCheck %s
3 // Test optnone on template instantiations.
5 //-- Effect of optnone on generic add template function.
7 template <typename T
> T
template_normal(T a
)
12 template <typename T
> __attribute__((optnone
)) T
template_optnone(T a
)
17 // This function should cause instantiations of each template, one marked
18 // with the 'optnone' attribute.
21 return template_normal
<int>(i
) + template_optnone
<int>(i
);
24 // CHECK: @_Z15template_normalIiET_S0_({{.*}}) [[NORMAL:#[0-9]+]]
25 // CHECK: @_Z16template_optnoneIiET_S0_({{.*}}) [[OPTNONE:#[0-9]+]]
28 //-- Effect of optnone on a partial specialization.
29 // FIRST TEST: a method becomes marked with optnone in the specialization.
31 template <typename T
, typename U
> class template_normal_base
{
35 return t
+ static_cast<T
>(u
);
39 template <typename U
> class template_normal_base
<int, U
>
42 __attribute__((optnone
)) int method (int t
, U u
)
44 return t
- static_cast<int>(u
);
48 // This function should cause an instantiation of the full template (whose
49 // method is not marked optnone) and an instantiation of the partially
50 // specialized template (whose method is marked optnone).
55 template_normal_base
<float, int> class_normal
;
56 template_normal_base
<int, float> class_optnone
;
57 float r1
= class_normal
.method(z
, y
);
58 float r2
= class_optnone
.method(y
, z
);
61 // CHECK: @_ZN20template_normal_baseIfiE6methodEfi({{.*}}) [[NORMAL]]
62 // CHECK: @_ZN20template_normal_baseIifE6methodEif({{.*}}) [[OPTNONE]]
65 //-- Effect of optnone on a partial specialization.
66 // SECOND TEST: a method loses optnone in the specialization.
68 template <typename T
, typename U
> class template_optnone_base
{
70 __attribute__((optnone
)) T
method(T t
, U u
)
72 return t
+ static_cast<T
>(u
);
76 template <typename U
> class template_optnone_base
<int, U
>
79 int method (int t
, U u
)
81 return t
- static_cast<int>(u
);
85 // This function should cause an instantiation of the full template (whose
86 // method is marked optnone) and an instantiation of the partially
87 // specialized template (whose method is not marked optnone).
92 template_optnone_base
<float, int> class_optnone
;
93 template_optnone_base
<int, float> class_normal
;
94 float r1
= class_optnone
.method(z
, y
);
95 float r2
= class_normal
.method(y
, z
);
98 // CHECK: @_ZN21template_optnone_baseIfiE6methodEfi({{.*}}) [[OPTNONE]]
99 // CHECK: @_ZN21template_optnone_baseIifE6methodEif({{.*}}) [[NORMAL]]
102 // CHECK: attributes [[NORMAL]] =
103 // CHECK-NOT: optnone
104 // CHECK: attributes [[OPTNONE]] = {{.*}} optnone