diff options
author | Zancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au> | 2012-09-24 09:58:17 +1000 |
---|---|---|
committer | Zancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au> | 2012-09-24 09:58:17 +1000 |
commit | 222e2a7620e6520ffaf4fc4e69d79c18da31542e (patch) | |
tree | 7bfbc05bfa3b41c8f9d2e56d53a0bc3e310df239 /clang/test/CodeGen/bitfield-assign.c | |
parent | 3d206f03985b50beacae843d880bccdc91a9f424 (diff) |
Add the clang library to the repo (with some of my changes, too).
Diffstat (limited to 'clang/test/CodeGen/bitfield-assign.c')
-rw-r--r-- | clang/test/CodeGen/bitfield-assign.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/clang/test/CodeGen/bitfield-assign.c b/clang/test/CodeGen/bitfield-assign.c new file mode 100644 index 0000000..b8ab613 --- /dev/null +++ b/clang/test/CodeGen/bitfield-assign.c @@ -0,0 +1,44 @@ +/* Check that the result of a bitfield assignment is properly + truncated and does not generate a redundant load. */ + +/* Check that we get one load for each simple assign and two for the + compound assign (load the old value before the add then load again + to store back). Also check that our g0 pattern is good. */ +// RUN: %clang_cc1 -triple i386-unknown-unknown -O0 -emit-llvm -o %t %s +// RUN: grep 'load ' %t | count 5 +// RUN: grep "@g0" %t | count 4 + +// Check that we got the right value. +// RUN: %clang_cc1 -triple i386-unknown-unknown -O3 -emit-llvm -o %t %s +// RUN: grep 'load ' %t | count 0 +// RUN: grep "@g0" %t | count 0 + +struct s0 { + int f0 : 2; + _Bool f1 : 1; + unsigned f2 : 2; +}; + +int g0(); + +void f0(void) { + struct s0 s; + if ((s.f0 = 3) != -1) g0(); +} + +void f1(void) { + struct s0 s; + if ((s.f1 = 3) != 1) g0(); +} + +void f2(void) { + struct s0 s; + if ((s.f2 = 3) != 3) g0(); +} + +void f3(void) { + struct s0 s; + // Just check this one for load counts. + s.f0 += 3; +} + |