[cfe-commits] r126357 - /cfe/trunk/lib/AST/RecordLayoutBuilder.cpp

Daniel Dunbar daniel at zuster.org
Thu Feb 24 08:33:02 PST 2011


Hi Ken,

This broke some GCC tests. Test case:
--
ddunbar at ozzy:~$ curl -s -o - http://minormatter.com/~ddunbar/files/t.i
| clang -x c -
Assertion failed: (Size % Context.getCharWidth() == 0), function
getSize, file /Volumes/Data/Users/ddunbar/llvm/tools/clang/lib/AST/RecordLayoutBuilder.cpp,
line 702.
0  clang             0x0000000101b656a5 PrintStackTrace(void*) + 53
1  clang             0x0000000101b65c6b SignalHandler(int) + 379
2  libSystem.B.dylib 0x00007fff882e767a _sigtramp + 26
3  clang             0x0000000100ac8b05 std::pair<unsigned long long,
unsigned int>::pair(unsigned long long const&, unsigned int const&) +
37
4  clang             0x000000010003460b raise + 27
5  clang             0x00000001000346ca abort + 26
6  clang             0x00000001000346a4 __assert_rtn + 132
7  clang             0x0000000100be8f7b (anonymous
namespace)::RecordLayoutBuilder::getSize() const + 123
8  clang             0x0000000100be9b60 (anonymous
namespace)::RecordLayoutBuilder::LayoutField(clang::FieldDecl const*)
+ 2448
9  clang             0x0000000100beccf3 (anonymous
namespace)::RecordLayoutBuilder::LayoutFields(clang::RecordDecl
const*) + 99
10 clang             0x0000000100be7459 (anonymous
namespace)::RecordLayoutBuilder::Layout(clang::RecordDecl const*) + 57
11 clang             0x0000000100be6ce7
clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const
+ 1591
12 clang             0x0000000100a9415a
clang::ASTContext::getTypeInfo(clang::Type const*) const + 2458
13 clang             0x0000000100ab7315
clang::ASTContext::getTypeInfo(clang::QualType) const + 53
14 clang             0x0000000100ab84f1
clang::ASTContext::getTypeSize(clang::QualType) const + 33
15 clang             0x0000000100a94913
clang::ASTContext::getTypeSizeInChars(clang::QualType) const + 51
16 clang             0x0000000100c1c04d
clang::ConstantArrayType::getNumAddressingBits(clang::ASTContext&,
clang::QualType, llvm::APInt const&) + 413
17 clang             0x00000001008062c8
clang::Sema::BuildArrayType(clang::QualType,
clang::ArrayType::ArraySizeModifier, clang::Expr*, unsigned int,
clang::SourceRange, clang::DeclarationName) + 4312
18 clang             0x0000000100808d0c
clang::Sema::GetTypeForDeclarator(clang::Declarator&, clang::Scope*,
clang::TagDecl**, bool) + 4956
19 clang             0x00000001005099d5
clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&,
clang::ASTMultiPtr<clang::TemplateParameterList*>, bool) + 2645
20 clang             0x0000000100508f72
clang::Sema::ActOnDeclarator(clang::Scope*, clang::Declarator&) + 98
21 clang             0x00000001004008d2
clang::Parser::ParseDeclarationAfterDeclarator(clang::Declarator&,
clang::Parser::ParsedTemplateInfo const&) + 482
22 clang             0x000000010040036c
clang::Parser::ParseDeclGroup(clang::Parser::ParsingDeclSpec&,
unsigned int, bool, clang::SourceLocation*) + 956
23 clang             0x00000001004602eb
clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsingDeclSpec&,
clang::AccessSpecifier) + 1339
24 clang             0x0000000100460360
clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&,
clang::AccessSpecifier) + 96
25 clang             0x000000010045f7e5
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::Parser::ParsingDeclSpec*) + 3493
26 clang             0x000000010045ea09
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&)
+ 297
27 clang             0x00000001003f7a2c clang::ParseAST(clang::Sema&,
bool) + 284
28 clang             0x00000001000e7c7c
clang::ASTFrontendAction::ExecuteAction() + 284
29 clang             0x00000001003b8ae2
clang::CodeGenAction::ExecuteAction() + 1250
30 clang             0x00000001000e7827 clang::FrontendAction::Execute() + 343
31 clang             0x00000001000b6886
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 1078
32 clang             0x000000010004b2e5
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1077
33 clang             0x0000000100037aa4 cc1_main(char const**, char
const**, char const*, void*) + 1252
34 clang             0x0000000100044d3d main + 701
35 clang             0x00000001000375b4 start + 52
Stack dump:
0.	Program arguments:
/Volumes/Data/Users/ddunbar/llvm.obj.64/Debug+Asserts/bin/clang -cc1
-triple x86_64-apple-darwin10.0.0 -emit-obj -mrelax-all -disable-free
-main-file-name - -pic-level 1 -mdisable-fp-elim -masm-verbose
-munwind-tables -target-cpu core2 -target-linker-version 97.17
-resource-dir /Volumes/Data/Users/ddunbar/llvm.obj.64/Debug+Asserts/bin/../lib/clang/2.9
-ferror-limit 19 -fmessage-length 80 -stack-protector 1 -fblocks
-fdiagnostics-show-option -fcolor-diagnostics -o
/var/folders/U7/U7vhB+idGBy-KpZXlZNuXU+++TI/-Tmp-/cc-aS7bjZ.o -x c -
1.	/Users/ddunbar/public/clang-tests/gcc-4_2-testsuite/obj/gcc.dg-struct-layout-1/t002_test.h:26:83:
current parser token ';'
clang: error: unable to execute command: Illegal instruction
clang: error: clang frontend command failed due to signal 1 (use -v to
see invocation)
--

