Skip to content

Commit

Permalink
[Truffle] Fix overflow in Fixnum#-
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Jan 8, 2015
1 parent 989e723 commit f58aec1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
16 changes: 10 additions & 6 deletions core/src/main/java/org/jruby/truffle/nodes/core/FixnumNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;
import com.oracle.truffle.api.utilities.ConditionProfile;
import org.jruby.truffle.nodes.methods.UnsupportedOperationBehavior;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyArray;
Expand Down Expand Up @@ -155,21 +154,26 @@ public long subWithOverflow(int a, int b) {
return (long) a - (long) b;
}

@Specialization
public double sub(int a, double b) {
return a - b;
@Specialization(rewriteOn = ArithmeticException.class)
public long sub(int a, long b) {
return ExactMath.subtractExact(a, b);
}

@Specialization
public long sub(int a, long b) {
return ExactMath.subtractExact(a, b);
public Object subWithOverflow(int a, long b) {
return fixnumOrBignum(bignum(a).subtract(bignum(b)));
}

@Specialization
public Object sub(int a, RubyBignum b) {
return fixnumOrBignum(bignum(a).subtract(b));
}

@Specialization
public double sub(int a, double b) {
return a - b;
}

@Specialization(rewriteOn = ArithmeticException.class)
public long sub(long a, int b) {
return ExactMath.subtractExact(a, b);
Expand Down
1 change: 0 additions & 1 deletion spec/truffle/tags/core/fixnum/uminus_tags.txt

This file was deleted.

0 comments on commit f58aec1

Please sign in to comment.