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

[Bug tree-optimization/22000] [4.0 Regression] Read from volatile member of struct is optimized away


------- 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


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