8341178: TypeRawPtr::add_offset may be "miscompiled" due to UB
Reviewed-by: dlong, kvn
This commit is contained in:
parent
1f6bd0c3e5
commit
0a57fe1df6
@ -3111,8 +3111,8 @@ const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
|
||||
return (TypeRawPtr*)(new TypeRawPtr(ptr,nullptr))->hashcons();
|
||||
}
|
||||
|
||||
const TypeRawPtr *TypeRawPtr::make( address bits ) {
|
||||
assert( bits, "Use TypePtr for null" );
|
||||
const TypeRawPtr *TypeRawPtr::make(address bits) {
|
||||
assert(bits != nullptr, "Use TypePtr for null");
|
||||
return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
|
||||
}
|
||||
|
||||
@ -3201,15 +3201,21 @@ const TypePtr* TypeRawPtr::add_offset(intptr_t offset) const {
|
||||
case TypePtr::BotPTR:
|
||||
case TypePtr::NotNull:
|
||||
return this;
|
||||
case TypePtr::Null:
|
||||
case TypePtr::Constant: {
|
||||
address bits = _bits+offset;
|
||||
if ( bits == 0 ) return TypePtr::NULL_PTR;
|
||||
return make( bits );
|
||||
uintptr_t bits = (uintptr_t)_bits;
|
||||
uintptr_t sum = bits + offset;
|
||||
if (( offset < 0 )
|
||||
? ( sum > bits ) // Underflow?
|
||||
: ( sum < bits )) { // Overflow?
|
||||
return BOTTOM;
|
||||
} else if ( sum == 0 ) {
|
||||
return TypePtr::NULL_PTR;
|
||||
} else {
|
||||
return make( (address)sum );
|
||||
}
|
||||
}
|
||||
default: ShouldNotReachHere();
|
||||
}
|
||||
return nullptr; // Lint noise
|
||||
}
|
||||
|
||||
//------------------------------eq---------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user