Skip to content
New issue

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

optimizer changes behavior of IDIV, LDIV, IREM, LREM bytecode instructions when the result is dropped #7607

Closed
scabug opened this issue Jun 25, 2013 · 3 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Jun 25, 2013

When compiled with -optimize the following program goes wrong:

object Test {

  def main(args: Array[String]) {
    (1 / 0)
  }

}

It swallows the ArithmeticException that the JVMS specifies should be thrown. The bytecode emitted is:

  // access flags 0x1
  public main([Ljava/lang/String;)V
   L0
    LINENUMBER 5 L0
    RETURN
   L1
    LOCALVARIABLE this LTest$; L0 L1 0
    LOCALVARIABLE args [Ljava/lang/String; L0 L1 1
    MAXSTACK = 0
    MAXLOCALS = 2

The problem goes away when the body of main is changed to use the result of (1 / 0) (as opposed to discarding the result as above). For example -optimize emits correct bytecode for:

object Test {

  def main(args: Array[String]) {
    println(1 / 0)
  }

}

Originally reported in https://groups.google.com/forum/#!searchin/akka-user/optimize/akka-user/r0Teq08f-YU/2Dfl1yQKbL0J

@scabug
Copy link
Author

scabug commented Jun 25, 2013

@scabug
Copy link
Author

scabug commented Jun 26, 2013

@magarciaEPFL said:
I've added tests for this bug in the branch for the new optimizer,
magarciaEPFL/scala@d525b6c

(the new optimizer isn't prone to this bug)

@scabug
Copy link
Author

scabug commented Jun 6, 2014

@lrytz said:
fixed in scala/scala#3765, duplicate of #8601

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants