blob: 867534e6a20da4c719819d740a2f5ce1d43937e6 [file] [log] [blame]
Serge Pavlov08bb5d92020-10-23 18:36:16 +07001// RUN: %clang_cc1 -triple x86_64-linux -verify=norounding -Wno-unknown-pragmas %s
2// RUN: %clang_cc1 -triple x86_64-linux -verify=rounding %s -frounding-math -Wno-unknown-pragmas
Richard Smith7e801ca2020-10-13 19:14:13 -07003// rounding-no-diagnostics
4
5#define fold(x) (__builtin_constant_p(x) ? (x) : (x))
6
7constexpr double a = 1.0 / 3.0;
8
9constexpr int f(int n) { return int(n * (1.0 / 3.0)); }
10
11using T = int[f(3)];
12using T = int[1];
13
14enum Enum { enum_a = f(3) };
15
16struct Bitfield {
17 unsigned int n : 1;
18 unsigned int m : f(3);
19};
20
21void f(Bitfield &b) {
22 b.n = int(6 * (1.0 / 3.0)); // norounding-warning {{changes value from 2 to 0}}
23}
24
25const int k = 3 * (1.0 / 3.0);
26static_assert(k == 1, "");
27
28void g() {
29 // FIXME: Constant-evaluating this initializer is surprising, and violates
30 // the recommended practice in C++ [expr.const]p12:
31 //
32 // Implementations should provide consistent results of floating-point
33 // evaluations, irrespective of whether the evaluation is performed during
34 // translation or during program execution.
35 const int k = 3 * (1.0 / 3.0);
36 static_assert(k == 1, "");
37}
38
39int *h() {
40 return new int[int(-3 * (1.0 / 3.0))]; // norounding-error {{too large}}
41}
Serge Pavlov08bb5d92020-10-23 18:36:16 +070042
43
44// nextUp(1.F) == 0x1.000002p0F
45static_assert(1.0F + 0x0.000001p0F == 0x1.0p0F, "");
46
47char Arr01[1 + (1.0F + 0x0.000001p0F > 1.0F)];
48static_assert(sizeof(Arr01) == 1, "");
49
50struct S1 {
51 int : (1.0F + 0x0.000001p0F > 1.0F);
52 int f;
53};
54static_assert(sizeof(S1) == sizeof(int), "");
55
56#pragma STDC FENV_ROUND FE_UPWARD
57static_assert(1.0F + 0x0.000001p0F == 0x1.000002p0F, "");
58
59char Arr01u[1 + (1.0F + 0x0.000001p0F > 1.0F)];
60static_assert(sizeof(Arr01u) == 2, "");
61
62struct S1u {
63 int : (1.0F + 0x0.000001p0F > 1.0F);
64 int f;
65};
66static_assert(sizeof(S1u) > sizeof(int), "");
67
68#pragma STDC FENV_ROUND FE_DOWNWARD
69static_assert(1.0F + 0x0.000001p0F == 1.0F, "");
70
71char Arr01d[1 + (1.0F + 0x0.000001p0F > 1.0F)];
72static_assert(sizeof(Arr01d) == 1, "");
73
74struct S1d {
75 int : (1.0F + 0x0.000001p0F > 1.0F);
76 int f;
77};
78static_assert(sizeof(S1d) == sizeof(int), "");