xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/bitfield-assign.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc /* Check that the result of a bitfield assignment is properly
2*f4a2713aSLionel Sambuc    truncated and does not generate a redundant load. */
3*f4a2713aSLionel Sambuc 
4*f4a2713aSLionel Sambuc /* Check that we get one load for each simple assign and two for the
5*f4a2713aSLionel Sambuc    compound assign (load the old value before the add then load again
6*f4a2713aSLionel Sambuc    to store back). Also check that our g0 pattern is good. */
7*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -o %t %s
8*f4a2713aSLionel Sambuc // RUN: grep 'load ' %t | count 5
9*f4a2713aSLionel Sambuc // RUN: grep "@g0" %t | count 4
10*f4a2713aSLionel Sambuc 
11*f4a2713aSLionel Sambuc // Check that we got the right value.
12*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple i386-unknown-unknown -O3 -emit-llvm -o %t %s
13*f4a2713aSLionel Sambuc // RUN: not grep 'load ' %t
14*f4a2713aSLionel Sambuc // RUN: not grep "@g0" %t
15*f4a2713aSLionel Sambuc 
16*f4a2713aSLionel Sambuc struct s0 {
17*f4a2713aSLionel Sambuc   int f0 : 2;
18*f4a2713aSLionel Sambuc   _Bool f1 : 1;
19*f4a2713aSLionel Sambuc   unsigned f2 : 2;
20*f4a2713aSLionel Sambuc };
21*f4a2713aSLionel Sambuc 
22*f4a2713aSLionel Sambuc int g0();
23*f4a2713aSLionel Sambuc 
f0(void)24*f4a2713aSLionel Sambuc void f0(void) {
25*f4a2713aSLionel Sambuc   struct s0 s;
26*f4a2713aSLionel Sambuc   if ((s.f0 = 3) != -1) g0();
27*f4a2713aSLionel Sambuc }
28*f4a2713aSLionel Sambuc 
f1(void)29*f4a2713aSLionel Sambuc void f1(void) {
30*f4a2713aSLionel Sambuc   struct s0 s;
31*f4a2713aSLionel Sambuc   if ((s.f1 = 3) != 1) g0();
32*f4a2713aSLionel Sambuc }
33*f4a2713aSLionel Sambuc 
f2(void)34*f4a2713aSLionel Sambuc void f2(void) {
35*f4a2713aSLionel Sambuc   struct s0 s;
36*f4a2713aSLionel Sambuc   if ((s.f2 = 3) != 3) g0();
37*f4a2713aSLionel Sambuc }
38*f4a2713aSLionel Sambuc 
f3(void)39*f4a2713aSLionel Sambuc void f3(void) {
40*f4a2713aSLionel Sambuc   struct s0 s;
41*f4a2713aSLionel Sambuc   // Just check this one for load counts.
42*f4a2713aSLionel Sambuc   s.f0 += 3;
43*f4a2713aSLionel Sambuc }
44*f4a2713aSLionel Sambuc 
45