@@ -85,7 +85,6 @@ private boolean simplifyBlock(MethodNode mth, BlockNode block) {
8585 int insnCount = list .size ();
8686 InsnNode modInsn = simplifyInsn (mth , insn , null );
8787 if (modInsn != null ) {
88- modInsn .rebindArgs ();
8988 if (i < list .size () && list .get (i ) == insn ) {
9089 list .set (i , modInsn );
9190 } else {
@@ -95,6 +94,8 @@ private boolean simplifyBlock(MethodNode mth, BlockNode block) {
9594 }
9695 list .set (idx , modInsn );
9796 }
97+ InsnRemover .unbindInsn (mth , insn );
98+ modInsn .rebindArgs ();
9899 if (list .size () < insnCount ) {
99100 // some insns removed => restart block processing
100101 simplifyBlock (mth , block );
@@ -239,8 +240,8 @@ private static InsnNode processCast(MethodNode mth, IndexInsnNode castInsn, @Nul
239240 || shadowedByOuterCast (mth .root (), castToType , parentInsn )) {
240241 InsnNode insnNode = new InsnNode (InsnType .MOVE , 1 );
241242 insnNode .setOffset (castInsn .getOffset ());
242- insnNode .setResult (castInsn .getResult ());
243- insnNode .addArg (castArg );
243+ insnNode .setResult (InsnNode . duplicateArg ( castInsn .getResult () ));
244+ insnNode .addArg (castArg . duplicate () );
244245 return insnNode ;
245246 }
246247 return null ;
@@ -576,7 +577,11 @@ private static InsnNode simplifyArith(ArithNode arith) {
576577 if (litArg .isNegative ()) {
577578 LiteralArg negLitArg = litArg .negate ();
578579 if (negLitArg != null ) {
579- return new ArithNode (ArithOp .SUB , arith .getResult (), arith .getArg (0 ), negLitArg );
580+ RegisterArg resArg = InsnNode .duplicateArg (arith .getResult ());
581+ ArithNode newInsn = new ArithNode (ArithOp .SUB , resArg , arith .getArg (0 ).duplicate (), negLitArg );
582+ newInsn .copyAttributesFrom (arith );
583+ newInsn .setOffset (arith .getOffset ());
584+ return newInsn ;
580585 }
581586 }
582587 break ;
@@ -586,10 +591,12 @@ private static InsnNode simplifyArith(ArithNode arith) {
586591 InsnArg firstArg = arith .getArg (0 );
587592 long lit = litArg .getLiteral ();
588593 if (firstArg .getType () == ArgType .BOOLEAN && (lit == 0 || lit == 1 )) {
589- InsnNode node = new InsnNode (lit == 0 ? InsnType .MOVE : InsnType .NOT , 1 );
590- node .setResult (arith .getResult ());
591- node .addArg (firstArg );
592- return node ;
594+ InsnNode newInsn = new InsnNode (lit == 0 ? InsnType .MOVE : InsnType .NOT , 1 );
595+ newInsn .setResult (InsnNode .duplicateArg (arith .getResult ()));
596+ newInsn .addArg (firstArg .duplicate ());
597+ newInsn .copyAttributesFrom (arith );
598+ newInsn .setOffset (arith .getOffset ());
599+ return newInsn ;
593600 }
594601 break ;
595602 }
@@ -637,16 +644,22 @@ private static ArithNode convertFieldArith(MethodNode mth, InsnNode insn) {
637644 }
638645 if (wrapType == InsnType .ARITH ) {
639646 ArithNode ar = (ArithNode ) wrap ;
640- return ArithNode .oneArgOp (ar .getOp (), fArg , ar .getArg (1 ));
647+ ArithNode newInsn = ArithNode .oneArgOp (ar .getOp (), fArg , ar .getArg (1 ).duplicate ());
648+ newInsn .copyAttributesFrom (insn );
649+ newInsn .setOffset (insn .getOffset ());
650+ return newInsn ;
641651 }
642652 int argsCount = wrap .getArgsCount ();
643653 InsnNode concat = new InsnNode (InsnType .STR_CONCAT , argsCount - 1 );
644654 for (int i = 1 ; i < argsCount ; i ++) {
645- concat .addArg (wrap .getArg (i ));
655+ concat .addArg (wrap .getArg (i ). duplicate () );
646656 }
647657 InsnArg concatArg = InsnArg .wrapArg (concat );
648658 concatArg .setType (ArgType .STRING );
649- return ArithNode .oneArgOp (ArithOp .ADD , fArg , concatArg );
659+ ArithNode newInsn = ArithNode .oneArgOp (ArithOp .ADD , fArg , concatArg );
660+ newInsn .copyAttributesFrom (wrap );
661+ newInsn .setOffset (wrap .getOffset ());
662+ return newInsn ;
650663 } catch (Exception e ) {
651664 LOG .debug ("Can't convert field arith insn: {}, mth: {}" , insn , mth , e );
652665 }
0 commit comments