Debian Codegraph @

clang/test/Sema/warn-infinity-nan-disabled-lnx.cpp

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