diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-05-13 18:54:26 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-05-13 18:54:26 +0000 |
commit | ffdb8439d72d6667351e47786cf7ae1d1203c9d2 (patch) | |
tree | 78c92b903368226065c3d6d3074860672b02c140 /clang/lib/CodeGen | |
parent | 9e26d3708af2b39141a2642f6079eef0fbaecd83 (diff) | |
download | bcm5719-llvm-ffdb8439d72d6667351e47786cf7ae1d1203c9d2.tar.gz bcm5719-llvm-ffdb8439d72d6667351e47786cf7ae1d1203c9d2.zip |
ABI handling: Fix invalid assertion, it is possible for a valid
coercion to be specified which truncates padding bits. It would be
nice to still have the assert, but we don't have any API call for the
unpadding size of a type yet.
llvm-svn: 71695
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CGCall.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 072cc58e08f..2c89f3f50dd 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -1578,7 +1578,14 @@ static llvm::Value *CreateCoercedLoad(llvm::Value *SrcPtr, uint64_t DstSize = CGF.CGM.getTargetData().getTypeAllocSize(Ty); // If load is legal, just bitcast the src pointer. - if (SrcSize == DstSize) { + if (SrcSize >= DstSize) { + // Generally SrcSize is never greater than DstSize, since this + // means we are losing bits. However, this can happen in cases + // where the structure has additional padding, for example due to + // a user specified alignment. + // + // FIXME: Assert that we aren't truncating non-padding bits when + // have access to that information. llvm::Value *Casted = CGF.Builder.CreateBitCast(SrcPtr, llvm::PointerType::getUnqual(Ty)); llvm::LoadInst *Load = CGF.Builder.CreateLoad(Casted); @@ -1586,8 +1593,6 @@ static llvm::Value *CreateCoercedLoad(llvm::Value *SrcPtr, Load->setAlignment(1); return Load; } else { - assert(SrcSize < DstSize && "Coercion is losing source bits!"); - // Otherwise do coercion through memory. This is stupid, but // simple. llvm::Value *Tmp = CGF.CreateTempAlloca(Ty); @@ -1617,14 +1622,19 @@ static void CreateCoercedStore(llvm::Value *Src, uint64_t DstSize = CGF.CGM.getTargetData().getTypeAllocSize(DstTy); // If store is legal, just bitcast the src pointer. - if (SrcSize == DstSize) { + if (SrcSize >= DstSize) { + // Generally SrcSize is never greater than DstSize, since this + // means we are losing bits. However, this can happen in cases + // where the structure has additional padding, for example due to + // a user specified alignment. + // + // FIXME: Assert that we aren't truncating non-padding bits when + // have access to that information. llvm::Value *Casted = CGF.Builder.CreateBitCast(DstPtr, llvm::PointerType::getUnqual(SrcTy)); // FIXME: Use better alignment / avoid requiring aligned store. CGF.Builder.CreateStore(Src, Casted)->setAlignment(1); } else { - assert(SrcSize > DstSize && "Coercion is missing bits!"); - // Otherwise do coercion through memory. This is stupid, but // simple. llvm::Value *Tmp = CGF.CreateTempAlloca(SrcTy); |