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

Re: Question about C++ and type aliasing


Dan Nicolaescu wrote:
>   > I wasn't very clear on the outcome of that thread.  If I define a base
>   > class and another that is derived from it, and I use some virtual
>   > functions, will I get code that is as fast as doing the equivalent in C?
> 
> Is this related to aliasing?

I got the impression (rather unclearly) from the C++/aliasing thread in
January that the existence of a vtable was one of the conditions which
would disable alias calculations for an aggregate.  But you have cleared
up (below) that this isn't the case, in CVS.  Cool.

>   >   2. If I implement this in C++, using a type Derived which is derived
>   >      from another type, Base, I can implement exactly equivalent code,
>   >      right down to the word layout of the data structures and the
>   >      functions.  But will I get equivalently fast code (particularly
>   >      with respect to type alias analysis),
>   > 
>   >          (a) if there are no virtual functions in Derived or Base.
>   > 
>   >          (b) if there are virtual functions in Derived and Base.
> 
> The status quo is:
> In 3.1 alias analysis is disabled in C++ for all the aggregate types,
> it is only enabled in mainline CVS. Virtual functions don't influence
> alias analysis. Alias analysis is disabled for classes that have a
> virtual base. Multiple inheritance is ok. 
> 
> There's still a missing feature when using inheritance. 
> 
> For example:
> class first {  public:  double d;  int f1;}; 
> class second : public first {  public:  int f2;  short a;}; 
> 
> void
> foo (first *s1, second *s2)
> {  
>   s1->f1++;
>   s2->f2++;
>   s1->f1++;
>   s2->f2++;
> }  
> 
> s1->f1 and s2->f2 are considered to alias. If f1 and f2 are both
> defined in "first" (or "second") then they are not considered to
> alias. I submitted a patch to fix this about 2 weeks ago, but it has
> not been reviewed yet (no wonder, everybody is too busy fixing 3.1).

That's a mighty weird one, glad the fix is pending :-)
Thanks for your helpful reply.

cheers,
-- Jamie


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