This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [gimple] assignments to volatile


On Mon, Jun 21, 2010 at 1:56 PM, Nathan Sidwell <nathan@codesourcery.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
> instance,
> ? return vobj = data;
> will cause a reread of vobj, IF data is not a constant.
> or
> ?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);

and change

  if (want_value)
    {
      *expr_p = unshare_expr (*to_p);
      return GS_OK;

to

  if (want_value)
    {
      *expr_p = TREE_THIS_VOLATILE (*to_p) ? *from_p : unshare_expr (*to_p);
      return GS_O;

Richard.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]