diff options
author | Anders Carlsson <andersca@mac.com> | 2009-08-23 01:25:01 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-08-23 01:25:01 +0000 |
commit | fc3eaa47fa2ef70ab21131005c328adda3020737 (patch) | |
tree | 777338d19e91e829f91ac7bcad654dab0647c2a1 /lib/CodeGen | |
parent | 341bdf8d565f5282779a0ffd2d2b77f3a38b735e (diff) |
More work towards zero-initializing structs that contain member pointers in constant expressions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79805 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/CGExprConstant.cpp | 8 | ||||
-rw-r--r-- | lib/CodeGen/CGRecordLayoutBuilder.cpp | 21 | ||||
-rw-r--r-- | lib/CodeGen/CGRecordLayoutBuilder.h | 10 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenTypes.h | 20 |
4 files changed, 52 insertions, 7 deletions
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index b3e0fef1ba..2770527eba 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -800,6 +800,14 @@ llvm::Constant *CodeGenModule::EmitNullConstant(QualType T) { return llvm::ConstantArray::get(ATy, Array); } } + + if (const RecordType *RT = T->getAs<RecordType>()) { + const CGRecordLayout *Layout = Types.getCGRecordLayout(RT->getDecl()); + if (Layout->containsMemberPointer()) { + assert(0 && "FIXME: No support for structs with member pointers yet!"); + } + + } // FIXME: Handle structs that contain member pointers. if (T->isMemberPointerType()) diff --git a/lib/CodeGen/CGRecordLayoutBuilder.cpp b/lib/CodeGen/CGRecordLayoutBuilder.cpp index 0dc64f009d..ea5de5f2b1 100644 --- a/lib/CodeGen/CGRecordLayoutBuilder.cpp +++ b/lib/CodeGen/CGRecordLayoutBuilder.cpp @@ -301,6 +301,25 @@ uint64_t CGRecordLayoutBuilder::getTypeSizeInBytes(const llvm::Type *Ty) const { return Types.getTargetData().getTypeAllocSize(Ty); } +void CGRecordLayoutBuilder::CheckForMemberPointer(const FieldDecl *FD) { + // This record already contains a member pointer. + if (ContainsMemberPointer) + return; + + // Can only have member pointers if we're compiling C++. + if (!Types.getContext().getLangOptions().CPlusPlus) + return; + + QualType Ty = FD->getType(); + + if (Ty->isMemberPointerType()) { + // We have a member pointer! + ContainsMemberPointer = true; + return; + } + +} + CGRecordLayout * CGRecordLayoutBuilder::ComputeLayout(CodeGenTypes &Types, const RecordDecl *D) { @@ -330,5 +349,5 @@ CGRecordLayoutBuilder::ComputeLayout(CodeGenTypes &Types, Types.addBitFieldInfo(Info.FD, Info.FieldNo, Info.Start, Info.Size); } - return new CGRecordLayout(Ty); + return new CGRecordLayout(Ty, Builder.ContainsMemberPointer); } diff --git a/lib/CodeGen/CGRecordLayoutBuilder.h b/lib/CodeGen/CGRecordLayoutBuilder.h index ff551a4f13..63ddc10df5 100644 --- a/lib/CodeGen/CGRecordLayoutBuilder.h +++ b/lib/CodeGen/CGRecordLayoutBuilder.h @@ -36,6 +36,10 @@ class CGRecordLayoutBuilder { /// Packed - Whether the resulting LLVM struct will be packed or not. bool Packed; + /// ContainsMemberPointer - Whether one of the fields is a member pointer + /// or is a struct that contains a member pointer. + bool ContainsMemberPointer; + /// Alignment - Contains the alignment of the RecordDecl. unsigned Alignment; @@ -72,7 +76,8 @@ class CGRecordLayoutBuilder { llvm::SmallVector<LLVMBitFieldInfo, 16> LLVMBitFields; CGRecordLayoutBuilder(CodeGenTypes &Types) - : Types(Types), Packed(false), Alignment(0), AlignmentAsLLVMStruct(1) + : Types(Types), Packed(false), ContainsMemberPointer(false) + , Alignment(0), AlignmentAsLLVMStruct(1) , BitsAvailableInLastField(0), NextFieldOffsetInBytes(0) { } /// Layout - Will layout a RecordDecl. @@ -113,6 +118,9 @@ class CGRecordLayoutBuilder { unsigned getTypeAlignment(const llvm::Type *Ty) const; uint64_t getTypeSizeInBytes(const llvm::Type *Ty) const; + /// CheckForMemberPointer - Check if the field contains a member pointer. + void CheckForMemberPointer(const FieldDecl *FD); + public: /// ComputeLayout - Return the right record layout for a given record decl. static CGRecordLayout *ComputeLayout(CodeGenTypes &Types, diff --git a/lib/CodeGen/CodeGenTypes.h b/lib/CodeGen/CodeGenTypes.h index 530946bb8f..22ebbf1682 100644 --- a/lib/CodeGen/CodeGenTypes.h +++ b/lib/CodeGen/CodeGenTypes.h @@ -53,17 +53,27 @@ namespace CodeGen { /// lowering AST types to LLVM types. class CGRecordLayout { CGRecordLayout(); // DO NOT IMPLEMENT + + /// LLVMType - The LLVMType corresponding to this record layout. + const llvm::Type *LLVMType; + + /// ContainsMemberPointer - Whether one of the fields in this record layout + /// is a member pointer, or a struct that contains a member pointer. + bool ContainsMemberPointer; + public: - CGRecordLayout(const llvm::Type *T) - : STy(T) { } + CGRecordLayout(const llvm::Type *T, bool ContainsMemberPointer) + : LLVMType(T), ContainsMemberPointer(ContainsMemberPointer) { } /// getLLVMType - Return llvm type associated with this record. const llvm::Type *getLLVMType() const { - return STy; + return LLVMType; } - private: - const llvm::Type *STy; + bool containsMemberPointer() const { + return ContainsMemberPointer; + } + }; /// CodeGenTypes - This class organizes the cross-module state that is used |