[dragonegg] r181898 - Tweak the previous patch adding support for loading bitfields of arbitrary
Duncan Sands
baldrick at free.fr
Wed May 15 09:10:59 PDT 2013
Author: baldrick
Date: Wed May 15 11:10:59 2013
New Revision: 181898
URL: http://llvm.org/viewvc/llvm-project?rev=181898&view=rev
Log:
Tweak the previous patch adding support for loading bitfields of arbitrary
scalar type so it does the right thing in funky cases that probably don't
exist, such as a bitfield containing an i31.
Modified:
dragonegg/trunk/src/Convert.cpp
Modified: dragonegg/trunk/src/Convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Convert.cpp?rev=181898&r1=181897&r2=181898&view=diff
==============================================================================
--- dragonegg/trunk/src/Convert.cpp (original)
+++ dragonegg/trunk/src/Convert.cpp Wed May 15 11:10:59 2013
@@ -2856,22 +2856,22 @@ Value *TreeToLLVM::EmitLoadOfLValue(tree
// Otherwise the result type is a non-integer scalar, possibly a vector.
// Get the bits as an integer with the same alloc size as the result.
+ // Extending the integer with defined bits (rather than storing it as is to
+ // the temporary, which in effect extends with undefined bits) is required
+ // to get the right result for C-like languages.
Type *ResIntTy = IntegerType::get(Context, DL.getTypeAllocSizeInBits(Ty));
Value *ResInt = Builder.CreateIntCast(Val, ResIntTy, isSigned);
- // Create a temporary with the final type and store the bits to it. Going
- // via a temporary isn't really necessary: we could get the same effect by
- // casting the value. It is very natural however, since in effect we just
- // displace the original set of bits to a new memory location that is byte
- // aligned, from which we can trivially load the desired value.
+ // Create a temporary with the final type and store the bits to it.
Alignment = std::max(DL.getPrefTypeAlignment(Ty),
DL.getPrefTypeAlignment(ResIntTy));
- Value *Tmp = CreateTemporary(Ty, Alignment);
+ MemRef Tmp(CreateTemporary(Ty, Alignment), Alignment, false);
Builder.CreateStore(ResInt,
- Builder.CreateBitCast(Tmp, ResIntTy->getPointerTo()));
-
- // Load out the bits as the correct type.
- return Builder.CreateLoad(Tmp);
+ Builder.CreateBitCast(Tmp.Ptr, ResIntTy->getPointerTo()));
+ // At this point we have in essence just displaced the original set of bits to
+ // a new memory location that is byte aligned, from which we now trivially load
+ // the desired value.
+ return LoadRegisterFromMemory(Tmp, TREE_TYPE(exp), 0, Builder);
}
Value *TreeToLLVM::EmitADDR_EXPR(tree exp) {
More information about the llvm-commits
mailing list