Uploaded image for project: 'Scala Programming Language'
  1. Scala Programming Language
  2. SI-7607

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

    Details

    • Type: Bug
    • Status: CLOSED
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Scala 2.11.2
    • Component/s: Optimizer
    • Labels:

      Description

      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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                retronym Jason Zaugg
                Reporter:
                magarcia Miguel Garcia
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: