We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hey all,
It looks like >> is acting like >>> when inlined.
>>
>>>
This bug showed up in an sbt 0.13.12 project running Scala 2.11.8. I compiled a file containing this object, with -optimize enabled:
-optimize
object Bug { @inline def inlineShift(x: Int): Int = x >> 1 def shift(x: Int): Int = x >> 1 }
Then started a console with sbt console, and found the following discrepancy between the behavior of the two functions:
sbt console
scala> Bug.inlineShift(Int.MinValue) res0: Int = 1073741824 scala> Bug.shift(Int.MinValue) res1: Int = -1073741824 scala> Int.MinValue res2: Int = -2147483648
The functions both returned Int.MinValue when I removed the -optimize flag.
Int.MinValue
The text was updated successfully, but these errors were encountered:
Imported From: https://issues.scala-lang.org/browse/SI-10037?orig=1 Reporter: Sam Ritchie (sritchie) Affected Versions: 2.11.8
Sorry, something went wrong.
Sam Ritchie (sritchie) said: Sorry for all the edits. I can't figure out how to format the first block of code.
@som-snytt said:
GenASM and separate compilation:
$ ~/scala-2.11.8/bin/scalac -optimize -Ybackend:GenBCode shifted.scala && ~/scala-2.11.8/bin/scala -optimize -Ybackend:GenBCode Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_101). Type in expressions for evaluation. Or try :help. scala> shifted.Bug.inlineShift(Int.MinValue) res0: Int = -1073741824 scala> :quit $ rm shifted/*.class $ ~/scala-2.11.8/bin/scalac -optimize -Ybackend:GenASM shifted.scala && ~/scala-2.11.8/bin/scala -optimize -Ybackend:GenASM Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_101). Type in expressions for evaluation. Or try :help. scala> shifted.Bug.inlineShift(Int.MinValue) res0: Int = 1073741824 scala> :quit amarki@amarki-462836:~/tmp$ ~/scala-2.11.8/bin/scalac -optimize shifted.scala && ~/scala-2.11.8/bin/scala shifted.Test -1073741824 -1073741824 amarki@amarki-462836:~/tmp$ cat shifted.scala package shifted object Bug { @inline def inlineShift(x: Int): Int = x >> 1 def shift(x: Int): Int = x >> 1 def f(x: Int): Int = inlineShift(x) // ok } object Test extends App { println(Bug.inlineShift(Int.MinValue)) // ok println(Bug.shift(Int.MinValue)) }
@som-snytt said: scala/scala#5518
som-snytt
No branches or pull requests
Hey all,
It looks like
>>
is acting like>>>
when inlined.This bug showed up in an sbt 0.13.12 project running Scala 2.11.8. I compiled a file containing this object, with
-optimize
enabled:Then started a console with
sbt console
, and found the following discrepancy between the behavior of the two functions:The functions both returned
Int.MinValue
when I removed the-optimize
flag.The text was updated successfully, but these errors were encountered: