diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2012-01-02 14:19:45 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2012-01-02 14:19:45 +0000 |
commit | abf07a7fb669dcb74040eef948d61dfe3c59ff17 (patch) | |
tree | 07bd4265036179237cb2cc51c788e48912716537 /test/Driver/fast-math.c | |
parent | 1e8a0678df724a28fe47e0034246f2604056a278 (diff) | |
download | clang-abf07a7fb669dcb74040eef948d61dfe3c59ff17.tar.gz clang-abf07a7fb669dcb74040eef948d61dfe3c59ff17.tar.bz2 clang-abf07a7fb669dcb74040eef948d61dfe3c59ff17.tar.xz |
Fix PR11685 by implementing -ffast-math and its various friends in the
Clang driver. This involves a bunch of silly option parsing code to try
to carefully emulate GCC's options. Currently, this takes a conservative
approach, and unless all of the unsafe optimizations are enabled, none
of them are. The fine grained control doesn't seem particularly useful.
If it ever becomes useful, we can add that to LLVM first, and then
expose it here.
This also fixes a few tiny bugs in the flag management around
-fhonor-infinities and -fhonor-nans; the flags now form proper sets both
for enabling and disabling, with the last flag winning.
I've also implemented a moderately terrifying GCC feature where
a language change is also provided by the '-ffast-math' flag by defining
the __FAST_MATH__ preprocessor macro. This feature is tracked and
serialized in the frontend but it isn't used yet. A subsequent patch
will add the preprocessor macro and tests for it.
I've manually tested that codegen appears to respect this, but I've not
dug in enough to see if there is an easy way to test codegen options w/o
relying on the particulars of LLVM's optimizations.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147434 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Driver/fast-math.c')
-rw-r--r-- | test/Driver/fast-math.c | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/test/Driver/fast-math.c b/test/Driver/fast-math.c new file mode 100644 index 0000000000..aef7cc3624 --- /dev/null +++ b/test/Driver/fast-math.c @@ -0,0 +1,119 @@ +// Test that the GCC fast-math floating point flags get lowered to the correct +// permutation of Clang frontend flags. This is non-trivial for a few reasons. +// First, the GCC flags have many different and surprising effects. Second, +// LLVM only supports three switches which is more coarse grained than GCC's +// support. +// +// RUN: %clang -### -fno-honor-infinities -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-INFS %s +// CHECK-NO-INFS: "-cc1" +// CHECK-NO-INFS: "-menable-no-infs" +// +// RUN: %clang -### -fno-honor-nans -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-NANS %s +// CHECK-NO-NANS: "-cc1" +// CHECK-NO-NANS: "-menable-no-nans" +// +// RUN: %clang -### -fmath-errno -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-MATH-ERRNO %s +// CHECK-MATH-ERRNO: "-cc1" +// CHECK-MATH-ERRNO: "-fmath-errno" +// +// RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \ +// RUN: -fno-trapping-math -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-UNSAFE-MATH %s +// CHECK-UNSAFE-MATH: "-cc1" +// CHECK-UNSAFE-MATH: "-menable-unsafe-fp-math" +// +// Check that various umbrella flags also enable these frontend options. +// RUN: %clang -### -ffast-math -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-INFS %s +// RUN: %clang -### -ffast-math -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-NANS %s +// RUN: %clang -### -ffast-math -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-UNSAFE-MATH %s +// RUN: %clang -### -ffinite-math-only -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-INFS %s +// RUN: %clang -### -ffinite-math-only -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-NANS %s +// RUN: %clang -### -funsafe-math-optimizations -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-UNSAFE-MATH %s +// +// One umbrella flag is *really* weird and also changes the semantics of the +// program by adding a special preprocessor macro. Check that the frontend flag +// modeling this semantic change is provided. Also check that the semantic +// impact remains even if every optimization is disabled. +// RUN: %clang -### -ffast-math -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FAST-MATH %s +// RUN: %clang -### -ffast-math -fno-finite-math-only \ +// RUN: -fno-unsafe-math-optimizations -fmath-errno -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FAST-MATH %s +// CHECK-FAST-MATH: "-cc1" +// CHECK-FAST-MATH: "-ffast-math" +// +// Check various means of disabling these flags, including disabling them after +// they've been enabled via an umbrella flag. +// RUN: %clang -### -fno-honor-infinities -fhonor-infinities -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-NO-INFS %s +// RUN: %clang -### -ffinite-math-only -fhonor-infinities -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-NO-INFS %s +// RUN: %clang -### -ffinite-math-only -fno-finite-math-only -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-NO-INFS %s +// RUN: %clang -### -ffast-math -fhonor-infinities -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-NO-INFS %s +// RUN: %clang -### -ffast-math -fno-finite-math-only -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-NO-INFS %s +// CHECK-NO-NO-INFS: "-cc1" +// CHECK-NO-NO-INFS-NOT: "-menable-no-infs" +// CHECK-NO-NO-INFS: "-o" +// +// RUN: %clang -### -fno-honor-nans -fhonor-nans -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-NO-NANS %s +// RUN: %clang -### -ffinite-math-only -fhonor-nans -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-NO-NANS %s +// RUN: %clang -### -ffinite-math-only -fno-finite-math-only -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-NO-NANS %s +// RUN: %clang -### -ffast-math -fhonor-nans -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-NO-NANS %s +// RUN: %clang -### -ffast-math -fno-finite-math-only -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-NO-NANS %s +// CHECK-NO-NO-NANS: "-cc1" +// CHECK-NO-NO-NANS-NOT: "-menable-no-nans" +// CHECK-NO-NO-NANS: "-o" +// +// RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \ +// RUN: -fno-trapping-math -fno-associative-math -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s +// RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \ +// RUN: -fno-trapping-math -fno-reciprocal-math -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s +// RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \ +// RUN: -fno-trapping-math -fsigned-zeros -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s +// RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \ +// RUN: -fno-trapping-math -ftrapping-math -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s +// RUN: %clang -### -funsafe-math-optimizations -fno-associative-math -c %s \ +// RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s +// RUN: %clang -### -funsafe-math-optimizations -fno-reciprocal-math -c %s \ +// RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s +// RUN: %clang -### -funsafe-math-optimizations -fsigned-zeros -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s +// RUN: %clang -### -funsafe-math-optimizations -ftrapping-math -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s +// RUN: %clang -### -funsafe-math-optimizations -fno-unsafe-math-optimizations \ +// RUN: -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s +// RUN: %clang -### -ffast-math -fno-associative-math -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s +// RUN: %clang -### -ffast-math -fno-reciprocal-math -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s +// RUN: %clang -### -ffast-math -fsigned-zeros -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s +// RUN: %clang -### -ffast-math -ftrapping-math -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s +// RUN: %clang -### -ffast-math -fno-unsafe-math-optimizations -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s +// CHECK-NO-UNSAFE-MATH: "-cc1" +// CHECK-NO-UNSAFE-MATH-NOT: "-menable-unsafe-fp-math" +// CHECK-NO-UNSAFE-MATH: "-o" |