------- Comment #6 from mmitchel at gcc dot gnu dot org 2006-06-05 22:37 ------- An even smaller test case is:
== struct A { A(const A&); A& operator=(const A&); void baz() volatile; }; void A::baz() volatile { *this; } == The problem is that the middle-end is creating a copy of an object of type A -- and C++ front-end has an assert designed to prevent exactly that, since copies are supposed to be done by the copy constructor. The code in the middle-end is in fact unsafe (and so we cannot just remove the C++ assert) because for: struct B { ... }; struct D : virtual public B { ... }; void f(volatile D* p) { *p; } the type of "*p" will be "D" -- but we cannot safely read sizeof (D) bytes from *p, as sizeof (D) includes the size of the virtual base, and the virtual base may be located elsewhere. (If X derives from D virtually, then the B part of X may be located in memory below the D part of X.) If the C++ front end said that "p" points only to a D-as-base (as agreed elsewhere would be a good idea), then the middle end would still do the wrong thing, as it would touch only part of *p. Therefore, for a TREE_ADDRESSABLE type, I don't think the middle-end can or should do anything for a volatile access. It should just ignore the volatility. Diego, what say you? -- mmitchel at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dnovillo at redhat dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26577