aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGCall.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-05-13 18:54:26 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-05-13 18:54:26 +0000
commit7ef455be9beb7a755d815bfbdc38d55d1ce59b86 (patch)
treef8f9659a1e46885813a2e677abe8a98c71b2dd2f /lib/CodeGen/CGCall.cpp
parentff66803b43f2ea9206637dceb793e9505f3b9c48 (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71695 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGCall.cpp')
-rw-r--r--lib/CodeGen/CGCall.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp
index 072cc58e08..2c89f3f50d 100644
--- a/lib/CodeGen/CGCall.cpp
+++ b/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);