blob: 40b60cbcd6604b23be23acc1ae8a435b8a2ee70d [file] [log] [blame]
Chandler Carruthabf07a72012-01-02 14:19:45 +00001// 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// RUN: %clang -### -fno-honor-infinities -c %s 2>&1 \
8// RUN: | FileCheck --check-prefix=CHECK-NO-INFS %s
9// CHECK-NO-INFS: "-cc1"
10// CHECK-NO-INFS: "-menable-no-infs"
11//
12// RUN: %clang -### -fno-honor-nans -c %s 2>&1 \
13// RUN: | FileCheck --check-prefix=CHECK-NO-NANS %s
14// CHECK-NO-NANS: "-cc1"
15// CHECK-NO-NANS: "-menable-no-nans"
16//
17// RUN: %clang -### -fmath-errno -c %s 2>&1 \
18// RUN: | FileCheck --check-prefix=CHECK-MATH-ERRNO %s
19// CHECK-MATH-ERRNO: "-cc1"
20// CHECK-MATH-ERRNO: "-fmath-errno"
21//
Chandler Carruth4f50c502012-04-26 02:10:51 +000022// RUN: %clang -### -fmath-errno -fno-math-errno -c %s 2>&1 \
23// RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
24// RUN: %clang -### -target i686-apple-darwin -c %s 2>&1 \
25// RUN: | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
26// CHECK-NO-MATH-ERRNO: "-cc1"
27// CHECK-NO-MATH-ERRNO-NOT: "-fmath-errno"
28//
29// RUN: %clang -### -fno-math-errno -fassociative-math -freciprocal-math \
30// RUN: -fno-signed-zeros -fno-trapping-math -c %s 2>&1 \
Chandler Carruthabf07a72012-01-02 14:19:45 +000031// RUN: | FileCheck --check-prefix=CHECK-UNSAFE-MATH %s
32// CHECK-UNSAFE-MATH: "-cc1"
33// CHECK-UNSAFE-MATH: "-menable-unsafe-fp-math"
34//
35// Check that various umbrella flags also enable these frontend options.
36// RUN: %clang -### -ffast-math -c %s 2>&1 \
37// RUN: | FileCheck --check-prefix=CHECK-NO-INFS %s
38// RUN: %clang -### -ffast-math -c %s 2>&1 \
39// RUN: | FileCheck --check-prefix=CHECK-NO-NANS %s
40// RUN: %clang -### -ffast-math -c %s 2>&1 \
41// RUN: | FileCheck --check-prefix=CHECK-UNSAFE-MATH %s
42// RUN: %clang -### -ffinite-math-only -c %s 2>&1 \
43// RUN: | FileCheck --check-prefix=CHECK-NO-INFS %s
44// RUN: %clang -### -ffinite-math-only -c %s 2>&1 \
45// RUN: | FileCheck --check-prefix=CHECK-NO-NANS %s
Chandler Carruth4f50c502012-04-26 02:10:51 +000046// RUN: %clang -### -funsafe-math-optimizations -fno-math-errno -c %s 2>&1 \
Chandler Carruthabf07a72012-01-02 14:19:45 +000047// RUN: | FileCheck --check-prefix=CHECK-UNSAFE-MATH %s
48//
49// One umbrella flag is *really* weird and also changes the semantics of the
50// program by adding a special preprocessor macro. Check that the frontend flag
51// modeling this semantic change is provided. Also check that the semantic
52// impact remains even if every optimization is disabled.
53// RUN: %clang -### -ffast-math -c %s 2>&1 \
54// RUN: | FileCheck --check-prefix=CHECK-FAST-MATH %s
55// RUN: %clang -### -ffast-math -fno-finite-math-only \
56// RUN: -fno-unsafe-math-optimizations -fmath-errno -c %s 2>&1 \
57// RUN: | FileCheck --check-prefix=CHECK-FAST-MATH %s
58// CHECK-FAST-MATH: "-cc1"
59// CHECK-FAST-MATH: "-ffast-math"
60//
61// Check various means of disabling these flags, including disabling them after
62// they've been enabled via an umbrella flag.
63// RUN: %clang -### -fno-honor-infinities -fhonor-infinities -c %s 2>&1 \
64// RUN: | FileCheck --check-prefix=CHECK-NO-NO-INFS %s
65// RUN: %clang -### -ffinite-math-only -fhonor-infinities -c %s 2>&1 \
66// RUN: | FileCheck --check-prefix=CHECK-NO-NO-INFS %s
67// RUN: %clang -### -ffinite-math-only -fno-finite-math-only -c %s 2>&1 \
68// RUN: | FileCheck --check-prefix=CHECK-NO-NO-INFS %s
69// RUN: %clang -### -ffast-math -fhonor-infinities -c %s 2>&1 \
70// RUN: | FileCheck --check-prefix=CHECK-NO-NO-INFS %s
71// RUN: %clang -### -ffast-math -fno-finite-math-only -c %s 2>&1 \
72// RUN: | FileCheck --check-prefix=CHECK-NO-NO-INFS %s
73// CHECK-NO-NO-INFS: "-cc1"
74// CHECK-NO-NO-INFS-NOT: "-menable-no-infs"
75// CHECK-NO-NO-INFS: "-o"
76//
77// RUN: %clang -### -fno-honor-nans -fhonor-nans -c %s 2>&1 \
78// RUN: | FileCheck --check-prefix=CHECK-NO-NO-NANS %s
79// RUN: %clang -### -ffinite-math-only -fhonor-nans -c %s 2>&1 \
80// RUN: | FileCheck --check-prefix=CHECK-NO-NO-NANS %s
81// RUN: %clang -### -ffinite-math-only -fno-finite-math-only -c %s 2>&1 \
82// RUN: | FileCheck --check-prefix=CHECK-NO-NO-NANS %s
83// RUN: %clang -### -ffast-math -fhonor-nans -c %s 2>&1 \
84// RUN: | FileCheck --check-prefix=CHECK-NO-NO-NANS %s
85// RUN: %clang -### -ffast-math -fno-finite-math-only -c %s 2>&1 \
86// RUN: | FileCheck --check-prefix=CHECK-NO-NO-NANS %s
87// CHECK-NO-NO-NANS: "-cc1"
88// CHECK-NO-NO-NANS-NOT: "-menable-no-nans"
89// CHECK-NO-NO-NANS: "-o"
90//
91// RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \
92// RUN: -fno-trapping-math -fno-associative-math -c %s 2>&1 \
93// RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
94// RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \
95// RUN: -fno-trapping-math -fno-reciprocal-math -c %s 2>&1 \
96// RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
97// RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \
98// RUN: -fno-trapping-math -fsigned-zeros -c %s 2>&1 \
99// RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
100// RUN: %clang -### -fassociative-math -freciprocal-math -fno-signed-zeros \
101// RUN: -fno-trapping-math -ftrapping-math -c %s 2>&1 \
102// RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
103// RUN: %clang -### -funsafe-math-optimizations -fno-associative-math -c %s \
104// RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
105// RUN: %clang -### -funsafe-math-optimizations -fno-reciprocal-math -c %s \
106// RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
107// RUN: %clang -### -funsafe-math-optimizations -fsigned-zeros -c %s 2>&1 \
108// RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
109// RUN: %clang -### -funsafe-math-optimizations -ftrapping-math -c %s 2>&1 \
110// RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
111// RUN: %clang -### -funsafe-math-optimizations -fno-unsafe-math-optimizations \
112// RUN: -c %s 2>&1 \
113// RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
114// RUN: %clang -### -ffast-math -fno-associative-math -c %s 2>&1 \
115// RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
116// RUN: %clang -### -ffast-math -fno-reciprocal-math -c %s 2>&1 \
117// RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
118// RUN: %clang -### -ffast-math -fsigned-zeros -c %s 2>&1 \
119// RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
120// RUN: %clang -### -ffast-math -ftrapping-math -c %s 2>&1 \
121// RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
122// RUN: %clang -### -ffast-math -fno-unsafe-math-optimizations -c %s 2>&1 \
123// RUN: | FileCheck --check-prefix=CHECK-NO-UNSAFE-MATH %s
124// CHECK-NO-UNSAFE-MATH: "-cc1"
125// CHECK-NO-UNSAFE-MATH-NOT: "-menable-unsafe-fp-math"
126// CHECK-NO-UNSAFE-MATH: "-o"