fix size of loaded bitfields
commit522773d089700cce5551860aea3cb93f40b5f3a4
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>
Mon, 27 Feb 2017 09:27:49 +0000 (27 10:27 +0100)
committerChristopher Li <sparse@chrisli.org>
Fri, 3 Mar 2017 16:45:38 +0000 (4 00:45 +0800)
tree815d74e8bb097518194f53707d7f1260800a27ae
parentb8c268640114d614178d4875fbe0f5e6b53b036b
fix size of loaded bitfields

Loading a bitfield correctly take in account the offset
of the bitfield inside the whole container integer.
But truncating it to the width of the bitfield is not done
or is done very implicitely (because the correct size is not lost).
For example, with the following code:
struct bfu {
unsigned int a:3;
};
unsigned int get__bfu_a(struct bfu bf) { return bf.a; }

test-linearize gives as output something like:
get__bfu_a:
cast.32     %r2 <- (3) %arg1
ret.32      %r2

We can notice the (3) in the cast instruction but this is misleading
as %arg1 is not 3bit wide.

Fix this by adding the missing truncating cast.
This will then gives something like:
get__bfu_a:
cast.3      %r2 <- (32) %arg1
cast.32     %r3 <- (3) %r2
ret.32      %r3

Note the truncation could also be done by a and-mask but the cast
is more logical since we're here only changing size and not doing
some arithmetic operations.

Fixes: 1688f039c ("Re-do memory access linearization.")
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Signed-off-by: Christopher Li <sparse@chrisli.org>
linearize.c
validation/bitfield-size.c [new file with mode: 0644]