[flang][cuda] Adapt ExternalNameConversion to work in gpu module (#117039)
[llvm-project.git] / clang / test / AST / const-fpfeatures.cpp
blob5e903c8c0e8745382925d71c3613d8f4302b856a
1 // RUN: %clang_cc1 -emit-llvm -triple i386-linux -std=c++2a -Wno-unknown-pragmas %s -o - | FileCheck %s
3 // nextUp(1.F) == 0x1.000002p0F
5 constexpr float add_round_down(float x, float y) {
6 #pragma STDC FENV_ROUND FE_DOWNWARD
7 float res = x;
8 res += y;
9 return res;
12 constexpr float add_round_up(float x, float y) {
13 #pragma STDC FENV_ROUND FE_UPWARD
14 float res = x;
15 res += y;
16 return res;
19 float V1 = add_round_down(1.0F, 0x0.000001p0F);
20 float V2 = add_round_up(1.0F, 0x0.000001p0F);
21 // CHECK: @V1 = {{.*}} float 1.000000e+00
22 // CHECK: @V2 = {{.*}} float 0x3FF0000020000000
24 constexpr float add_cast_round_down(float x, double y) {
25 #pragma STDC FENV_ROUND FE_DOWNWARD
26 float res = x;
27 res += y;
28 return res;
31 constexpr float add_cast_round_up(float x, double y) {
32 #pragma STDC FENV_ROUND FE_UPWARD
33 float res = x;
34 res += y;
35 return res;
38 float V3 = add_cast_round_down(1.0F, 0x0.000001p0F);
39 float V4 = add_cast_round_up(1.0F, 0x0.000001p0F);
41 // CHECK: @V3 = {{.*}} float 1.000000e+00
42 // CHECK: @V4 = {{.*}} float 0x3FF0000020000000
44 // The next three variables use the same function as initializer, only rounding
45 // modes differ.
47 float V5 = []() -> float {
48 return [](float x, float y)->float {
49 #pragma STDC FENV_ROUND FE_UPWARD
50 return x + y;
51 }([](float x, float y) -> float {
52 #pragma STDC FENV_ROUND FE_UPWARD
53 return x + y;
54 }(1.0F, 0x0.000001p0F),
55 0x0.000001p0F);
56 }();
57 // CHECK: @V5 = {{.*}} float 0x3FF0000040000000
59 float V6 = []() -> float {
60 return [](float x, float y)->float {
61 #pragma STDC FENV_ROUND FE_DOWNWARD
62 return x + y;
63 }([](float x, float y) -> float {
64 #pragma STDC FENV_ROUND FE_UPWARD
65 return x + y;
66 }(1.0F, 0x0.000001p0F),
67 0x0.000001p0F);
68 }();
69 // CHECK: @V6 = {{.*}} float 0x3FF0000020000000
71 float V7 = []() -> float {
72 return [](float x, float y)->float {
73 #pragma STDC FENV_ROUND FE_DOWNWARD
74 return x + y;
75 }([](float x, float y) -> float {
76 #pragma STDC FENV_ROUND FE_DOWNWARD
77 return x + y;
78 }(1.0F, 0x0.000001p0F),
79 0x0.000001p0F);
80 }();
81 // CHECK: @V7 = {{.*}} float 1.000000e+00
83 #pragma STDC FENV_ROUND FE_DYNAMIC
85 template<float V> struct L {
86 constexpr L() : value(V) {}
87 float value;
90 #pragma STDC FENV_ROUND FE_DOWNWARD
91 L<0.1F> val_d;
92 // CHECK: @val_d = {{.*}} { float 0x3FB9999980000000 }
94 #pragma STDC FENV_ROUND FE_UPWARD
95 L<0.1F> val_u;
96 // CHECK: @val_u = {{.*}} { float 0x3FB99999A0000000 }
99 // Check literals in macros.
101 #pragma STDC FENV_ROUND FE_DOWNWARD
102 #define CONSTANT_0_1 0.1F
104 #pragma STDC FENV_ROUND FE_UPWARD
105 float C1_ru = CONSTANT_0_1;
106 // CHECK: @C1_ru = {{.*}} float 0x3FB99999A0000000
108 #pragma STDC FENV_ROUND FE_DOWNWARD
109 float C1_rd = CONSTANT_0_1;
110 // CHECK: @C1_rd = {{.*}} float 0x3FB9999980000000
112 #pragma STDC FENV_ROUND FE_DOWNWARD
113 #define PRAGMA(x) _Pragma(#x)
114 #define CONSTANT_0_1_RM(v, rm) ([](){ PRAGMA(STDC FENV_ROUND rm); return v; }())
116 #pragma STDC FENV_ROUND FE_UPWARD
117 float C2_rd = CONSTANT_0_1_RM(0.1F, FE_DOWNWARD);
118 float C2_ru = CONSTANT_0_1_RM(0.1F, FE_UPWARD);
119 // CHECK: @C2_rd = {{.*}} float 0x3FB9999980000000
120 // CHECK: @C2_ru = {{.*}} float 0x3FB99999A0000000
122 #pragma STDC FENV_ROUND FE_DOWNWARD
123 float C3_rd = CONSTANT_0_1_RM(0.1F, FE_DOWNWARD);
124 float C3_ru = CONSTANT_0_1_RM(0.1F, FE_UPWARD);
125 // CHECK: @C3_rd = {{.*}} float 0x3FB9999980000000
126 // CHECK: @C3_ru = {{.*}} float 0x3FB99999A0000000
128 // Check literals in template instantiations.
130 #pragma STDC FENV_ROUND FE_DYNAMIC
132 template<typename T, T C>
133 constexpr T foo() {
134 return C;
137 #pragma STDC FENV_ROUND FE_DOWNWARD
138 float var_d = foo<float, 0.1F>();
139 // CHECK: @var_d = {{.*}} float 0x3FB9999980000000
141 #pragma STDC FENV_ROUND FE_UPWARD
142 float var_u = foo<float, 0.1F>();
143 // CHECK: @var_u = {{.*}} float 0x3FB99999A0000000
145 #pragma STDC FENV_ROUND FE_DYNAMIC
147 template<typename T, T f> void foo2() {
148 T Val = f;
151 void func_01() {
152 #pragma STDC FENV_ROUND FE_DOWNWARD
153 foo2<float, 0.1f>();
156 void func_02() {
157 #pragma STDC FENV_ROUND FE_UPWARD
158 foo2<float, 0.1f>();
161 // CHECK-LABEL: define {{.*}} void @_Z4foo2IfTnT_Lf3dccccccEEvv()
162 // CHECK: store float 0x3FB9999980000000, ptr
164 // CHECK-LABEL: define {{.*}} void @_Z4foo2IfTnT_Lf3dcccccdEEvv()
165 // CHECK: store float 0x3FB99999A0000000, ptr
168 #pragma STDC FENV_ROUND FE_DOWNWARD
169 template <int C>
170 float tfunc_01() {
171 return 0.1F; // Must be 0x3FB9999980000000 in all instantiations.
173 template float tfunc_01<0>();
174 // CHECK-LABEL: define {{.*}} float @_Z8tfunc_01ILi0EEfv()
175 // CHECK: ret float 0x3FB9999980000000
177 #pragma STDC FENV_ROUND FE_UPWARD
178 template float tfunc_01<1>();
179 // CHECK-LABEL: define {{.*}} float @_Z8tfunc_01ILi1EEfv()
180 // CHECK: ret float 0x3FB9999980000000
182 template<> float tfunc_01<2>() {
183 return 0.1F;
185 // CHECK-LABEL: define {{.*}} float @_Z8tfunc_01ILi2EEfv()
186 // CHECK: ret float 0x3FB99999A0000000