[cfe-commits] r77351 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp lib/CodeGen/CGExpr.cpp test/CodeGenCXX/constructor-init.cpp

Anders Carlsson andersca at mac.com
Tue Jul 28 16:02:33 PDT 2009


On Jul 28, 2009, at 3:53 PM, Fariborz Jahanian wrote:

>
> On Jul 28, 2009, at 3:47 PM, Chris Lattner wrote:
>
>>
>> On Jul 28, 2009, at 3:46 PM, Fariborz Jahanian wrote:
>>
>>>>>
>>>>> +++ cfe/trunk/lib/CodeGen/CGCXX.cpp Tue Jul 28 13:54:57 2009
>>>>> @@ -168,16 +168,23 @@
>>>>> getContext().getASTRecordLayout(ClassDecl);
>>>>> llvm::Type *I8Ptr =
>>>>> VMContext.getPointerTypeUnqual(llvm::Type::Int8Ty);
>>>>> unsigned Idx = 0;
>>>>> +  bool DerivedToBaseConversion = false;
>>>>> for (CXXRecordDecl::base_class_const_iterator i =
>>>>>      ClassDecl->bases_begin(),
>>>>>      e = ClassDecl->bases_end(); i != e; ++i, ++Idx) {
>>>>> if (!i->isVirtual()) {
>>>>>     const CXXRecordDecl *Base =
>>>>>     cast<CXXRecordDecl>(i->getType()->getAsRecordType()-
>>>>>> getDecl());
>>>>> -        if (Base == BaseClassDecl)
>>>>> -          break;
>>>>> +      if (Base == BaseClassDecl) {
>>>>> +        DerivedToBaseConversion = true;
>>>>> +        break;
>>>>> +      }
>>>>> }
>>>>> }
>>>>
>>>> Can you convert this loop to be a static function instead?
>>>> Justification here:
>>>> http://llvm.org/docs/CodingStandards.html#hl_predicateloops
>>>
>>> This code will all likelihood change when Anders has the type
>>> layout change done.
>>> Base class offset calculation is based on the current layout and
>>> will be replaced soon.
>>
>> This code seems like a generally useful predicate.  Isn't there
>> other places in the compiler that compute the same thing?
> I don;t know at this time. Note that loop also computes index into the
> Offset table for a given base class. So, it does other things.
> In any case, I will make sure that this loop, in whatever form it will
> be, will go into a static function.
>
> - fariborz

We now have this information in the ASTRecordLayout -

/// getBaseClassOffset - Get the offset, in bits, for the given base  
class.
uint64_t getBaseClassOffset(const CXXRecordDecl *Base) const;

I imagined that AddressCXXOfBaseClass would know the the path of base  
classes so it could just walk it and use getBaseClassOffset to get the  
final offset. (This won't work if any of the base classes in the  
hierarchy are virtual of course but let's not worry about that right  
now :).

Anders



More information about the cfe-commits mailing list