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