Mercurial > hg > truffle
changeset 4705:27397872945f
fix "integer overflow when computing constant displacement"
by introducing a temp variable for large constant indexes
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Mon, 27 Feb 2012 14:50:10 +0100 |
parents | 351b9054b49d |
children | a59fe7906f0b dfa7c9a45d8e |
files | graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java |
diffstat | 1 files changed, 11 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java Mon Feb 27 14:45:10 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java Mon Feb 27 14:50:10 2012 +0100 @@ -153,15 +153,20 @@ scale = target().sizeInBytes(location.getValueKind()); } if (isConstant(index)) { - displacement += asConstant(index).asLong() * scale; - index = CiValue.IllegalValue; + long newDisplacement = displacement + asConstant(index).asLong() * scale; + // only use the constant index if the resulting displacement fits into a 32 bit offset + if (NumUtil.isInt(newDisplacement)) { + displacement = newDisplacement; + index = CiValue.IllegalValue; + } else { + // create a temporary variable for the index, the pointer load cannot handle a constant index + CiValue newIndex = newVariable(CiKind.Long); + emitMove(index, newIndex); + index = newIndex; + } } } - if (!NumUtil.isInt(displacement)) { - // Currently it's not worth handling this case. - throw new CiBailout("integer overflow when computing constant displacement"); - } return new CiAddress(location.getValueKind(), base, index, CiAddress.Scale.fromInt(scale), (int) displacement); }