* [optimization/6059] -fvolatile-*: fix or kill?
@ 2003-01-16 15:31 Richard Sandiford
2003-01-16 23:47 ` Graham Stott
0 siblings, 1 reply; 2+ messages in thread
From: Richard Sandiford @ 2003-01-16 15:31 UTC (permalink / raw)
To: gcc
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [optimization/6059] -fvolatile-*: fix or kill?
2003-01-16 15:31 [optimization/6059] -fvolatile-*: fix or kill? Richard Sandiford
@ 2003-01-16 23:47 ` Graham Stott
0 siblings, 0 replies; 2+ messages in thread
From: Graham Stott @ 2003-01-16 23:47 UTC (permalink / raw)
To: Richard Sandiford; +Cc: gcc
Richard Sandiford wrote:
> 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.
>
There also the related option
-fvolatile Consider all mem refs through pointers as volatile
I would vote to purge them any idea when they were added?
Cheers
Graham
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-01-16 21:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-16 15:31 [optimization/6059] -fvolatile-*: fix or kill? Richard Sandiford
2003-01-16 23:47 ` Graham Stott
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).