[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Sema / warn-infinity-nan-disabled-lnx.cpp
blob357c9e5b6410737d85177e44f5fabbddc1356b1e
1 // RUN: %clang_cc1 -x c++ -verify=no-inf-no-nan \
2 // RUN: -triple powerpc64le-unknown-unknown %s \
3 // RUN: -menable-no-infs -menable-no-nans -std=c++23
5 // RUN: %clang_cc1 -x c++ -verify=no-inf-no-nan \
6 // RUN: -triple powerpc64le-unknown-unknown %s \
7 // RUN: -menable-no-infs -menable-no-nans -funsafe-math-optimizations \
8 // RUN: -std=c++23
10 // RUN: %clang_cc1 -x c++ -verify=no-fast -triple powerpc64le-unknown-unknown \
11 // RUN: %s -std=c++23
13 // RUN: %clang_cc1 -x c++ -verify=no-inf -triple powerpc64le-unknown-unknown %s \
14 // RUN: -menable-no-infs -std=c++23
16 // RUN: %clang_cc1 -x c++ -verify=no-inf -triple powerpc64le-unknown-unknown %s \
17 // RUN: -menable-no-infs -funsafe-math-optimizations -std=c++23
19 // RUN: %clang_cc1 -x c++ -verify=no-nan -triple powerpc64le-unknown-unknown %s \
20 // RUN: -menable-no-nans -std=c++23
22 // RUN: %clang_cc1 -x c++ -verify=no-nan -triple powerpc64le-unknown-unknown %s \
23 // RUN: -funsafe-math-optimizations -menable-no-nans -std=c++23
25 // RUN: %clang_cc1 -x c++ -verify=no-fast -triple powerpc64le-unknown-unknown \
26 // RUN: %s -Wno-nan-infinity-disabled -menable-no-infs -std=c++23
28 // RUN: %clang_cc1 -x c++ -verify=no-fast -triple powerpc64le-unknown-unknown \
29 // RUN: %s -Wno-nan-infinity-disabled -menable-no-nans -std=c++23
31 // no-fast-no-diagnostics
33 int isunorderedf (float x, float y);
34 extern "C++" {
35 namespace std __attribute__((__visibility__("default"))) {
36 bool
37 isinf(float __x);
38 bool
39 isinf(double __x);
40 bool
41 isinf(long double __x);
42 bool
43 isnan(float __x);
44 bool
45 isnan(double __x);
46 bool
47 isnan(long double __x);
48 bool
49 isfinite(float __x);
50 bool
51 isfinite(double __x);
52 bool
53 isfinte(long double __x);
54 bool
55 isunordered(float __x, float __y);
56 bool
57 isunordered(double __x, double __y);
58 bool
59 isunordered(long double __x, long double __y);
60 } // namespace )
63 #define NAN (__builtin_nanf(""))
64 #define INFINITY (__builtin_inff())
66 template <class _Ty>
67 class numeric_limits {
68 public:
69 [[nodiscard]] static constexpr _Ty infinity() noexcept {
70 return _Ty();
74 template <>
75 class numeric_limits<float> {
76 public:
77 [[nodiscard]] static constexpr float infinity() noexcept {
78 return __builtin_huge_val();
81 template <>
82 class numeric_limits<double> {
83 public:
84 [[nodiscard]] static constexpr double infinity() noexcept {
85 return __builtin_huge_val();
89 int compareit(float a, float b) {
90 volatile int i, j, k, l, m, n, o, p;
91 // no-inf-no-nan-warning@+4 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
92 // no-inf-no-nan-warning@+3 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
93 // no-inf-warning@+2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
94 // no-inf-warning@+1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
95 i = a == INFINITY;
97 // no-inf-no-nan-warning@+4 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
98 // no-inf-no-nan-warning@+3 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
99 // no-inf-warning@+2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
100 // no-inf-warning@+1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
101 j = INFINITY == a;
103 // no-inf-no-nan-warning@+4 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
104 // no-inf-no-nan-warning@+3 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
105 // no-nan-warning@+2 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
106 // no-nan-warning@+1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
107 i = a == NAN;
109 // no-inf-no-nan-warning@+4 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
110 // no-inf-no-nan-warning@+3 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
111 // no-nan-warning@+2 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
112 // no-nan-warning@+1 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
113 j = NAN == a;
115 // no-inf-no-nan-warning@+4 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
116 // no-inf-no-nan-warning@+3 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
117 // no-inf-warning@+2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
118 // no-inf-warning@+1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
119 j = INFINITY <= a;
121 // no-inf-no-nan-warning@+4 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
122 // no-inf-no-nan-warning@+3 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
123 // no-inf-warning@+2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
124 // no-inf-warning@+1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
125 j = INFINITY < a;
127 // no-inf-no-nan-warning@+4 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
128 // no-inf-no-nan-warning@+3 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
129 // no-nan-warning@+2 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
130 // no-nan-warning@+1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
131 j = a > NAN;
133 // no-inf-no-nan-warning@+4 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
134 // no-inf-no-nan-warning@+3 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
135 // no-nan-warning@+2 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
136 // no-nan-warning@+1 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
137 j = a >= NAN;
139 // no-inf-no-nan-warning@+2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
140 // no-inf-warning@+1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
141 k = std::isinf(a);
143 // no-inf-no-nan-warning@+2 {{use of NaN is undefined behavior due to the currently enabled floating-point option}}
144 // no-nan-warning@+1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
145 l = std::isnan(a);
147 // no-inf-no-nan-warning@+2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
148 // no-inf-warning@+1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
149 o = std::isfinite(a);
151 // no-inf-no-nan-warning@+2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
152 // no-inf-warning@+1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
153 m = __builtin_isinf(a);
155 // no-inf-no-nan-warning@+2 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
156 // no-nan-warning@+1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
157 n = __builtin_isnan(a);
159 // no-inf-no-nan-warning@+2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
160 // no-inf-warning@+1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
161 p = __builtin_isfinite(a);
163 // These should NOT warn, since they are not using NaN or infinity.
164 j = a > 1.1;
165 j = b < 1.1;
166 j = a >= 1.1;
167 j = b <= 1.1;
168 j = isunorderedf(a, b);
170 #ifndef INFINITY
171 j = a;
172 #endif
173 #ifndef NAN
174 j = b;
175 #endif
176 #ifdef INFINITY
177 j = a;
178 #endif
179 #ifdef NAN
180 j = b;
181 #endif
182 #if defined(INFINITY)
183 j = a;
184 #elifndef(INFINITY)
185 j = b;
186 #endif
187 #if defined(INFINITY)
188 j = a;
189 #elifndef(NAN)
190 j = b;
191 #endif
192 #if defined(NAN)
193 j = a;
194 #elifndef(INFINITY)
195 j = b;
196 #endif
198 // no-inf-no-nan-warning@+4 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
199 // no-inf-no-nan-warning@+3 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
200 // no-nan-warning@+2 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
201 // no-nan-warning@+1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
202 j = isunorderedf(a, NAN);
204 // no-inf-no-nan-warning@+4 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
205 // no-inf-no-nan-warning@+3 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
206 // no-inf-warning@+2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
207 // no-inf-warning@+1 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
208 j = isunorderedf(a, INFINITY);
210 // no-inf-no-nan-warning@+6 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
211 // no-inf-no-nan-warning@+5 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
212 // no-inf-no-nan-warning@+4 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
213 // no-nan-warning@+3 {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
214 // no-nan-warning@+2 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
215 // no-nan-warning@+1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
216 i = std::isunordered(a, NAN);
218 // no-inf-no-nan-warning@+6 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
219 // no-inf-no-nan-warning@+5 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
220 // no-inf-no-nan-warning@+4 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
221 // no-inf-warning@+3 {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
222 // no-inf-warning@+2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
223 // no-nan-warning@+1 {{use of NaN is undefined behavior due to the currently enabled floating-point options}}
224 i = std::isunordered(a, INFINITY);
226 // no-inf-no-nan-warning@+2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
227 // no-inf-warning@+1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
228 double y = i * numeric_limits<double>::infinity();
230 // no-inf-no-nan-warning@+2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
231 // no-inf-warning@+1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
232 j = numeric_limits<float>::infinity();
233 return 0;