diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-04-27 18:31:32 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-04-27 18:31:32 +0000 |
commit | 8e03444e924665d4d90f5cfc0624c815256e0309 (patch) | |
tree | 0adefb7d321cd1c7ee80be51bf5bd7f9002e5651 /lib/CodeGen/CGCall.cpp | |
parent | 4064de959853503d9b87065adac1b277fff8af20 (diff) |
x86-32 ABI: Fix crash on return of structure with flexible array
member.
Also, spell bitfield more consistently as bit-field.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70220 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGCall.cpp')
-rw-r--r-- | lib/CodeGen/CGCall.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index 41d4d7c90b..07663bfaea 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -237,7 +237,7 @@ static bool areAllFields32Or64BitBasicType(const RecordDecl *RD, if (!is32Or64BitBasicType(FD->getType(), Context)) return false; - // FIXME: Reject bitfields wholesale; there are two problems, we + // FIXME: Reject bit-fields wholesale; there are two problems, we // don't know how to expand them yet, and the predicate for // telling if a bitfield still counts as "basic" is more // complicated than what we were doing previously. @@ -342,7 +342,7 @@ bool X86_32ABIInfo::shouldReturnTypeInRegister(QualType Ty, e = RT->getDecl()->field_end(Context); i != e; ++i) { const FieldDecl *FD = *i; - // FIXME: Reject bitfields wholesale for now; this is incorrect. + // FIXME: Reject bit-fields wholesale for now; this is incorrect. if (FD->isBitField()) return false; @@ -385,9 +385,15 @@ ABIArgInfo X86_32ABIInfo::classifyReturnType(QualType RetTy, return ABIArgInfo::getDirect(); } else if (CodeGenFunction::hasAggregateLLVMType(RetTy)) { + // Structures with flexible arrays are always indirect. + if (const RecordType *RT = RetTy->getAsStructureType()) + if (RT->getDecl()->hasFlexibleArrayMember()) + return ABIArgInfo::getIndirect(0); + // Outside of Darwin, structs and unions are always indirect. if (!IsDarwin && !RetTy->isAnyComplexType()) return ABIArgInfo::getIndirect(0); + // Classify "single element" structs as their element type. if (const Type *SeltTy = isSingleElementStruct(RetTy, Context)) { if (const BuiltinType *BT = SeltTy->getAsBuiltinType()) { @@ -766,7 +772,7 @@ void X86_64ABIInfo::classify(QualType Ty, // AMD64-ABI 3.2.3p2: Rule 1. If ..., or it contains unaligned // fields, it has class MEMORY. // - // Note, skip this test for bitfields, see below. + // Note, skip this test for bit-fields, see below. if (!BitField && Offset % Context.getTypeAlign(i->getType())) { Lo = Memory; return; @@ -780,7 +786,7 @@ void X86_64ABIInfo::classify(QualType Ty, // NO_CLASS. Class FieldLo, FieldHi; - // Bitfields require special handling, they do not force the + // Bit-fields require special handling, they do not force the // structure to be passed in memory even if unaligned, and // therefore they can straddle an eightbyte. if (BitField) { |