Debian Codegraph @

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

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