1*f4a2713aSLionel Sambuc // Test that the GCC fast-math floating point flags get lowered to the correct 2*f4a2713aSLionel Sambuc // permutation of Clang frontend flags. This is non-trivial for a few reasons. 3*f4a2713aSLionel Sambuc // First, the GCC flags have many different and surprising effects. Second, 4*f4a2713aSLionel Sambuc // LLVM only supports three switches which is more coarse grained than GCC's 5*f4a2713aSLionel Sambuc // support. 6*f4a2713aSLionel Sambuc // 7*f4a2713aSLionel Sambuc // Both of them use gcc driver for as. 8*f4a2713aSLionel Sambuc // REQUIRES: clang-driver 9*f4a2713aSLionel Sambuc // 10*f4a2713aSLionel Sambuc // RUN: %clang -### -fno-honor-infinities -c %s 2>&1 \ 11*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-INFS %s 12*f4a2713aSLionel Sambuc // CHECK-NO-INFS: "-cc1" 13*f4a2713aSLionel Sambuc // CHECK-NO-INFS: "-menable-no-infs" 14*f4a2713aSLionel Sambuc // 15*f4a2713aSLionel Sambuc // RUN: %clang -### -fno-fast-math -fno-honor-infinities -c %s 2>&1 \ 16*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-FAST-MATH-NO-INFS %s 17*f4a2713aSLionel Sambuc // CHECK-NO-FAST-MATH-NO-INFS: "-cc1" 18*f4a2713aSLionel Sambuc // CHECK-NO-FAST-MATH-NO-INFS: "-menable-no-infs" 19*f4a2713aSLionel Sambuc // 20*f4a2713aSLionel Sambuc // RUN: %clang -### -fno-honor-infinities -fno-fast-math -c %s 2>&1 \ 21*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-INFS-NO-FAST-MATH %s 22*f4a2713aSLionel Sambuc // CHECK-NO-INFS-NO-FAST-MATH: "-cc1" 23*f4a2713aSLionel Sambuc // CHECK-NO-INFS-NO-FAST-MATH-NOT: "-menable-no-infs" 24*f4a2713aSLionel Sambuc // 25*f4a2713aSLionel Sambuc // RUN: %clang -### -fno-honor-nans -c %s 2>&1 \ 26*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-NANS %s 27*f4a2713aSLionel Sambuc // CHECK-NO-NANS: "-cc1" 28*f4a2713aSLionel Sambuc // CHECK-NO-NANS: "-menable-no-nans" 29*f4a2713aSLionel Sambuc // 30*f4a2713aSLionel Sambuc // RUN: %clang -### -fno-fast-math -fno-honor-nans -c %s 2>&1 \ 31*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-FAST-MATH-NO-NANS %s 32*f4a2713aSLionel Sambuc // CHECK-NO-FAST-MATH-NO-NANS: "-cc1" 33*f4a2713aSLionel Sambuc // CHECK-NO-FAST-MATH-NO-NANS: "-menable-no-nans" 34*f4a2713aSLionel Sambuc // 35*f4a2713aSLionel Sambuc // RUN: %clang -### -fno-honor-nans -fno-fast-math -c %s 2>&1 \ 36*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-NANS-NO-FAST-MATH %s 37*f4a2713aSLionel Sambuc // CHECK-NO-NANS-NO-FAST-MATH: "-cc1" 38*f4a2713aSLionel Sambuc // CHECK-NO-NANS-NO-FAST-MATH-NOT: "-menable-no-nans" 39*f4a2713aSLionel Sambuc // 40*f4a2713aSLionel Sambuc // RUN: %clang -### -fmath-errno -c %s 2>&1 \ 41*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-MATH-ERRNO %s 42*f4a2713aSLionel Sambuc // CHECK-MATH-ERRNO: "-cc1" 43*f4a2713aSLionel Sambuc // CHECK-MATH-ERRNO: "-fmath-errno" 44*f4a2713aSLionel Sambuc // 45*f4a2713aSLionel Sambuc // RUN: %clang -### -fmath-errno -fno-math-errno -c %s 2>&1 \ 46*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s 47*f4a2713aSLionel Sambuc // CHECK-NO-MATH-ERRNO: "-cc1" 48*f4a2713aSLionel Sambuc // CHECK-NO-MATH-ERRNO-NOT: "-fmath-errno" 49*f4a2713aSLionel Sambuc // 50*f4a2713aSLionel Sambuc // Target defaults for -fmath-errno (reusing the above checks). 51*f4a2713aSLionel Sambuc // RUN: %clang -### -target i686-unknown-linux -c %s 2>&1 \ 52*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-MATH-ERRNO %s 53*f4a2713aSLionel Sambuc // RUN: %clang -### -target i686-apple-darwin -c %s 2>&1 \ 54*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s 55*f4a2713aSLionel Sambuc // RUN: %clang -### -target x86_64-unknown-freebsd -c %s 2>&1 \ 56*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s 57*f4a2713aSLionel Sambuc // RUN: %clang -### -target x86_64-unknown-netbsd -c %s 2>&1 \ 58*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s 59*f4a2713aSLionel Sambuc // RUN: %clang -### -target x86_64-unknown-openbsd -c %s 2>&1 \ 60*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s 61*f4a2713aSLionel Sambuc // RUN: %clang -### -target x86_64-unknown-dragonfly -c %s 2>&1 \ 62*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s 63*f4a2713aSLionel Sambuc // 64*f4a2713aSLionel Sambuc // Check that -ffast-math disables -fmath-errno, and -fno-fast-math merely 65*f4a2713aSLionel Sambuc // preserves the target default. Also check various flag set operations between 66*f4a2713aSLionel Sambuc // the two flags. (Resuses above checks.) 67*f4a2713aSLionel Sambuc // RUN: %clang -### -ffast-math -c %s 2>&1 \ 68*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s 69*f4a2713aSLionel Sambuc // RUN: %clang -### -fmath-errno -ffast-math -c %s 2>&1 \ 70*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s 71*f4a2713aSLionel Sambuc // RUN: %clang -### -ffast-math -fmath-errno -c %s 2>&1 \ 72*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-MATH-ERRNO %s 73*f4a2713aSLionel Sambuc // RUN: %clang -### -target i686-unknown-linux -fno-fast-math -c %s 2>&1 \ 74*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-MATH-ERRNO %s 75*f4a2713aSLionel Sambuc // RUN: %clang -### -target i686-unknown-linux -fno-math-errno -fno-fast-math -c %s 2>&1 \ 76*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-MATH-ERRNO %s 77*f4a2713aSLionel Sambuc // RUN: %clang -### -target i686-apple-darwin -fno-fast-math -c %s 2>&1 \ 78*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s 79*f4a2713aSLionel Sambuc // RUN: %clang -### -target i686-apple-darwin -fno-math-errno -fno-fast-math -c %s 2>&1 \ 80*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s 81*f4a2713aSLionel Sambuc // RUN: %clang -### -fno-fast-math -fno-math-errno -c %s 2>&1 \ 82*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s 83*f4a2713aSLionel Sambuc // 84*f4a2713aSLionel Sambuc // RUN: %clang -### -fno-math-errno -fassociative-math -freciprocal-math \ 85*f4a2713aSLionel Sambuc // RUN: -fno-signed-zeros -fno-trapping-math -c %s 2>&1 \ 86*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-UNSAFE-MATH %s 87*f4a2713aSLionel Sambuc // CHECK-UNSAFE-MATH: "-cc1" 88*f4a2713aSLionel Sambuc // CHECK-UNSAFE-MATH: "-menable-unsafe-fp-math" 89*f4a2713aSLionel Sambuc // 90*f4a2713aSLionel Sambuc // RUN: %clang -### -fno-fast-math -fno-math-errno -fassociative-math -freciprocal-math \ 91*f4a2713aSLionel Sambuc // RUN: -fno-signed-zeros -fno-trapping-math -c %s 2>&1 \ 92*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-FAST-MATH-UNSAFE-MATH %s 93*f4a2713aSLionel Sambuc // CHECK-NO-FAST-MATH-UNSAFE-MATH: "-cc1" 94*f4a2713aSLionel Sambuc // CHECK-NO-FAST-MATH-UNSAFE-MATH: "-menable-unsafe-fp-math" 95*f4a2713aSLionel Sambuc // 96*f4a2713aSLionel Sambuc // RUN: %clang -### -fno-fast-math -fno-math-errno -fassociative-math -freciprocal-math \ 97*f4a2713aSLionel Sambuc // RUN: -fno-fast-math -fno-signed-zeros -fno-trapping-math -c %s 2>&1 \ 98*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-UNSAFE-MATH-NO-FAST-MATH %s 99*f4a2713aSLionel Sambuc // CHECK-UNSAFE-MATH-NO-FAST-MATH: "-cc1" 100*f4a2713aSLionel Sambuc // CHECK-UNSAFE-MATH-NO-FAST-MATH-NOT: "-menable-unsafe-fp-math" 101*f4a2713aSLionel Sambuc // 102*f4a2713aSLionel Sambuc // Check that various umbrella flags also enable these frontend options. 103*f4a2713aSLionel Sambuc // RUN: %clang -### -ffast-math -c %s 2>&1 \ 104*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-INFS %s 105*f4a2713aSLionel Sambuc // RUN: %clang -### -ffast-math -c %s 2>&1 \ 106*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-NANS %s 107*f4a2713aSLionel Sambuc // RUN: %clang -### -ffast-math -c %s 2>&1 \ 108*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-UNSAFE-MATH %s 109*f4a2713aSLionel Sambuc // RUN: %clang -### -ffinite-math-only -c %s 2>&1 \ 110*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-INFS %s 111*f4a2713aSLionel Sambuc // RUN: %clang -### -ffinite-math-only -c %s 2>&1 \ 112*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-NANS %s 113*f4a2713aSLionel Sambuc // RUN: %clang -### -funsafe-math-optimizations -fno-math-errno -c %s 2>&1 \ 114*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-UNSAFE-MATH %s 115*f4a2713aSLionel Sambuc // 116*f4a2713aSLionel Sambuc // One umbrella flag is *really* weird and also changes the semantics of the 117*f4a2713aSLionel Sambuc // program by adding a special preprocessor macro. Check that the frontend flag 118*f4a2713aSLionel Sambuc // modeling this semantic change is provided. Also check that the semantic 119*f4a2713aSLionel Sambuc // impact remains even if every optimization is disabled. 120*f4a2713aSLionel Sambuc // RUN: %clang -### -ffast-math -c %s 2>&1 \ 121*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-FAST-MATH %s 122*f4a2713aSLionel Sambuc // RUN: %clang -### -fno-fast-math -ffast-math -c %s 2>&1 \ 123*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-FAST-MATH %s 124*f4a2713aSLionel Sambuc // RUN: %clang -### -ffast-math -fno-finite-math-only \ 125*f4a2713aSLionel Sambuc // RUN: -fno-unsafe-math-optimizations -fmath-errno -c %s 2>&1 \ 126*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-FAST-MATH %s 127*f4a2713aSLionel Sambuc // CHECK-FAST-MATH: "-cc1" 128*f4a2713aSLionel Sambuc // CHECK-FAST-MATH: "-ffast-math" 129*f4a2713aSLionel Sambuc // 130*f4a2713aSLionel Sambuc // RUN: %clang -### -ffast-math -fno-fast-math -c %s 2>&1 \ 131*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-FAST-MATH %s 132*f4a2713aSLionel Sambuc // CHECK-NO-FAST-MATH: "-cc1" 133*f4a2713aSLionel Sambuc // CHECK-NO-FAST-MATH-NOT: "-ffast-math" 134*f4a2713aSLionel Sambuc // 135*f4a2713aSLionel Sambuc // Check various means of disabling these flags, including disabling them after 136*f4a2713aSLionel Sambuc // they've been enabled via an umbrella flag. 137*f4a2713aSLionel Sambuc // RUN: %clang -### -fno-honor-infinities -fhonor-infinities -c %s 2>&1 \ 138*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-NO-INFS %s 139*f4a2713aSLionel Sambuc // RUN: %clang -### -ffinite-math-only -fhonor-infinities -c %s 2>&1 \ 140*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-NO-INFS %s 141*f4a2713aSLionel Sambuc // RUN: %clang -### -ffinite-math-only -fno-finite-math-only -c %s 2>&1 \ 142*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-NO-INFS %s 143*f4a2713aSLionel Sambuc // RUN: %clang -### -ffast-math -fhonor-infinities -c %s 2>&1 \ 144*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-NO-INFS %s 145*f4a2713aSLionel Sambuc // RUN: %clang -### -ffast-math -fno-finite-math-only -c %s 2>&1 \ 146*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-NO-INFS %s 147*f4a2713aSLionel Sambuc // CHECK-NO-NO-INFS: "-cc1" 148*f4a2713aSLionel Sambuc // CHECK-NO-NO-INFS-NOT: "-menable-no-infs" 149*f4a2713aSLionel Sambuc // CHECK-NO-NO-INFS: "-o" 150*f4a2713aSLionel Sambuc // 151*f4a2713aSLionel Sambuc // RUN: %clang -### -fno-honor-nans -fhonor-nans -c %s 2>&1 \ 152*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-NO-NANS %s 153*f4a2713aSLionel Sambuc // RUN: %clang -### -ffinite-math-only -fhonor-nans -c %s 2>&1 \ 154*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-NO-NANS %s 155*f4a2713aSLionel Sambuc // RUN: %clang -### -ffinite-math-only -fno-finite-math-only -c %s 2>&1 \ 156*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-NO-NANS %s 157*f4a2713aSLionel Sambuc // RUN: %clang -### -ffast-math -fhonor-nans -c %s 2>&1 \ 158*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-NO-NANS %s 159*f4a2713aSLionel Sambuc // RUN: %clang -### -ffast-math -fno-finite-math-only -c %s 2>&1 \ 160*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-NO-NANS %s 161*f4a2713aSLionel Sambuc // CHECK-NO-NO-NANS: "-cc1" 162*f4a2713aSLionel Sambuc // CHECK-NO-NO-NANS-NOT: "-menable-no-nans" 163*f4a2713aSLionel Sambuc // CHECK-NO-NO-NANS: "-o" 164*f4a2713aSLionel Sambuc // 165*f4a2713aSLionel Sambuc // RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \ 166*f4a2713aSLionel Sambuc // RUN: -fno-trapping-math -fno-associative-math -c %s 2>&1 \ 167*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 168*f4a2713aSLionel Sambuc // RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \ 169*f4a2713aSLionel Sambuc // RUN: -fno-trapping-math -fno-reciprocal-math -c %s 2>&1 \ 170*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 171*f4a2713aSLionel Sambuc // RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \ 172*f4a2713aSLionel Sambuc // RUN: -fno-trapping-math -fsigned-zeros -c %s 2>&1 \ 173*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 174*f4a2713aSLionel Sambuc // RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \ 175*f4a2713aSLionel Sambuc // RUN: -fno-trapping-math -ftrapping-math -c %s 2>&1 \ 176*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 177*f4a2713aSLionel Sambuc // RUN: %clang -### -funsafe-math-optimizations -fno-associative-math -c %s \ 178*f4a2713aSLionel Sambuc // RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 179*f4a2713aSLionel Sambuc // RUN: %clang -### -funsafe-math-optimizations -fno-reciprocal-math -c %s \ 180*f4a2713aSLionel Sambuc // RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 181*f4a2713aSLionel Sambuc // RUN: %clang -### -funsafe-math-optimizations -fsigned-zeros -c %s 2>&1 \ 182*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 183*f4a2713aSLionel Sambuc // RUN: %clang -### -funsafe-math-optimizations -ftrapping-math -c %s 2>&1 \ 184*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 185*f4a2713aSLionel Sambuc // RUN: %clang -### -funsafe-math-optimizations -fno-unsafe-math-optimizations \ 186*f4a2713aSLionel Sambuc // RUN: -c %s 2>&1 \ 187*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 188*f4a2713aSLionel Sambuc // RUN: %clang -### -ffast-math -fno-associative-math -c %s 2>&1 \ 189*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 190*f4a2713aSLionel Sambuc // RUN: %clang -### -ffast-math -fno-reciprocal-math -c %s 2>&1 \ 191*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 192*f4a2713aSLionel Sambuc // RUN: %clang -### -ffast-math -fsigned-zeros -c %s 2>&1 \ 193*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 194*f4a2713aSLionel Sambuc // RUN: %clang -### -ffast-math -ftrapping-math -c %s 2>&1 \ 195*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 196*f4a2713aSLionel Sambuc // RUN: %clang -### -ffast-math -fno-unsafe-math-optimizations -c %s 2>&1 \ 197*f4a2713aSLionel Sambuc // RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s 198*f4a2713aSLionel Sambuc // CHECK-NO-UNSAFE-MATH: "-cc1" 199*f4a2713aSLionel Sambuc // CHECK-NO-UNSAFE-MATH-NOT: "-menable-unsafe-fp-math" 200*f4a2713aSLionel Sambuc // CHECK-NO-UNSAFE-MATH: "-o" 201