annotate clang/test/Sema/rounding-math.c @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 // RUN: %clang_cc1 -triple x86_64-linux -std=c17 -verify=expected,norounding %s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 // RUN: %clang_cc1 -triple x86_64-linux -std=gnu17 -verify=expected,norounding %s
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 // RUN: %clang_cc1 -triple x86_64-linux -std=c17 -verify=expected,rounding %s -frounding-math
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 // RUN: %clang_cc1 -triple x86_64-linux -std=gnu17 -verify=expected,rounding %s -frounding-math
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 #define fold(x) (__builtin_constant_p(x) ? (x) : (x))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 double a = 1.0 / 3.0;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 #define f(n) ((n) * (1.0 / 3.0))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 _Static_assert(fold((int)f(3)) == 1, "");
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 typedef int T[fold((int)f(3))];
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 typedef int T[1];
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 enum Enum { enum_a = (int)f(3) };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 struct Bitfield {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 unsigned int n : 1;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 unsigned int m : fold((int)f(3));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 void bitfield(struct Bitfield *b) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 b->n = (int)(6 * (1.0 / 3.0)); // norounding-warning {{changes value from 2 to 0}}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 void vlas() {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 // This is always a VLA due to its syntactic form.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 typedef int vla1[(int)(-3 * (1.0 / 3.0))];
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 struct X1 { vla1 v; }; // expected-error {{fields must have a constant size}}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 // This is always folded to a constant.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 typedef int vla2[fold((int)(-3 * (1.0 / 3.0)))]; // expected-error {{negative size}}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 struct X2 { vla2 v; };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 }