207
|
1 // RUN: %clang_cc1 -triple x86_64-linux -std=c17 -verify=expected,norounding %s
|
|
2 // RUN: %clang_cc1 -triple x86_64-linux -std=gnu17 -verify=expected,norounding %s
|
|
3 // RUN: %clang_cc1 -triple x86_64-linux -std=c17 -verify=expected,rounding %s -frounding-math
|
|
4 // RUN: %clang_cc1 -triple x86_64-linux -std=gnu17 -verify=expected,rounding %s -frounding-math
|
|
5
|
|
6 #define fold(x) (__builtin_constant_p(x) ? (x) : (x))
|
|
7
|
|
8 double a = 1.0 / 3.0;
|
|
9
|
|
10 #define f(n) ((n) * (1.0 / 3.0))
|
|
11 _Static_assert(fold((int)f(3)) == 1, "");
|
|
12
|
|
13 typedef int T[fold((int)f(3))];
|
|
14 typedef int T[1];
|
|
15
|
|
16 enum Enum { enum_a = (int)f(3) };
|
|
17
|
|
18 struct Bitfield {
|
|
19 unsigned int n : 1;
|
|
20 unsigned int m : fold((int)f(3));
|
|
21 };
|
|
22
|
|
23 void bitfield(struct Bitfield *b) {
|
|
24 b->n = (int)(6 * (1.0 / 3.0)); // norounding-warning {{changes value from 2 to 0}}
|
|
25 }
|
|
26
|
|
27 void vlas() {
|
|
28 // This is always a VLA due to its syntactic form.
|
|
29 typedef int vla1[(int)(-3 * (1.0 / 3.0))];
|
|
30 struct X1 { vla1 v; }; // expected-error {{fields must have a constant size}}
|
|
31
|
|
32 // This is always folded to a constant.
|
|
33 typedef int vla2[fold((int)(-3 * (1.0 / 3.0)))]; // expected-error {{negative size}}
|
|
34 struct X2 { vla2 v; };
|
|
35 }
|