soot-oss / soot

Soot - A Java optimization framework
GNU Lesser General Public License v2.1
2.89k stars 710 forks source link

Improper translation to Jimple in scenarios involving temporary variables #2085

Open DeepakUniAdel opened 5 months ago

DeepakUniAdel commented 5 months ago

The issue is for the following Java code :

int bitValue = 0; for (int j = 0; j < 32; j++) { bitValue ^= (help >>> j) & 1; }

simple generated is : (34) $j = 0 (35) $j = 0 (36) if $j >= 32 (37) $stack24 = $help >>> $j (38) $stack25 = $stack24 & 1 (39) $j = $j ^ $stack25 (40) $j = $j + 1 (41) goto

Where the variable "bitValue" is completely replaced with a temporary variable "I" twice. The same happens when trying to build Jimple out of the code:

byte[] rv = new byte[size]; int offSet = 0; for(int i = 0; i != arrays.length; ++i) { System.arraycopy(arrays[i], 0, rv, offSet, arrays[i].length); offSet += arrays[i].length; }

    return rv;

(10) $i = newarray (byte)[$size] (11) $offSet = 0 (12) $i = 0 (13) $stack6 = lengthof $arrays (14) if $i == $stack6 (15) $stack9 = $arrays[$i] (16) $stack7 = $arrays[$i] (17) $stack8 = lengthof $stack7 (18) staticinvoke <java.lang.System: void arraycopy(java.lang.Object,int,java.lang.Object,int,int)>($stack9, 0, $i, $offSet, $stack8) (19) $stack10 = $arrays[$i] (20) $stack11 = lengthof $stack10 (21) $offSet = $offSet + $stack11 (22) $i = $i + 1

here again the variable "rv" is replaced with temporary variable "I". Kindly check if this issue is caused due to an error in implementation of the Jimple data structures