[cfe-commits] r128776 - in /cfe/trunk/lib/CodeGen: CGClass.cpp CGDebugInfo.cpp CGRTTI.cpp CGVTables.cpp CGVTables.h

Devang Patel dpatel at apple.com
Mon Apr 4 13:39:01 PDT 2011


Ken,

This little series of patches are breaking debug info. In attached test case, base offset for class D -> C is now wrong. It used to be

0x00000c82:     TAG_class_type [27] *
                 AT_sibling( {0x00000cca} )
                 AT_name( "D" )
                 AT_byte_size( 0x28 )
                 AT_decl_file( "/private/tmp/i.cc" )
                 AT_decl_line( 164 )

0x00000c8c:         TAG_inheritance [29]
                     AT_type( {0x00000bcc} ( B ) )
                     AT_data_member_location( +0 )
                     AT_accessibility( DW_ACCESS_public )

0x00000c95:         TAG_inheritance [29]
                     AT_type( {0x00000c27} ( C ) )
                     AT_data_member_location( +16 )  <---- Now this is +2 after your patches.
                     AT_accessibility( DW_ACCESS_public )

Now, the debug info claims that C is at +2 offset.

If you want to reproduce this bug then follow these steps:
1) Compile attached test case - i.cc and load it in debugger
2) Set a breakpoint at inheritance2() and run
3) After you hit the breakpoint examine the value of g_D.C::x
    It should print 18.

For now, I am reverting your patches. 

Please take a look. The offset is BaseOffset parameter in DBuilder.createInheritance() calls in CGDebugInfo.cpp

Thanks,
-
Devang

On Apr 2, 2011, at 10:52 AM, Ken Dyck wrote:

