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@xxxxxxxxx> --- linearize.c | 4 ++-- validation/optim/volatile-bitfield.c | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/linearize.c b/linearize.c index 1444e655b..b27b04c4b 100644 --- a/linearize.c +++ b/linearize.c @@ -946,7 +946,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; @@ -962,7 +962,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 c28efb09a..99db44014 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\\. -- 2.18.0