diff options
author | Anders Carlsson <andersca@mac.com> | 2009-07-25 00:24:56 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-07-25 00:24:56 +0000 |
commit | 87a9a34e5bfb9e7deb43506adc13188a9cea85a7 (patch) | |
tree | 6ec0176549438091793e9d57a5bbebc2691fdd22 /clang/lib | |
parent | 8c8e88bd39e3e0d49155dfdb730fea55920adf31 (diff) | |
download | bcm5719-llvm-87a9a34e5bfb9e7deb43506adc13188a9cea85a7.tar.gz bcm5719-llvm-87a9a34e5bfb9e7deb43506adc13188a9cea85a7.zip |
More work on the constant struct builder. We now try to layout all constant structs but throw away the result.
llvm-svn: 77021
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/CodeGen/CGExprConstant.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index 07570c1034b..84e9283cadb 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -34,6 +34,7 @@ class VISIBILITY_HIDDEN ConstStructBuilder { CodeGenFunction *CGF; bool Packed; + unsigned NextFieldOffsetInBytes; std::vector<llvm::Constant *> Elements; @@ -131,12 +132,24 @@ class VISIBILITY_HIDDEN ConstStructBuilder { ElementNo++; } + uint64_t LayoutSizeInBytes = Layout.getSize() / 8; + + if (NextFieldOffsetInBytes > LayoutSizeInBytes) { + // If the struct is bigger than the size of the record type, + // we must have a flexible array member at the end. + assert(RD->hasFlexibleArrayMember() && + "Must have flexible array member if struct is bigger than type!"); + + // No tail padding is necessary. + return true; + } + // Append tail padding if necessary. AppendTailPadding(Layout.getSize()); - + assert(Layout.getSize() / 8 == NextFieldOffsetInBytes && "Tail padding mismatch!"); - + return true; } @@ -156,16 +169,15 @@ public: const InitListExpr *ILE) { ConstStructBuilder Builder(CGM, CGF); - // FIXME: Use this when it works well enough. - return 0; - if (!Builder.Build(ILE)) return 0; llvm::Constant *Result = CGM.getLLVMContext().getConstantStruct(Builder.Elements, Builder.Packed); - assert(Builder.NextFieldOffsetInBytes == Builder.getSizeInBytes(Result)); + assert(llvm::RoundUpToAlignment(Builder.NextFieldOffsetInBytes, + Builder.getAlignment(Result)) == + Builder.getSizeInBytes(Result) && "Size mismatch!"); return Result; } @@ -330,6 +342,7 @@ public: } llvm::Constant *EmitStructInitialization(InitListExpr *ILE) { + // FIXME: Use the returned struct when the builder works well enough. ConstStructBuilder::BuildStruct(CGM, CGF, ILE); const llvm::StructType *SType = |