[llvm-commits] [dragonegg] r128082 - /dragonegg/trunk/Constants.cpp
Duncan Sands
baldrick at free.fr
Tue Mar 22 02:59:27 PDT 2011
Author: baldrick
Date: Tue Mar 22 04:59:27 2011
New Revision: 128082
URL: http://llvm.org/viewvc/llvm-project?rev=128082&view=rev
Log:
Do not assume that the size of a host 'char' is 8.
Modified:
dragonegg/trunk/Constants.cpp
Modified: dragonegg/trunk/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/Constants.cpp?rev=128082&r1=128081&r2=128082&view=diff
==============================================================================
--- dragonegg/trunk/Constants.cpp (original)
+++ dragonegg/trunk/Constants.cpp Tue Mar 22 04:59:27 2011
@@ -411,13 +411,14 @@
/// moment only INTEGER_CST, REAL_CST, COMPLEX_CST and VECTOR_CST are supported.
static Constant *ConvertCST(tree exp) {
const tree type = TREE_TYPE(exp);
- unsigned SizeInBytes = (TREE_INT_CST_LOW(TYPE_SIZE(type)) + 7) / 8;
+ unsigned SizeInChars = (TREE_INT_CST_LOW(TYPE_SIZE(type)) + CHAR_BIT - 1) /
+ CHAR_BIT;
// Encode the constant in Buffer in target format.
- std::vector<unsigned char> Buffer(SizeInBytes);
- unsigned BytesWritten = native_encode_expr(exp, &Buffer[0], SizeInBytes);
- assert(BytesWritten == SizeInBytes && "Failed to fully encode expression!");
+ std::vector<unsigned char> Buffer(SizeInChars);
+ unsigned CharsWritten = native_encode_expr(exp, &Buffer[0], SizeInChars);
+ assert(CharsWritten == SizeInChars && "Failed to fully encode expression!");
// Turn it into an LLVM byte array.
- return ConstantArray::get(Context, StringRef((char *)&Buffer[0], SizeInBytes),
+ return ConstantArray::get(Context, StringRef((char *)&Buffer[0], SizeInChars),
/*AddNull*/false);
}
More information about the llvm-commits
mailing list