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