Skip to content

Commit

Permalink
Merge pull request #351 from scala-native/topic/fix-divulong-sig
Browse files Browse the repository at this point in the history
Fix #350
  • Loading branch information
densh committed Oct 24, 2016
2 parents 7adba28 + c999672 commit 2c2ed58
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package object runtime {
def divUInt(l: Int, r: Int): Int = undefined

/** Intrinsified unsigned devision on longs. */
def divULong(l: Long, r: Long): Int = undefined
def divULong(l: Long, r: Long): Long = undefined

/** Intrinsified unsigned remainder on ints. */
def remUInt(l: Int, r: Int): Int = undefined
Expand All @@ -24,10 +24,7 @@ package object runtime {
def remULong(l: Long, r: Long): Long = undefined

/** Intrinsified byte to unsigned int converstion. */
def byteToUInt(b: Byte): Int = {
if (b > 0) 0 + b
else Byte.MaxValue.toInt + (-b)
}
def byteToUInt(b: Byte): Int = undefined

/** Intrinsified byte to unsigned long conversion. */
def byteToULong(b: Byte): Long = undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1534,9 +1534,10 @@ abstract class NirCodeGen
}

def genCoercion(
value: Val, fromty: nir.Type, toty: nir.Type, focus: Focus): Focus =
if (fromty == toty) focus withValue value
else {
value: Val, fromty: nir.Type, toty: nir.Type, focus: Focus): Focus = {
if (fromty == toty) {
focus withValue value
} else {
val conv = (fromty, toty) match {
case (nir.Type.Ptr, _: nir.Type.RefKind) =>
Conv.Bitcast
Expand All @@ -1557,6 +1558,7 @@ abstract class NirCodeGen
}
focus withOp Op.Conv(conv, toty, value)
}
}

def coercionTypes(code: Int) = {
import scalaPrimitives._
Expand Down
8 changes: 8 additions & 0 deletions unit-tests/src/main/scala/scala/scalanative/issues/_350.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package scala.scalanative.issues

object _350 extends tests.Suite {
test("github.com/scala-native/scala-native/issues/350") {
val div = java.lang.Long.divideUnsigned(42L, 2L)
assert(div == 21L)
}
}
1 change: 1 addition & 0 deletions unit-tests/src/main/scala/tests/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ object Main {
scala.scalanative.issues._260,
scala.scalanative.issues._314,
scala.scalanative.issues._337,
scala.scalanative.issues._350,
scala.scalanative.native.CStringSuite,
scala.scalanative.native.CInteropSuite,
scala.scalanative.native.InstanceOfSuite,
Expand Down

0 comments on commit 2c2ed58

Please sign in to comment.