aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-08-09 17:53:18 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-08-25 21:04:11 +0200
commitcf773f6cf67c88731a77be96245b2a1600de94ff (patch)
tree2446b5aadb235ac5c9eb3f3d4408da7c43c7f156
parent418aa1fe4bd938f9028ef1f2a71bea56aa9ab3ad (diff)
downloadsparse-dev-cf773f6cf67c88731a77be96245b2a1600de94ff.tar.gz
fix: do not optimize away accesses to volatile bitfields
Accesses to volatiles must, of course, not be optimized away. For this, we need to check to type associated to the memory access. Currently this is done by checking if the type of the result of the memops is volatile or not. Usualy, the type of the result is the same as the one of the access so everything is good but for bitfields, the memop is not done with the type of the bitfield itself but to its base type. Since this base type is unrelated to the access type, it is generaly not marked as volatile even when the access to the bitfield is volatile. Fix this by using the true type of the access to set the field struct instruction::is_volatile. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--linearize.c4
-rw-r--r--validation/optim/volatile-bitfield.c1
2 files changed, 2 insertions, 3 deletions
diff --git a/linearize.c b/linearize.c
index fc4c4271..c4f38456 100644
--- a/linearize.c
+++ b/linearize.c
@@ -991,7 +991,7 @@ static pseudo_t add_load(struct entrypoint *ep, struct access_data *ad)
insn->target = new;
insn->offset = ad->offset;
- insn->is_volatile = insn->type && (insn->type->ctype.modifiers & MOD_VOLATILE);
+ insn->is_volatile = ad->type && (ad->type->ctype.modifiers & MOD_VOLATILE);
use_pseudo(insn, ad->address, &insn->src);
add_one_insn(ep, insn);
return new;
@@ -1007,7 +1007,7 @@ static void add_store(struct entrypoint *ep, struct access_data *ad, pseudo_t va
store = alloc_typed_instruction(OP_STORE, ad->btype);
store->offset = ad->offset;
- store->is_volatile = store->type && (store->type->ctype.modifiers & MOD_VOLATILE);
+ store->is_volatile = ad->type && (ad->type->ctype.modifiers & MOD_VOLATILE);
use_pseudo(store, value, &store->target);
use_pseudo(store, ad->address, &store->src);
add_one_insn(ep, store);
diff --git a/validation/optim/volatile-bitfield.c b/validation/optim/volatile-bitfield.c
index c28efb09..99db4401 100644
--- a/validation/optim/volatile-bitfield.c
+++ b/validation/optim/volatile-bitfield.c
@@ -10,7 +10,6 @@ void foo(volatile struct s *p)
/*
* check-name: volatile-bitfield
* check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
*
* check-output-ignore
* check-output-contains: load\\.