[llvm-commits] [dragonegg] r127979 - in /dragonegg/trunk: Constants.cpp Constants.h
Duncan Sands
baldrick at free.fr
Sun Mar 20 14:10:16 PDT 2011
Author: baldrick
Date: Sun Mar 20 16:10:15 2011
New Revision: 127979
URL: http://llvm.org/viewvc/llvm-project?rev=127979&view=rev
Log:
Add some sanity checks on the constants returned by ConvertInitializer
and correct the description of this method.
Modified:
dragonegg/trunk/Constants.cpp
dragonegg/trunk/Constants.h
Modified: dragonegg/trunk/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/Constants.cpp?rev=127979&r1=127978&r2=127979&view=diff
==============================================================================
--- dragonegg/trunk/Constants.cpp (original)
+++ dragonegg/trunk/Constants.cpp Sun Mar 20 16:10:15 2011
@@ -1294,27 +1294,61 @@
/// equal to or less than that of the original expression.
Constant *ConvertInitializer(tree exp) {
assert(TREE_CONSTANT(exp) && "Isn't a constant!");
+
+ Constant *Init;
switch (TREE_CODE(exp)) {
default:
debug_tree(exp);
assert(0 && "Unknown constant to convert!");
abort();
- case INTEGER_CST: return ConvertINTEGER_CST(exp);
- case REAL_CST: return ConvertREAL_CST(exp);
- case VECTOR_CST: return ConvertVECTOR_CST(exp);
- case STRING_CST: return ConvertSTRING_CST(exp);
- case COMPLEX_CST: return ConvertCOMPLEX_CST(exp);
- case NOP_EXPR: return ConvertNOP_EXPR(exp);
- case CONVERT_EXPR: return ConvertCONVERT_EXPR(exp);
+ case INTEGER_CST:
+ Init = ConvertINTEGER_CST(exp);
+ break;
+ case REAL_CST:
+ Init = ConvertREAL_CST(exp);
+ break;
+ case VECTOR_CST:
+ Init = ConvertVECTOR_CST(exp);
+ break;
+ case STRING_CST:
+ Init = ConvertSTRING_CST(exp);
+ break;
+ case COMPLEX_CST:
+ Init = ConvertCOMPLEX_CST(exp);
+ break;
+ case NOP_EXPR:
+ Init = ConvertNOP_EXPR(exp);
+ break;
+ case CONVERT_EXPR:
+ Init = ConvertCONVERT_EXPR(exp);
+ break;
case PLUS_EXPR:
- case MINUS_EXPR: return ConvertBinOp_CST(exp);
- case CONSTRUCTOR: return ConvertCONSTRUCTOR(exp);
- case VIEW_CONVERT_EXPR: return ConvertInitializer(TREE_OPERAND(exp, 0));
- case POINTER_PLUS_EXPR: return ConvertPOINTER_PLUS_EXPR(exp);
+ case MINUS_EXPR:
+ Init = ConvertBinOp_CST(exp);
+ break;
+ case CONSTRUCTOR:
+ Init = ConvertCONSTRUCTOR(exp);
+ break;
+ case VIEW_CONVERT_EXPR:
+ Init = ConvertInitializer(TREE_OPERAND(exp, 0));
+ break;
+ case POINTER_PLUS_EXPR:
+ Init = ConvertPOINTER_PLUS_EXPR(exp);
+ break;
case ADDR_EXPR:
- return TheFolder->CreateBitCast(AddressOf(TREE_OPERAND(exp, 0)),
+ Init = TheFolder->CreateBitCast(AddressOf(TREE_OPERAND(exp, 0)),
ConvertType(TREE_TYPE(exp)));
+ break;
}
+
+ assert((!ConvertType(TREE_TYPE(exp))->isSized() ||
+ getTargetData().getTypeAllocSizeInBits(ConvertType(TREE_TYPE(exp))) <=
+ getTargetData().getTypeAllocSizeInBits(Init->getType())) &&
+ "Constant too small for type!");
+ assert(getTargetData().getABITypeAlignment(Init->getType()) * 8 <=
+ TYPE_ALIGN(TREE_TYPE(exp)) && "Constant over aligned!");
+
+ return Init;
}
Modified: dragonegg/trunk/Constants.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/Constants.h?rev=127979&r1=127978&r2=127979&view=diff
==============================================================================
--- dragonegg/trunk/Constants.h (original)
+++ dragonegg/trunk/Constants.h Sun Mar 20 16:10:15 2011
@@ -41,8 +41,12 @@
/// ConvertInitializer - Convert the initial value for a global variable to an
/// equivalent LLVM constant. Also handles constant constructors. The type of
/// the returned value may be pretty much anything. All that is guaranteed is
-/// that it has the same alloc size as the original expression and has alignment
-/// equal to or less than that of the original expression.
+/// that its alloc size is equal to the size of the initial value and that its
+/// alignment is less than or equal to the initial value's GCC type alignment.
+/// Note that the GCC type may have variable size or no size, in which case the
+/// size is determined by the initial value. When this happens the size of the
+/// initial value may exceed the alloc size of the LLVM memory type generated
+/// for the GCC type (see ConvertType); it is never smaller than the alloc size.
extern llvm::Constant *ConvertInitializer(tree_node *exp);
/// InterpretAsType - Interpret the bits of the given constant (starting from
More information about the llvm-commits
mailing list