[cfe-commits] Fix Bug 11751 - Unmatched BaseTy in Assertion Test in ComputeRecordLayout function

Yin Ma yinma at codeaurora.org
Thu Jan 12 13:37:35 PST 2012


Hi, 

 

     I have posted a potential bug as
http://llvm.org/bugs/show_bug.cgi?id=11751

And a potential fix for the bug. The attachment t.c is the file to reduce
the assertion

And please compile clang with -enable-assertion.

 

This assertion in CGRecordLayout *CodeGenTypes::ComputeRecordLayout(const

RecordDecl *D, llvm::StructType *Ty) bothers Peren test. It makes it failed.

This assertion tried to compute the size of BaseTy of a layout's non virtual

size. However, the real code has modified the BaseTy before assertion. So I

added a recompution of the real BaseTy in assert test segment 

 

...

  // If we're in C++, compute the base subobject type.

  llvm::StructType *BaseTy = 0;

  if (isa<CXXRecordDecl>(D)) {

    BaseTy = Builder.BaseSubobjectType;

    if (!BaseTy) BaseTy = Ty;   <--- is not BaseTy anymore if BaseTy is NULL

  }

...

#ifndef NDEBUG

  // Verify that the computed LLVM struct size matches the AST layout size.

  const ASTRecordLayout &Layout = getContext().getASTRecordLayout(D);

...

 

  if (BaseTy) {  <-- this requires the true BaseTy

    CharUnits NonVirtualSize  = Layout.getNonVirtualSize();

    CharUnits NonVirtualAlign = Layout.getNonVirtualAlign();

    CharUnits AlignedNonVirtualTypeSize = 

      NonVirtualSize.RoundUpToAlignment(NonVirtualAlign);

 

    uint64_t AlignedNonVirtualTypeSizeInBits = 

      getContext().toBits(AlignedNonVirtualTypeSize);

 

    assert(AlignedNonVirtualTypeSizeInBits == 

           getTargetData().getTypeAllocSizeInBits(BaseTy) &&

           "Type size mismatch!");

  }

 

My potential fix is to recompute the BaseTy in the assertion segment to deal
with this problem. (as

Clang.diff)  I have run both cross and simple cross test validation with
this change. No new failure is 

introduced. (report.txt and test.report). Please give a review, Thanks.

 

                                  Yin 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120112/83c4b0de/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang.diff
Type: application/octet-stream
Size: 633 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120112/83c4b0de/attachment.obj>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: report.txt
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120112/83c4b0de/attachment.txt>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t.c
Type: application/octet-stream
Size: 58 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120112/83c4b0de/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.report
Type: application/octet-stream
Size: 1999 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120112/83c4b0de/attachment-0002.obj>


More information about the cfe-commits mailing list