I'll revert for now, please take a look!

Thanks,
 - Daniel

On Wed, Feb 23, 2011 at 6:12 PM, Ken Dyck <kd at kendyck.com> wrote:
> Author: kjdyck
> Date: Wed Feb 23 20:12:14 2011
> New Revision: 126357
>
> URL: http://llvm.org/viewvc/llvm-project?rev=126357&view=rev
> Log:
> Use CharUnits values for Size and DataSize outside of the bitfield layout
> methods, when they are known to be exact multiples of the width of the char
> type.
>
> Modified:
>    cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
>
> Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=126357&r1=126356&r2=126357&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
> +++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Wed Feb 23 20:12:14 2011
> @@ -815,8 +815,8 @@
>   assert(DataSize == 0 && "Vtable pointer must be at offset zero!");
>
>   // Update the size.
> -  setSize(getSizeInBits() + GetVirtualPointersSize(RD));
> -  setDataSize(getSizeInBits());
> +  setSize(getSize() + Context.toCharUnitsFromBits(GetVirtualPointersSize(RD)));
> +  setDataSize(getSize());
>
>   CharUnits UnpackedBaseAlign =
>     Context.toCharUnitsFromBits(Context.Target.getPointerAlign(0));
> @@ -1108,8 +1108,7 @@
>   // If we have an empty base class, try to place it at offset 0.
>   if (Base->Class->isEmpty() &&
>       EmptySubobjects->CanPlaceBaseAtOffset(Base, CharUnits::Zero())) {
> -    uint64_t RecordSizeInBits = Context.toBits(Layout.getSize());
> -    setSize(std::max(getSizeInBits(), RecordSizeInBits));
> +    setSize(std::max(getSize(), Layout.getSize()));
>
>     return CharUnits::Zero();
>   }
> @@ -1124,27 +1123,24 @@
>   }
>
>   // Round up the current record size to the base's alignment boundary.
> -  uint64_t Offset =
> -    llvm::RoundUpToAlignment(getDataSizeInBits(), Context.toBits(BaseAlign));
> +  CharUnits Offset = getDataSize().RoundUpToAlignment(BaseAlign);
>
>   // Try to place the base.
> -  while (!EmptySubobjects->CanPlaceBaseAtOffset(Base,
> -                                          Context.toCharUnitsFromBits(Offset)))
> -    Offset += Context.toBits(BaseAlign);
> +  while (!EmptySubobjects->CanPlaceBaseAtOffset(Base, Offset))
> +    Offset += BaseAlign;
>
>   if (!Base->Class->isEmpty()) {
>     // Update the data size.
> -    setDataSize(Offset + Context.toBits(Layout.getNonVirtualSize()));
> +    setDataSize(Offset + Layout.getNonVirtualSize());
>
> -    setSize(std::max(getSizeInBits(), getDataSizeInBits()));
> +    setSize(std::max(getSize(), getDataSize()));
>   } else
> -    setSize(std::max(getSizeInBits(),
> -                     Offset + Context.toBits(Layout.getSize())));
> +    setSize(std::max(getSize(), Offset + Layout.getSize()));
>
>   // Remember max struct/class alignment.
>   UpdateAlignment(BaseAlign, UnpackedBaseAlign);
>
> -  return Context.toCharUnitsFromBits(Offset);
> +  return Offset;
>  }
>
>  void RecordLayoutBuilder::InitializeLayout(const Decl *D) {
> @@ -1233,7 +1229,7 @@
>     // We start laying out ivars not at the end of the superclass
>     // structure, but at the next byte following the last field.
>     setSize(SL.getDataSize());
> -    setDataSize(getSizeInBits());
> +    setDataSize(getSize());
>   }
>
>   InitializeLayout(D);
> @@ -1483,14 +1479,13 @@
>                     Context.toBits(UnpackedFieldAlign), FieldPacked, D);
>
>   // Reserve space for this field.
> -  uint64_t FieldSizeInBits = Context.toBits(FieldSize);
>   if (IsUnion)
> -    setSize(std::max(getSizeInBits(), FieldSizeInBits));
> +    setSize(std::max(getSize(), FieldSize));
>   else
> -    setSize(Context.toBits(FieldOffset) + FieldSizeInBits);
> +    setSize(FieldOffset + FieldSize);
>
>   // Update the data size.
> -  setDataSize(getSizeInBits());
> +  setDataSize(getSize());
>
>   // Remember max struct/class alignment.
>   UpdateAlignment(FieldAlign, UnpackedFieldAlign);
> @@ -1504,17 +1499,18 @@
>       // which is not empty but of size 0; such as having fields of
>       // array of zero-length, remains of Size 0
>       if (RD->isEmpty())
> -        setSize(8);
> +        setSize(CharUnits::One());
>     }
>     else
> -      setSize(8);
> +      setSize(CharUnits::One());
>   }
>   // Finally, round the size of the record up to the alignment of the
>   // record itself.
>   uint64_t UnpaddedSize = getSizeInBits() - UnfilledBitsInLastByte;
> -  uint64_t UnpackedSize =
> +  uint64_t UnpackedSizeInBits =
>     llvm::RoundUpToAlignment(getSizeInBits(),
>                              Context.toBits(UnpackedAlignment));
> +  CharUnits UnpackedSize = Context.toCharUnitsFromBits(UnpackedSizeInBits);
>   setSize(llvm::RoundUpToAlignment(getSizeInBits(), Context.toBits(Alignment)));
>
>   unsigned CharBitNum = Context.Target.getCharWidth();
> @@ -1536,7 +1532,7 @@
>     // Warn if we packed it unnecessarily. If the alignment is 1 byte don't
>     // bother since there won't be alignment issues.
>     if (Packed && UnpackedAlignment > CharUnits::One() &&
> -        getSizeInBits() == UnpackedSize)
> +        getSize() == UnpackedSize)
>       Diag(D->getLocation(), diag::warn_unnecessary_packed)
>           << Context.getTypeDeclType(RD);
>   }
>
>
> _______________________________________________
> 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