Skip to content

Commit 108078a

Browse files
marc-chevalierdafedafe
authored andcommitted
8338194: ubsan: mulnode.cpp:862:59: runtime error: shift exponent 64 is too large for 64-bit type 'long unsigned int'
Reviewed-by: dlong, dfenacci
1 parent 841989b commit 108078a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/hotspot/share/opto/mulnode.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -924,13 +924,15 @@ Node *AndLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
924924
if( t12 && t12->is_con() ) { // Shift is by a constant
925925
int shift = t12->get_con();
926926
shift &= BitsPerJavaLong - 1; // semantics of Java shifts
927-
const julong sign_bits_mask = ~(((julong)CONST64(1) << (julong)(BitsPerJavaLong - shift)) -1);
928-
// If the AND'ing of the 2 masks has no bits, then only original shifted
929-
// bits survive. NO sign-extension bits survive the maskings.
930-
if( (sign_bits_mask & mask) == 0 ) {
931-
// Use zero-fill shift instead
932-
Node *zshift = phase->transform(new URShiftLNode(in1->in(1), in1->in(2)));
933-
return new AndLNode(zshift, in(2));
927+
if (shift != 0) {
928+
const julong sign_bits_mask = ~(((julong)CONST64(1) << (julong)(BitsPerJavaLong - shift)) -1);
929+
// If the AND'ing of the 2 masks has no bits, then only original shifted
930+
// bits survive. NO sign-extension bits survive the maskings.
931+
if( (sign_bits_mask & mask) == 0 ) {
932+
// Use zero-fill shift instead
933+
Node *zshift = phase->transform(new URShiftLNode(in1->in(1), in1->in(2)));
934+
return new AndLNode(zshift, in(2));
935+
}
934936
}
935937
}
936938
}

0 commit comments

Comments
 (0)