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