Skip to content

Commit 1241533

Browse files
committed
Fix: add missing special case for lshift of 0.
1 parent 0101f0b commit 1241533

File tree

1 file changed

+20
-3
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints

1 file changed

+20
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,11 +1185,20 @@ Object doLLOvf(long left, long right) {
11851185
}
11861186
}
11871187

1188-
@Specialization
1188+
@Specialization(guards = {"left == 0", "right.isZeroOrPositive()"})
1189+
static int doLPiZero(@SuppressWarnings("unused") long left, @SuppressWarnings("unused") PInt right) {
1190+
return 0;
1191+
}
1192+
1193+
@Specialization(replaces = "doLPiZero")
11891194
PInt doLPi(long left, PInt right) {
11901195
raiseNegativeShiftCount(!right.isZeroOrPositive());
1196+
if (left == 0) {
1197+
return factory().createInt(BigInteger.ZERO);
1198+
}
11911199
try {
1192-
return factory().createInt(op(PInt.longToBigInteger(left), right.intValueExact()));
1200+
int iright = right.intValueExact();
1201+
return factory().createInt(op(PInt.longToBigInteger(left), iright));
11931202
} catch (ArithmeticException e) {
11941203
throw raise(PythonErrorType.OverflowError);
11951204
}
@@ -1219,9 +1228,17 @@ PInt doPiL(PInt left, long right) {
12191228
}
12201229
}
12211230

1222-
@Specialization
1231+
@Specialization(guards = {"left.isZero()", "right.isZeroOrPositive()"})
1232+
static int doPiPiZero(@SuppressWarnings("unused") PInt left, @SuppressWarnings("unused") PInt right) {
1233+
return 0;
1234+
}
1235+
1236+
@Specialization(replaces = "doPiPiZero")
12231237
PInt doPiPi(PInt left, PInt right) {
12241238
raiseNegativeShiftCount(!right.isZeroOrPositive());
1239+
if (left.isZero()) {
1240+
return factory().createInt(BigInteger.ZERO);
1241+
}
12251242
try {
12261243
return factory().createInt(op(left.getValue(), right.intValueExact()));
12271244
} catch (ArithmeticException e) {

0 commit comments

Comments
 (0)