xref: /llvm-project/clang/test/Parser/fp-floatcontrol-syntax.cpp (revision f5360d4bb3376347479d86547d21b95d80be786d)
1 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -DCHECK_ERROR %s -verify
2 
3 float function_scope(float a) {
4 #pragma float_control(precise, on) junk // expected-warning {{extra tokens at end of '#pragma float_control' - ignored}}
5   return a;
6 }
7 
8 #ifdef CHECK_ERROR
9 #pragma float_control(push)
10 #pragma float_control(pop)
11 #pragma float_control(precise, on, push)
12 void check_stack() {
13 #pragma float_control(push)                   // expected-error {{can only appear at file scope}}
14 #pragma float_control(pop)                    // expected-error {{can only appear at file scope}}
15 #pragma float_control(precise, on, push)      // expected-error {{can only appear at file scope}}
16 #pragma float_control(except, on, push)       // expected-error {{can only appear at file scope}}
17 #pragma float_control(except, on, push, junk) // expected-error {{float_control is malformed}}
18   return;
19 }
20 #endif
21 
22 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fdenormal-fp-math=preserve-sign,preserve-sign -ftrapping-math -fsyntax-only %s -DDEFAULT -verify
23 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only %s -ffp-contract=fast -DPRECISE -verify
24 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only %s -ftrapping-math -ffp-contract=off -frounding-math -ffp-exception-behavior=strict -DSTRICT -verify
25 // RUN: %clang_cc1 -triple x86_64-linux-gnu -menable-no-infs -menable-no-nans -menable-unsafe-fp-math -fno-signed-zeros -mreassociate -freciprocal-math -ffp-contract=fast -ffast-math -ffinite-math-only -fsyntax-only %s -DFAST -verify
26 double a = 0.0;
27 double b = 1.0;
28 
29 //FIXME At some point this warning will be removed, until then
30 //      document the warning
31 #ifdef FAST
32 // expected-warning@+1{{pragma STDC FENV_ACCESS ON is not supported, ignoring pragma}}
33 #pragma STDC FENV_ACCESS ON // expected-error{{'#pragma STDC FENV_ACCESS ON' is illegal when precise is disabled}}
34 #else
35 #pragma STDC FENV_ACCESS ON // expected-warning{{pragma STDC FENV_ACCESS ON is not supported, ignoring pragma}}
36 #endif
37 #ifdef STRICT
38 #pragma float_control(precise, off) // expected-error {{'#pragma float_control(precise, off)' is illegal when except is enabled}}
39 #else
40 #pragma float_control(precise, off) // expected-error {{'#pragma float_control(precise, off)' is illegal when fenv_access is enabled}}
41 #endif
42 
43 #pragma float_control(precise, on)
44 #pragma float_control(except, on) // OK
45 #ifndef STRICT
46 #pragma float_control(except, on)
47 #pragma float_control(precise, off) // expected-error {{'#pragma float_control(precise, off)' is illegal when except is enabled}}
48 #endif
49 int main() {
50 #ifdef STRICT
51 #pragma float_control(precise, off) // expected-error {{'#pragma float_control(precise, off)' is illegal when except is enabled}}
52 #else
53 #pragma float_control(precise, off) // expected-error {{'#pragma float_control(precise, off)' is illegal when except is enabled}}
54 #endif
55 #pragma float_control(except, on)
56   //  error: '#pragma float_control(except, on)' is illegal when precise is disabled
57   double x = b / a; // only used for fp flag setting
58   if (a == a)       // only used for fp flag setting
59     return 0;       //(int)x;
60 }
61