Skip to content

Commit

Permalink
Merge pull request #347 from ragnr/topic/sizeof-unsigned
Browse files Browse the repository at this point in the history
Correct sizeof for unsigned types. Fixes #328
  • Loading branch information
densh committed Oct 24, 2016
2 parents a782f95 + 63c7d5b commit 7adba28
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1414,10 +1414,9 @@ abstract class NirCodeGen
val Apply(_, Seq(ctp)) = app

val sym = extractClassFromImplicitClassTag(ctp)
val ty = genTypeSym(sym)

code match {
case SIZEOF => focus withOp Op.Sizeof(ty)
case SIZEOF => focus withOp Op.Sizeof(genTypeSym(sym, boxUnsigned = false))
case TYPEOF => focus withValue genTypeSymValue(sym)
case _ => unreachable
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package scala.scalanative.native

object UnsignedSizeOfSuite extends tests.Suite {

test("UByte's size should be 1") {
assert(sizeof[UByte] == 1)
}

test("UShort's size should be 2") {
assert(sizeof[UShort] == 2)
}

test("UInt's size should be 4") {
assert(sizeof[UInt] == 4)
}

test("ULong's size should be 8") {
assert(sizeof[ULong] == 8)
}

}
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 @@ -16,6 +16,7 @@ object Main {
scala.scalanative.native.CStringSuite,
scala.scalanative.native.CInteropSuite,
scala.scalanative.native.InstanceOfSuite,
scala.scalanative.native.UnsignedSizeOfSuite,
scala.ArrayIntCopySuite,
scala.ArrayDoubleCopySuite,
scala.ArrayObjectCopySuite,
Expand Down

0 comments on commit 7adba28

Please sign in to comment.