> Author: kjdyck
> Date: Sat Apr  2 12:52:22 2011
> New Revision: 128776
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=128776&view=rev
> Log:
> Change the return type of CodeGenVTables::getVirtualBaseOffsetOffset() to
> CharUnits. No change in functionality intended.
> 
> Modified:
>    cfe/trunk/lib/CodeGen/CGClass.cpp
>    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
>    cfe/trunk/lib/CodeGen/CGRTTI.cpp
>    cfe/trunk/lib/CodeGen/CGVTables.cpp
>    cfe/trunk/lib/CodeGen/CGVTables.h
> 
> Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=128776&r1=128775&r2=128776&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGClass.cpp Sat Apr  2 12:52:22 2011
> @@ -1317,11 +1317,12 @@
>                                            const CXXRecordDecl *ClassDecl,
>                                            const CXXRecordDecl *BaseClassDecl) {
>   llvm::Value *VTablePtr = GetVTablePtr(This, Int8PtrTy);
> -  int64_t VBaseOffsetOffset = 
> +  CharUnits VBaseOffsetOffset = 
>     CGM.getVTables().getVirtualBaseOffsetOffset(ClassDecl, BaseClassDecl);
> 
>   llvm::Value *VBaseOffsetPtr = 
> -    Builder.CreateConstGEP1_64(VTablePtr, VBaseOffsetOffset, "vbase.offset.ptr");
> +    Builder.CreateConstGEP1_64(VTablePtr, VBaseOffsetOffset.getQuantity(), 
> +                               "vbase.offset.ptr");
>   const llvm::Type *PtrDiffTy = 
>     ConvertType(getContext().getPointerDiffType());
> 
> 
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=128776&r1=128775&r2=128776&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Sat Apr  2 12:52:22 2011
> @@ -808,7 +808,7 @@
>   for (CXXRecordDecl::base_class_const_iterator BI = RD->bases_begin(),
>          BE = RD->bases_end(); BI != BE; ++BI) {
>     unsigned BFlags = 0;
> -    uint64_t BaseOffset;
> +    CharUnits BaseOffset;
> 
>     const CXXRecordDecl *Base =
>       cast<CXXRecordDecl>(BI->getType()->getAs<RecordType>()->getDecl());
> @@ -816,10 +816,11 @@
>     if (BI->isVirtual()) {
>       // virtual base offset offset is -ve. The code generator emits dwarf
>       // expression where it expects +ve number.
> -      BaseOffset = 0 - CGM.getVTables().getVirtualBaseOffsetOffset(RD, Base);
> +      BaseOffset = CharUnits::Zero() - 
> +        CGM.getVTables().getVirtualBaseOffsetOffset(RD, Base);
>       BFlags = llvm::DIDescriptor::FlagVirtual;
>     } else
> -      BaseOffset = RL.getBaseClassOffsetInBits(Base);
> +      BaseOffset = RL.getBaseClassOffset(Base);
> 
>     AccessSpecifier Access = BI->getAccessSpecifier();
>     if (Access == clang::AS_private)
> @@ -830,7 +831,7 @@
>     llvm::DIType DTy = 
>       DBuilder.createInheritance(RecordTy,                                     
>                                  getOrCreateType(BI->getType(), Unit),
> -                                 BaseOffset, BFlags);
> +                                 BaseOffset.getQuantity(), BFlags);
>     EltTys.push_back(DTy);
>   }
> }
> 
> Modified: cfe/trunk/lib/CodeGen/CGRTTI.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRTTI.cpp?rev=128776&r1=128775&r2=128776&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGRTTI.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGRTTI.cpp Sat Apr  2 12:52:22 2011
> @@ -877,7 +877,8 @@
>     // subobject. For a virtual base, this is the offset in the virtual table of
>     // the virtual base offset for the virtual base referenced (negative).
>     if (Base->isVirtual())
> -      OffsetFlags = CGM.getVTables().getVirtualBaseOffsetOffset(RD, BaseDecl);
> +      OffsetFlags = 
> +        CGM.getVTables().getVirtualBaseOffsetOffset(RD, BaseDecl).getQuantity();
>     else {
>       const ASTRecordLayout &Layout = CGM.getContext().getASTRecordLayout(RD);
>       OffsetFlags = Layout.getBaseClassOffsetInBits(BaseDecl) / 8;
> 
> Modified: cfe/trunk/lib/CodeGen/CGVTables.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.cpp?rev=128776&r1=128775&r2=128776&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGVTables.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGVTables.cpp Sat Apr  2 12:52:22 2011
> @@ -1339,7 +1339,7 @@
>       } else {
>         Adjustment.VBaseOffsetOffset = 
>           VTables.getVirtualBaseOffsetOffset(Offset.DerivedClass,
> -                                             Offset.VirtualBase);
> +                                             Offset.VirtualBase).getQuantity();
>       }
>     }
> 
> @@ -2431,14 +2431,15 @@
>   return I->second;
> }
> 
> -int64_t CodeGenVTables::getVirtualBaseOffsetOffset(const CXXRecordDecl *RD, 
> -                                                   const CXXRecordDecl *VBase) {
> +CharUnits 
> +CodeGenVTables::getVirtualBaseOffsetOffset(const CXXRecordDecl *RD, 
> +                                           const CXXRecordDecl *VBase) {
>   ClassPairTy ClassPair(RD, VBase);
> 
>   VirtualBaseClassOffsetOffsetsMapTy::iterator I = 
>     VirtualBaseClassOffsetOffsets.find(ClassPair);
>   if (I != VirtualBaseClassOffsetOffsets.end())
> -    return I->second.getQuantity();
> +    return I->second;
> 
>   VCallAndVBaseOffsetBuilder Builder(RD, RD, /*FinalOverriders=*/0,
>                                      BaseSubobject(RD, CharUnits::Zero()),
> @@ -2458,7 +2459,7 @@
>   I = VirtualBaseClassOffsetOffsets.find(ClassPair);
>   assert(I != VirtualBaseClassOffsetOffsets.end() && "Did not find index!");
> 
> -  return I->second.getQuantity();
> +  return I->second;
> }
> 
> uint64_t
> 
> Modified: cfe/trunk/lib/CodeGen/CGVTables.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.h?rev=128776&r1=128775&r2=128776&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGVTables.h (original)
> +++ cfe/trunk/lib/CodeGen/CGVTables.h Sat Apr  2 12:52:22 2011
> @@ -235,13 +235,13 @@
>   /// stored.
>   uint64_t getMethodVTableIndex(GlobalDecl GD);
> 
> -  /// getVirtualBaseOffsetOffset - Return the offset in bytes (relative to the
> +  /// getVirtualBaseOffsetOffset - Return the offset in chars (relative to the
>   /// vtable address point) where the offset of the virtual base that contains 
>   /// the given base is stored, otherwise, if no virtual base contains the given
>   /// class, return 0.  Base must be a virtual base class or an unambigious
>   /// base.
> -  int64_t getVirtualBaseOffsetOffset(const CXXRecordDecl *RD,
> -                                     const CXXRecordDecl *VBase);
> +  CharUnits getVirtualBaseOffsetOffset(const CXXRecordDecl *RD,
> +                                       const CXXRecordDecl *VBase);
> 
>   /// getAddressPoint - Get the address point of the given subobject in the
>   /// class decl.
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list