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