< prev index next >
src/share/vm/opto/subnode.cpp
Print this page
rev 9644 : 8145096: Undefined behaviour in HotSpot
Summary: Fix some integer overflows
Reviewed-by: duke
*** 250,261 ****
//------------------------------sub--------------------------------------------
// A subtract node differences it's two inputs.
const Type *SubINode::sub( const Type *t1, const Type *t2 ) const {
const TypeInt *r0 = t1->is_int(); // Handy access
const TypeInt *r1 = t2->is_int();
! int32_t lo = r0->_lo - r1->_hi;
! int32_t hi = r0->_hi - r1->_lo;
// We next check for 32-bit overflow.
// If that happens, we just assume all integers are possible.
if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR
((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND
--- 250,261 ----
//------------------------------sub--------------------------------------------
// A subtract node differences it's two inputs.
const Type *SubINode::sub( const Type *t1, const Type *t2 ) const {
const TypeInt *r0 = t1->is_int(); // Handy access
const TypeInt *r1 = t2->is_int();
! int32_t lo = java_subtract(r0->_lo, r1->_hi);
! int32_t hi = java_subtract(r0->_hi, r1->_lo);
// We next check for 32-bit overflow.
// If that happens, we just assume all integers are possible.
if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR
((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND
*** 359,370 ****
//------------------------------sub--------------------------------------------
// A subtract node differences it's two inputs.
const Type *SubLNode::sub( const Type *t1, const Type *t2 ) const {
const TypeLong *r0 = t1->is_long(); // Handy access
const TypeLong *r1 = t2->is_long();
! jlong lo = r0->_lo - r1->_hi;
! jlong hi = r0->_hi - r1->_lo;
// We next check for 32-bit overflow.
// If that happens, we just assume all integers are possible.
if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR
((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND
--- 359,370 ----
//------------------------------sub--------------------------------------------
// A subtract node differences it's two inputs.
const Type *SubLNode::sub( const Type *t1, const Type *t2 ) const {
const TypeLong *r0 = t1->is_long(); // Handy access
const TypeLong *r1 = t2->is_long();
! jlong lo = java_subtract(r0->_lo, r1->_hi);
! jlong hi = java_subtract(r0->_hi, r1->_lo);
// We next check for 32-bit overflow.
// If that happens, we just assume all integers are possible.
if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR
((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND
< prev index next >