This is the mail archive of the
mailing list for the GCC project.
Re: [gimple] assignments to volatile
- From: Richard Guenther <richard dot guenther at gmail dot com>
- To: Nathan Sidwell <nathan at codesourcery dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 21 Jun 2010 14:07:54 +0200
- Subject: Re: [gimple] assignments to volatile
- References: <4C1F5380.firstname.lastname@example.org>
On Mon, Jun 21, 2010 at 1:56 PM, Nathan Sidwell <email@example.com> wrote:
> I've come across inconsistent and surprising behaviour when assigning to
> volatile lvalues.
> Sometimes we re-read the assigned-to object, and sometimes we do not. ?For
> ? return vobj = data;
> will cause a reread of vobj, IF data is not a constant.
> ?cond ? vobj = data : 0
> will cause a reread of vobj, even when we don't use the result of the
> conditional expression -- unless data is a constant, in which case there is
> no-reread. ?(And confusingly, if you put void casts inside the two
> conditional sub-expressions, the re-reading goes away, but it doesn't even
> when you explicitly cast the whole expression to void).
> In the attached testcase, test_1, test_6 and test_7 have this surprising
> rereading behaviour.
> The fault appears to be in gimplify_modify_expr, where we return the LHS as
> the value, if the caller wants the value. ?The attached patch changes that
> routine when the target lvalue is volatile. ?In that case it will create a
> temporary to hold the RHS value, assign that temporary to the LHS and then
> return the temporary.
> Although the bug is architecture-neutral, the testcase is x86-specific
> because it's checking for specific accesses occurring.
> built and tested on i686-pc-linux-gnu, ok?
Hm, TREE_THIS_VOLATILE (TREE_TYPE (*to_p)) should
certainly be TREE_THIS_VOLATILE (*to_p), and all this
should be done after gimplifying *to_p. I think even just
before we build the gimple assign/call do
if (TREE_THIS_VOLATILE (*to_p) && want_value)
*from_p = get_initialized_tmp_var (*from_p, pre_p, post_p);
*expr_p = unshare_expr (*to_p);
*expr_p = TREE_THIS_VOLATILE (*to_p) ? *from_p : unshare_expr (*to_p);