blackdrag commented on code in PR #2707:
URL: https://github.com/apache/groovy/pull/2707#discussion_r3604382620


##########
src/test/groovy/org/codehaus/groovy/classgen/asm/PeepholeOptimizingMethodVisitorTest.groovy:
##########
@@ -329,16 +329,91 @@ final class PeepholeOptimizingMethodVisitorTest {
         assert opcodeLines(bytecode) == ['IINC 0 1', 'RETURN']
     }
 
+    @Test
+    void removesLoadAndAttachedCheckcastBeforePop() {
+        def bytecode = sequenceFor('(Ljava/lang/Object;)V') {
+            visitVarInsn(Opcodes.ALOAD, 0)
+            visitTypeInsn(Opcodes.CHECKCAST, 'java/lang/String')
+            visitInsn(Opcodes.POP)
+            visitInsn(RETURN)
+        }
+
+        // ALOAD + CHECKCAST are both dead once the value is discarded.
+        assert opcodeLines(bytecode) == ['RETURN']
+    }
+
     @Test
     void removesStandaloneCheckcastBeforePop() {
         def bytecode = sequenceFor('(Ljava/lang/Object;)V') {
             visitVarInsn(Opcodes.ALOAD, 0)
+            visitInsn(Opcodes.NOP) // force the load to flush so CHECKCAST is 
standalone
             visitTypeInsn(Opcodes.CHECKCAST, 'java/lang/String')
             visitInsn(Opcodes.POP)
             visitInsn(RETURN)
         }
 
-        assert opcodeLines(bytecode) == ['ALOAD 0', 'POP', 'RETURN']
+        assert opcodeLines(bytecode) == ['ALOAD 0', 'NOP', 'POP', 'RETURN']

Review Comment:
   agreed, the cast exception should be retained.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to