On Wed, 2005-05-11 at 15:30 -0700, Mark Mitchell wrote:
> Wolfgang Bangerth wrote:
> > Mark,
> > it occurred to me that asking the question you pose may use language that 
> > is 
> > more unfamiliar than necessary. How about this question instead -- assume
> > 
> >   struct S { int s; };
> >   struct X {
> >     int i;
> >     struct S s;
> >   };
> > 
> >   void g(struct S*);
> >   void f() {
> >     X x;
> >     g(&x.s);
> >   }
> > 
> > Would the compiler be allowed to realize that X::i is never referenced and 
> > therefore a dead variable? I assume the compiler doesn't do that right now, 
> > but it would be straightforward for a scalar replacement algorithm to not 
> > even allocate stack space for X::i, but only X::s, and hand the address of 
> > the only remaining stack object, of type S, to g().
> 
> I agree that this is the same issue, in another guise.  My point of view 
> is that this optimization would not be valid, pending clarification of 
> the issues we've been discussing.  As soon as any component of "x" is 
> addressed, we must assume that all of "x" is addressed -- unless we can 
> prove otherwise, by, say, looking at the body of "g".

Just a slightly dis-connected question (probably very academic):

Given the following:

struct A {
        B& b1;
        B& b2;
  const B& b3;

  A(B& b): b1(b),b2(b),b3(b) { }
};

Is the compiler allowed to suppress b2 and/or b3 from the layout of the
object. The next question comes when b1,b2 and b3 are in various places
in an inheritance path, would it be allowed to only keep the first
reference in this path (provided of course that it can be proved that
all references are bound to the same object).

        

Reply via email to