mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-19 19:29:31 +00:00
Fix for problem when allocating something like this:
malloc(100-i); git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2409 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
868cb7da08
commit
4840146b46
@ -62,7 +62,7 @@ static bool MallocConvertableToType(MallocInst *MI, const Type *Ty,
|
|||||||
analysis::ExprType Expr = analysis::ClassifyExpression(MI->getArraySize());
|
analysis::ExprType Expr = analysis::ClassifyExpression(MI->getArraySize());
|
||||||
|
|
||||||
// Get information about the base datatype being allocated, before & after
|
// Get information about the base datatype being allocated, before & after
|
||||||
unsigned ReqTypeSize = TD.getTypeSize(Ty);
|
int ReqTypeSize = TD.getTypeSize(Ty);
|
||||||
unsigned OldTypeSize = TD.getTypeSize(MI->getType()->getElementType());
|
unsigned OldTypeSize = TD.getTypeSize(MI->getType()->getElementType());
|
||||||
|
|
||||||
// Must have a scale or offset to analyze it...
|
// Must have a scale or offset to analyze it...
|
||||||
@ -71,15 +71,11 @@ static bool MallocConvertableToType(MallocInst *MI, const Type *Ty,
|
|||||||
// Get the offset and scale of the allocation...
|
// Get the offset and scale of the allocation...
|
||||||
int OffsetVal = Expr.Offset ? getConstantValue(Expr.Offset) : 0;
|
int OffsetVal = Expr.Offset ? getConstantValue(Expr.Offset) : 0;
|
||||||
int ScaleVal = Expr.Scale ? getConstantValue(Expr.Scale) : (Expr.Var ? 1 : 0);
|
int ScaleVal = Expr.Scale ? getConstantValue(Expr.Scale) : (Expr.Var ? 1 : 0);
|
||||||
if (ScaleVal < 0 || OffsetVal < 0) {
|
|
||||||
cerr << "malloc of a negative number???\n";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The old type might not be of unit size, take old size into consideration
|
// The old type might not be of unit size, take old size into consideration
|
||||||
// here...
|
// here...
|
||||||
unsigned Offset = (unsigned)OffsetVal * OldTypeSize;
|
int Offset = OffsetVal * OldTypeSize;
|
||||||
unsigned Scale = (unsigned)ScaleVal * OldTypeSize;
|
int Scale = ScaleVal * OldTypeSize;
|
||||||
|
|
||||||
// In order to be successful, both the scale and the offset must be a multiple
|
// In order to be successful, both the scale and the offset must be a multiple
|
||||||
// of the requested data type's size.
|
// of the requested data type's size.
|
||||||
|
Loading…
Reference in New Issue
Block a user