This is the mail archive of the gcc@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]

[optimization/6059] -fvolatile-*: fix or kill?


Sorry if this has been covered before, but...

As optimization/6059 says, -fvolatile-global and -fvolatile-static
don't work any more.  Test case:

    int x;
    void foo () { while (x); }

Compile with -O2 -fvolatile-global and the load of 'x' is hoisted.

I think the change came with:

    <http://gcc.gnu.org/ml/gcc-patches/2000-05/msg01680.html>

Before the patch we had (varasm.c:make_decl_rtl, gcc 2.95.3):

	  /* If this variable is to be treated as volatile, show its
	     tree node has side effects.  If it has side effects, either
	     because of this test or from TREE_THIS_VOLATILE also
	     being set, show the MEM is volatile.  */
	  if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
	      && TREE_PUBLIC (decl))
	    TREE_SIDE_EFFECTS (decl) = 1;
	  else if (flag_volatile_static && TREE_CODE (decl) == VAR_DECL
	       && (TREE_PUBLIC (decl) || TREE_STATIC (decl)))
	    TREE_SIDE_EFFECTS (decl) = 1;

	  if (TREE_SIDE_EFFECTS (decl))
	    MEM_VOLATILE_P (DECL_RTL (decl)) = 1;

The patch removes the last two lines and uses the new
set_mem_attributes() instead.  This new code takes MEM_VOLATILE_P
from the decl's type (i.e. TYPE_VOLATILE (TREE_TYPE (decl)))
rather than TREE_SIDE_EFFECTS.

So:

- 2.95 handled the test case correctly but I don't think any 3.x
  release did.  Certainly 3.0.4 had the same problem as trunk.

- 6059 seems to be the only report about the problem in all this time.
  The options can't be _that_ widely used.

- The options (intentionally?) mark variables as volatile without giving
  them a volatile type.  In the test case, 'x' is a volatile value but
  '&x' is a plain 'int *'.  You won't get warnings about:

      void bar () { int *y = &x; while (*y); }

  despite the obvious bad effects.  (You would of course get a warning
  if 'x' were explicitly declared volatile.)

Given which, is it OK to just remove the options?  I'll prepare
a patch if so...

Richard


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