This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/22000] [4.0 Regression] Read from volatile member of struct is optimized away
- From: "rpedersen at atmel dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 13 Jun 2005 11:56:04 -0000
- Subject: [Bug tree-optimization/22000] [4.0 Regression] Read from volatile member of struct is optimized away
- References: <20050610135925.22000.rpedersen@atmel.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From rpedersen at atmel dot com 2005-06-13 11:56 -------
(In reply to comment #5)
> (In reply to comment #0)
> > I think that the C standard says C that the "name" of variable
> > becomes an rvalue (the actual value) thus requires that the variable
> > is accessed.
>
> It actually says that accessing a volatile qualified object through a
nonvolatile
> qualified lvalue (as would be the case if referenced via a non-volatile
qualified
> cast expression) is implementation defined.
>
If you are correct, the proposed testcase might be misleading.
Changing the expression for accessing the volatile member
of the struct to:
"(volatile int)ptr->b;"
or just:
"ptr->b;"
still leads to the access being optimized away.
> Personally, it seems more consistent to abide by the semantics specified
> by a programmer's explicit cast expression, thereby if given:
>
> int x, y;
> const int *z;
>
> x = (volatile int)y; // specifies a reference to a volatile int object.
>
> z = &(const int)x; // specifies a reference to a const int object.
>
> And correspondingly:
>
> int x;
> volatile int y;
> const int z;
>
> x = (int)y; // cast's away volatile (therefore may be optimized away),
> // therefore if not desired, shouldn't be "cast away".
>
> (int)z = x; // cast's away const (although may generate a run-time
> // exception if referencing a READONLY allocated object),
> // therefore if not desired, shouldn't be "cast away".
>
I agree with you on this.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22000