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
12 constexpr float add_round_up(float x
, float y
) {
13 #pragma STDC FENV_ROUND FE_UPWARD
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
31 constexpr float add_cast_round_up(float x
, double y
) {
32 #pragma STDC FENV_ROUND FE_UPWARD
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
47 float V5
= []() -> float {
48 return [](float x
, float y
)->float {
49 #pragma STDC FENV_ROUND FE_UPWARD
51 }([](float x
, float y
) -> float {
52 #pragma STDC FENV_ROUND FE_UPWARD
54 }(1.0F
, 0x0.000001p0F
),
57 // CHECK: @V5 = {{.*}} float 0x3FF0000040000000
59 float V6
= []() -> float {
60 return [](float x
, float y
)->float {
61 #pragma STDC FENV_ROUND FE_DOWNWARD
63 }([](float x
, float y
) -> float {
64 #pragma STDC FENV_ROUND FE_UPWARD
66 }(1.0F
, 0x0.000001p0F
),
69 // CHECK: @V6 = {{.*}} float 0x3FF0000020000000
71 float V7
= []() -> float {
72 return [](float x
, float y
)->float {
73 #pragma STDC FENV_ROUND FE_DOWNWARD
75 }([](float x
, float y
) -> float {
76 #pragma STDC FENV_ROUND FE_DOWNWARD
78 }(1.0F
, 0x0.000001p0F
),
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
) {}
90 #pragma STDC FENV_ROUND FE_DOWNWARD
92 // CHECK: @val_d = {{.*}} { float 0x3FB9999980000000 }
94 #pragma STDC FENV_ROUND FE_UPWARD
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
>
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() {
152 #pragma STDC FENV_ROUND FE_DOWNWARD
157 #pragma STDC FENV_ROUND FE_UPWARD
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
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>() {
185 // CHECK-LABEL: define {{.*}} float @_Z8tfunc_01ILi2EEfv()
186 // CHECK: ret float 0x3FB99999A0000000