1 // Test that the GCC fast-math floating point flags get lowered to the correct 2 // permutation of Clang frontend flags. This is non-trivial for a few reasons. 3 // First, the GCC flags have many different and surprising effects. Second, 4 // LLVM only supports three switches which is more coarse grained than GCC's 5 // support. 6 // 7 // Both of them use gcc driver for as. 8 // REQUIRES: clang-driver 9 // 10 // RUN: %clang -### -fno-honor-infinities -c %s 2>&1 \ 11 // RUN: | FileCheck --check-prefix=CHECK-NO-INFS %s 12 // infinites [sic] is a supported alternative spelling of infinities. 13 // RUN: %clang -### -fno-honor-infinites -c %s 2>&1 \ 14 // RUN: | FileCheck --check-prefix=CHECK-NO-INFS %s 15 // CHECK-NO-INFS: "-cc1" 16 // CHECK-NO-INFS: "-menable-no-infs" 17 // 18 // RUN: %clang -### -fno-fast-math -fno-honor-infinities -c %s 2>&1 \ 19 // RUN: | FileCheck --check-prefix=CHECK-NO-FAST-MATH-NO-INFS %s 20 // CHECK-NO-FAST-MATH-NO-INFS: "-cc1" 21 // CHECK-NO-FAST-MATH-NO-INFS: "-menable-no-infs" 22 // 23 // RUN: %clang -### -fno-honor-infinities -fno-fast-math -c %s 2>&1 \ 24 // RUN: | FileCheck --check-prefix=CHECK-NO-INFS-NO-FAST-MATH %s 25 // CHECK-NO-INFS-NO-FAST-MATH: "-cc1" 26 // CHECK-NO-INFS-NO-FAST-MATH-NOT: "-menable-no-infs" 27 // 28 // RUN: %clang -### -fno-signed-zeros -c %s 2>&1 \ 29 // RUN: | FileCheck --check-prefix=CHECK-NO-SIGNED-ZEROS %s 30 // CHECK-NO-SIGNED-ZEROS: "-cc1" 31 // CHECK-NO-SIGNED-ZEROS: "-fno-signed-zeros" 32 // 33 // RUN: %clang -### -fno-fast-math -fno-signed-zeros -c %s 2>&1 \ 34 // RUN: | FileCheck --check-prefix=CHECK-NO-FAST-MATH-NO-SIGNED-ZEROS %s 35 // CHECK-NO-FAST-MATH-NO-SIGNED-ZEROS: "-cc1" 36 // CHECK-NO-FAST-MATH-NO-SIGNED-ZEROS: "-fno-signed-zeros" 37 // 38 // RUN: %clang -### -fno-signed-zeros -fno-fast-math -c %s 2>&1 \ 39 // RUN: | FileCheck --check-prefix=CHECK-NO-SIGNED-ZEROS-NO-FAST-MATH %s 40 // CHECK-NO-SIGNED-ZEROS-NO-FAST-MATH: "-cc1" 41 // CHECK-NO-SIGNED-ZEROS-NO-FAST-MATH-NOT: "-fno-signed-zeros" 42 // 43 // RUN: %clang -### -freciprocal-math -c %s 2>&1 \ 44 // RUN: | FileCheck --check-prefix=CHECK-RECIPROCAL-MATH %s 45 // CHECK-RECIPROCAL-MATH: "-cc1" 46 // CHECK-RECIPROCAL-MATH: "-freciprocal-math" 47 // 48 // RUN: %clang -### -fno-fast-math -freciprocal-math -c %s 2>&1 \ 49 // RUN: | FileCheck --check-prefix=CHECK-NO-FAST-MATH-RECIPROCAL-MATH %s 50 // CHECK-NO-FAST-MATH-RECIPROCAL-MATH: "-cc1" 51 // CHECK-NO-FAST-MATH-RECIPROCAL-MATH: "-freciprocal-math" 52 // 53 // RUN: %clang -### -freciprocal-math -fno-fast-math -c %s 2>&1 \ 54 // RUN: | FileCheck --check-prefix=CHECK-RECIPROCAL-MATH-NO-FAST-MATH %s 55 // CHECK-RECIPROCAL-MATH-NO-FAST-MATH: "-cc1" 56 // CHECK-RECIPROCAL-MATH-NO-FAST-MATH-NOT: "-freciprocal-math" 57 // 58 // RUN: %clang -### -fno-honor-nans -c %s 2>&1 \ 59 // RUN: | FileCheck --check-prefix=CHECK-NO-NANS %s 60 // CHECK-NO-NANS: "-cc1" 61 // CHECK-NO-NANS: "-menable-no-nans" 62 // 63 // RUN: %clang -### -fno-fast-math -fno-honor-nans -c %s 2>&1 \ 64 // RUN: | FileCheck --check-prefix=CHECK-NO-FAST-MATH-NO-NANS %s 65 // CHECK-NO-FAST-MATH-NO-NANS: "-cc1" 66 // CHECK-NO-FAST-MATH-NO-NANS: "-menable-no-nans" 67 // 68 // RUN: %clang -### -fno-honor-nans -fno-fast-math -c %s 2>&1 \ 69 // RUN: | FileCheck --check-prefix=CHECK-NO-NANS-NO-FAST-MATH %s 70 // CHECK-NO-NANS-NO-FAST-MATH: "-cc1" 71 // CHECK-NO-NANS-NO-FAST-MATH-NOT: "-menable-no-nans" 72 // 73 // RUN: %clang -### -fmath-errno -c %s 2>&1 \ 74 // RUN: | FileCheck --check-prefix=CHECK-MATH-ERRNO %s 75 // CHECK-MATH-ERRNO: "-cc1" 76 // CHECK-MATH-ERRNO: "-fmath-errno" 77 // 78 // RUN: %clang -### -fmath-errno -fno-math-errno -c %s 2>&1 \ 79 // RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s 80 // CHECK-NO-MATH-ERRNO: "-cc1" 81 // CHECK-NO-MATH-ERRNO-NOT: "-fmath-errno" 82 // 83 // Target defaults for -fmath-errno (reusing the above checks). 84 // RUN: %clang -### -target i686-unknown-linux -c %s 2>&1 \ 85 // RUN: | FileCheck --check-prefix=CHECK-MATH-ERRNO %s 86 // RUN: %clang -### -target i686-apple-darwin -c %s 2>&1 \ 87 // RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s 88 // RUN: %clang -### -target x86_64-unknown-freebsd -c %s 2>&1 \ 89 // RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s 90 // RUN: %clang -### -target x86_64-unknown-netbsd -c %s 2>&1 \ 91 // RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s 92 // RUN: %clang -### -target x86_64-unknown-openbsd -c %s 2>&1 \ 93 // RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s 94 // RUN: %clang -### -target x86_64-unknown-dragonfly -c %s 2>&1 \ 95 // RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s 96 // RUN: %clang -### -target x86_64-fuchsia -c %s 2>&1 \ 97 // RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s 98 // 99 // Check that -ffast-math disables -fmath-errno, and -fno-fast-math merely 100 // preserves the target default. Also check various flag set operations between 101 // the two flags. (Resuses above checks.) 102 // RUN: %clang -### -ffast-math -c %s 2>&1 \ 103 // RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s 104 // RUN: %clang -### -fmath-errno -ffast-math -c %s 2>&1 \ 105 // RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s 106 // RUN: %clang -### -ffast-math -fmath-errno -c %s 2>&1 \ 107 // RUN: | FileCheck --check-prefix=CHECK-MATH-ERRNO %s 108 // RUN: %clang -### -target i686-unknown-linux -fno-fast-math -c %s 2>&1 \ 109 // RUN: | FileCheck --check-prefix=CHECK-MATH-ERRNO %s 110 // RUN: %clang -### -target i686-unknown-linux -fno-math-errno -fno-fast-math -c %s 2>&1 \ 111 // RUN: | FileCheck --check-prefix=CHECK-MATH-ERRNO %s 112 // RUN: %clang -### -target i686-apple-darwin -fno-fast-math -c %s 2>&1 \ 113 // RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s 114 // RUN: %clang -### -target i686-apple-darwin -fno-math-errno -fno-fast-math -c %s 2>&1 \ 115 // RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s 116 // RUN: %clang -### -fno-fast-math -fno-math-errno -c %s 2>&1 \ 117 // RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s 118 // 119 // RUN: %clang -### -fno-math-errno -fassociative-math -freciprocal-math \ 120 // RUN: -fno-signed-zeros -fno-trapping-math -c %s 2>&1 \ 121 // RUN: | FileCheck --check-prefix=CHECK-UNSAFE-MATH %s 122 // CHECK-UNSAFE-MATH: "-cc1" 123 // CHECK-UNSAFE-MATH: "-menable-unsafe-fp-math" 124 // CHECK-UNSAFE-MATH: "-mreassociate" 125 // 126 // RUN: %clang -### -fno-fast-math -fno-math-errno -fassociative-math -freciprocal-math \ 127 // RUN: -fno-signed-zeros -fno-trapping-math -c %s 2>&1 \ 128 // RUN: | FileCheck --check-prefix=CHECK-NO-FAST-MATH-UNSAFE-MATH %s 129 // CHECK-NO-FAST-MATH-UNSAFE-MATH: "-cc1" 130 // CHECK-NO-FAST-MATH-UNSAFE-MATH: "-menable-unsafe-fp-math" 131 // CHECK-NO-FAST-MATH-UNSAFE-MATH: "-mreassociate" 132 133 // The 2nd -fno-fast-math overrides -fassociative-math. 134 135 // RUN: %clang -### -fno-fast-math -fno-math-errno -fassociative-math -freciprocal-math \ 136 // RUN: -fno-fast-math -fno-signed-zeros -fno-trapping-math -c %s 2>&1 \ 137 // RUN: | FileCheck --check-prefix=CHECK-UNSAFE-MATH-NO-FAST-MATH %s 138 // CHECK-UNSAFE-MATH-NO-FAST-MATH: "-cc1" 139 // CHECK-UNSAFE-MATH-NO-FAST-MATH-NOT: "-menable-unsafe-fp-math" 140 // CHECK-UNSAFE-MATH-NO-FAST-MATH-NOT: "-mreassociate" 141 // 142 // Check that various umbrella flags also enable these frontend options. 143 // RUN: %clang -### -ffast-math -c %s 2>&1 \ 144 // RUN: | FileCheck --check-prefix=CHECK-NO-INFS %s 145 // RUN: %clang -### -ffast-math -c %s 2>&1 \ 146 // RUN: | FileCheck --check-prefix=CHECK-NO-NANS %s 147 // RUN: %clang -### -ffast-math -c %s 2>&1 \ 148 // RUN: | FileCheck --check-prefix=CHECK-UNSAFE-MATH %s 149 // RUN: %clang -### -ffinite-math-only -c %s 2>&1 \ 150 // RUN: | FileCheck --check-prefix=CHECK-NO-INFS %s 151 // RUN: %clang -### -ffinite-math-only -c %s 2>&1 \ 152 // RUN: | FileCheck --check-prefix=CHECK-NO-NANS %s 153 // RUN: %clang -### -funsafe-math-optimizations -fno-math-errno -c %s 2>&1 \ 154 // RUN: | FileCheck --check-prefix=CHECK-UNSAFE-MATH %s 155 // 156 // One umbrella flag is *really* weird and also changes the semantics of the 157 // program by adding a special preprocessor macro. Check that the frontend flag 158 // modeling this semantic change is provided. Also check that the flag is not 159 // present if any of the optimizations are disabled. 160 // RUN: %clang -### -ffast-math -c %s 2>&1 \ 161 // RUN: | FileCheck --check-prefix=CHECK-FAST-MATH %s 162 // RUN: %clang -### -fno-fast-math -ffast-math -c %s 2>&1 \ 163 // RUN: | FileCheck --check-prefix=CHECK-FAST-MATH %s 164 // RUN: %clang -### -funsafe-math-optimizations -ffinite-math-only \ 165 // RUN: -fno-math-errno -ffp-contract=fast -c %s 2>&1 \ 166 // RUN: | FileCheck --check-prefix=CHECK-FAST-MATH %s 167 // RUN: %clang -### -fno-honor-infinities -fno-honor-nans -fno-math-errno \ 168 // RUN: -fassociative-math -freciprocal-math -fno-signed-zeros \ 169 // RUN: -fno-trapping-math -ffp-contract=fast -c %s 2>&1 \ 170 // RUN: | FileCheck --check-prefix=CHECK-FAST-MATH %s 171 // CHECK-FAST-MATH: "-cc1" 172 // CHECK-FAST-MATH: "-ffast-math" 173 // CHECK-FAST-MATH: "-ffinite-math-only" 174 // 175 // RUN: %clang -### -ffast-math -fno-fast-math -c %s 2>&1 \ 176 // RUN: | FileCheck --check-prefix=CHECK-NO-FAST-MATH %s 177 // RUN: %clang -### -ffast-math -fno-finite-math-only -c %s 2>&1 \ 178 // RUN: | FileCheck --check-prefix=CHECK-NO-FAST-MATH %s 179 // RUN: %clang -### -ffast-math -fno-unsafe-math-optimizations -c %s 2>&1 \ 180 // RUN: | FileCheck --check-prefix=CHECK-NO-FAST-MATH %s 181 // RUN: %clang -### -ffast-math -fmath-errno -c %s 2>&1 \ 182 // RUN: | FileCheck --check-prefix=CHECK-NO-FAST-MATH %s 183 // RUN: %clang -### -ffast-math -fno-associative-math -c %s 2>&1 \ 184 // RUN: | FileCheck --check-prefix=CHECK-NO-FAST-MATH --check-prefix=CHECK-ASSOC-MATH %s 185 // CHECK-NO-FAST-MATH: "-cc1" 186 // CHECK-NO-FAST-MATH-NOT: "-ffast-math" 187 // CHECK-ASSOC-MATH-NOT: "-mreassociate" 188 // 189 // Check various means of disabling these flags, including disabling them after 190 // they've been enabled via an umbrella flag. 191 // RUN: %clang -### -fno-honor-infinities -fhonor-infinities -c %s 2>&1 \ 192 // RUN: | FileCheck --check-prefix=CHECK-NO-NO-INFS %s 193 // RUN: %clang -### -ffinite-math-only -fhonor-infinities -c %s 2>&1 \ 194 // RUN: | FileCheck --check-prefix=CHECK-NO-NO-INFS %s 195 // RUN: %clang -### -ffinite-math-only -fno-finite-math-only -c %s 2>&1 \ 196 // RUN: | FileCheck --check-prefix=CHECK-NO-NO-INFS %s 197 // RUN: %clang -### -ffast-math -fhonor-infinities -c %s 2>&1 \ 198 // RUN: | FileCheck --check-prefix=CHECK-NO-NO-INFS %s 199 // RUN: %clang -### -ffast-math -fno-finite-math-only -c %s 2>&1 \ 200 // RUN: | FileCheck --check-prefix=CHECK-NO-NO-INFS %s 201 // CHECK-NO-NO-INFS: "-cc1" 202 // CHECK-NO-NO-INFS-NOT: "-menable-no-infs" 203 // CHECK-NO-NO-INFS-NOT: "-ffinite-math-only" 204 // CHECK-NO-NO-INFS: "-o" 205 // 206 // RUN: %clang -### -fno-honor-nans -fhonor-nans -c %s 2>&1 \ 207 // RUN: | FileCheck --check-prefix=CHECK-NO-NO-NANS %s 208 // RUN: %clang -### -ffinite-math-only -fhonor-nans -c %s 2>&1 \ 209 // RUN: | FileCheck --check-prefix=CHECK-NO-NO-NANS %s 210 // RUN: %clang -### -ffinite-math-only -fno-finite-math-only -c %s 2>&1 \ 211 // RUN: | FileCheck --check-prefix=CHECK-NO-NO-NANS %s 212 // RUN: %clang -### -ffast-math -fhonor-nans -c %s 2>&1 \ 213 // RUN: | FileCheck --check-prefix=CHECK-NO-NO-NANS %s 214 // RUN: %clang -### -ffast-math -fno-finite-math-only -c %s 2>&1 \ 215 // RUN: | FileCheck --check-prefix=CHECK-NO-NO-NANS %s 216 // CHECK-NO-NO-NANS: "-cc1" 217 // CHECK-NO-NO-NANS-NOT: "-menable-no-nans" 218 // CHECK-NO-NO-NANS-NOT: "-ffinite-math-only" 219 // CHECK-NO-NO-NANS: "-o" 220 221 // A later inverted option overrides an earlier option. 222 223 // RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \ 224 // RUN: -fno-trapping-math -fno-associative-math -c %s 2>&1 \ 225 // RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 226 227 // RUN: %clang -### -funsafe-math-optimizations -fno-associative-math -c %s \ 228 // RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 229 230 // RUN: %clang -### -funsafe-math-optimizations -fno-reciprocal-math -c %s \ 231 // RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 232 // RUN: %clang -### -funsafe-math-optimizations -fsigned-zeros -c %s 2>&1 \ 233 // RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 234 // RUN: %clang -### -funsafe-math-optimizations -ftrapping-math -c %s 2>&1 \ 235 // RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 236 // RUN: %clang -### -funsafe-math-optimizations -fno-unsafe-math-optimizations \ 237 // RUN: -c %s 2>&1 \ 238 // RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 239 // RUN: %clang -### -ffast-math -fno-associative-math -c %s 2>&1 \ 240 // RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 241 242 // RUN: %clang -### -ffast-math -fno-reciprocal-math -c %s 2>&1 \ 243 // RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 244 // RUN: %clang -### -ffast-math -fsigned-zeros -c %s 2>&1 \ 245 // RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 246 // RUN: %clang -### -ffast-math -ftrapping-math -c %s 2>&1 \ 247 // RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 248 // RUN: %clang -### -ffast-math -fno-unsafe-math-optimizations -c %s 2>&1 \ 249 // RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 250 251 // CHECK-NO-UNSAFE-MATH: "-cc1" 252 // CHECK-NO-UNSAFE-MATH-NOT: "-menable-unsafe-fp-math" 253 // CHECK-NO_UNSAFE-MATH-NOT: "-mreassociate" 254 // CHECK-NO-UNSAFE-MATH: "-o" 255 256 257 // Reassociate is allowed because it does not require reciprocal-math. 258 259 // RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \ 260 // RUN: -fno-trapping-math -fno-reciprocal-math -c %s 2>&1 \ 261 // RUN: | FileCheck --check-prefix=CHECK-REASSOC-NO-UNSAFE-MATH %s 262 263 // CHECK-REASSOC-NO-UNSAFE-MATH: "-cc1" 264 // CHECK-REASSOC-NO-UNSAFE-MATH-NOT: "-menable-unsafe-fp-math" 265 // CHECK-REASSOC-NO_UNSAFE-MATH: "-mreassociate" 266 // CHECK-REASSOC-NO-UNSAFE-MATH-NOT: "-menable-unsafe-fp-math" 267 // CHECK-REASSOC-NO-UNSAFE-MATH: "-o" 268 269 270 // In these runs, reassociate is not allowed because both no-signed-zeros and no-trapping-math are required. 271 272 // RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \ 273 // RUN: -fno-trapping-math -fsigned-zeros -c %s 2>&1 \ 274 // RUN: | FileCheck --check-prefix=CHECK-NO-REASSOC-NO-UNSAFE-MATH %s 275 276 // RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \ 277 // RUN: -fno-trapping-math -ftrapping-math -c %s 2>&1 \ 278 // RUN: | FileCheck --check-prefix=CHECK-NO-REASSOC-NO-UNSAFE-MATH %s 279 280 // CHECK-NO-REASSOC-NO-UNSAFE-MATH: "-cc1" 281 // CHECK-NO-REASSOC-NO-UNSAFE-MATH-NOT: "-menable-unsafe-fp-math" 282 // CHECK-NO-REASSOC-NO_UNSAFE-MATH-NOT: "-mreassociate" 283 // CHECK-NO-REASSOC-NO-UNSAFE-MATH-NOT: "-menable-unsafe-fp-math" 284 // CHECK-NO-REASSOC-NO-UNSAFE-MATH: "-o" 285 286 287 // RUN: %clang -### -ftrapping-math -fno-trapping-math -c %s 2>&1 \ 288 // RUN: | FileCheck --check-prefix=CHECK-NO-TRAPPING-MATH %s 289 // CHECK-NO-TRAPPING-MATH: "-fno-trapping-math" 290