xref: /llvm-project/clang/test/Parser/pragma-fenv_access.c (revision 880fa7faa97bad63e403c924263b01fb81783227)
1 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -triple x86_64-linux-gnu -ffp-exception-behavior=strict -DSTRICT -fsyntax-only -verify %s
3 // RUN: %clang_cc1 -triple x86_64-linux-gnu -x c++ -DCPP -DSTRICT -ffp-exception-behavior=strict -fsyntax-only -verify %s
4 #ifdef CPP
5 #define CONST constexpr
6 #else
7 #define CONST const
8 #endif
9 
10 #pragma STDC FENV_ACCESS IN_BETWEEN   // expected-warning {{expected 'ON' or 'OFF' or 'DEFAULT' in pragma}}
11 
12 #pragma STDC FENV_ACCESS OFF
13 
func_04(int x,float y)14 float func_04(int x, float y) {
15   if (x)
16     return y + 2;
17   #pragma STDC FENV_ACCESS ON // expected-error{{'#pragma STDC FENV_ACCESS' can only appear at file scope or at the start of a compound statement}}
18   return x + y;
19 }
20 
21 #pragma STDC FENV_ACCESS ON
main(void)22 int main(void) {
23   CONST float one = 1.0F ;
24   CONST float three = 3.0F ;
25   CONST float four = 4.0F ;
26   CONST float frac_ok = one/four;
27 #if !defined(CPP)
28 //expected-note@+2 {{declared here}}
29 #endif
30   CONST float frac = one/three;
31   CONST double d = one;
32   CONST int not_too_big = 255;
33   CONST float fnot_too_big = not_too_big;
34   CONST int too_big = 0x7ffffff0;
35 #if defined(CPP)
36 //expected-warning@+2{{implicit conversion}}
37 #endif
38   CONST float fbig = too_big; // inexact
39 #if !defined(CPP)
40 #define static_assert _Static_assert
41 #endif
42 enum {
43   e1 = (int)one, e3 = (int)three, e4 = (int)four, e_four_quarters = (int)(frac_ok * 4)
44 };
45 static_assert(e1 == 1  && e3 == 3 && e4 == 4 && e_four_quarters == 1, "");
46 enum {
47 #if !defined(CPP)
48 // expected-error@+2 {{not an integer constant expression}} expected-note@+2 {{is not a constant expression}}
49 #endif
50   e_three_thirds = (int)(frac * 3)
51 };
52   if (one <= four)  return 0;
53   return -1;
54 }
55