diff --git a/sootup.core/src/main/java/sootup/core/jimple/common/ref/JArrayRef.java b/sootup.core/src/main/java/sootup/core/jimple/common/ref/JArrayRef.java index 43e4d641590..7cd15bb3fdd 100644 --- a/sootup.core/src/main/java/sootup/core/jimple/common/ref/JArrayRef.java +++ b/sootup.core/src/main/java/sootup/core/jimple/common/ref/JArrayRef.java @@ -27,7 +27,9 @@ import javax.annotation.Nonnull; import sootup.core.jimple.basic.*; import sootup.core.jimple.visitor.RefVisitor; +import sootup.core.types.ArrayType; import sootup.core.types.Type; +import sootup.core.types.UnknownType; import sootup.core.util.Copyable; import sootup.core.util.printer.StmtPrinter; @@ -88,7 +90,12 @@ public List getUses() { @Override @Nonnull public Type getType() { - return base.getType(); + Type baseType = base.getType(); + if(baseType instanceof ArrayType) { + return ((ArrayType)baseType).getElementType(); + } else { + return UnknownType.getInstance(); + } } @Override diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java index 3c84cbaa119..aaa17475999 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmMethodSource.java @@ -252,13 +252,18 @@ private Object resolveAnnotationsInDefaultValue(Object a) { @Nonnull private JavaLocal getOrCreateLocal(int idx) { + return getOrCreateLocal(idx, null); + } + + @Nonnull + private JavaLocal getOrCreateLocal(int idx, @Nullable Type typeHint) { if (idx >= maxLocals) { throw new IllegalArgumentException("Invalid local index: " + idx); } JavaLocal local = locals.get(idx); if (local == null) { String name = determineLocalName(idx, false); // FIXME: isField - local = JavaJimple.newLocal(name, UnknownType.getInstance(), Collections.emptyList()); + local = JavaJimple.newLocal(name, typeHint != null ? typeHint : UnknownType.getInstance(), Collections.emptyList()); locals.set(idx, local); } return local; @@ -291,9 +296,14 @@ void setStmt(@Nonnull AbstractInsnNode insn, @Nonnull Stmt stmt) { @Nonnull Local newStackLocal() { + return newStackLocal(UnknownType.getInstance()); + } + + @Nonnull + Local newStackLocal(Type type) { int idx = nextLocal++; JavaLocal l = - JavaJimple.newLocal("$stack" + idx, UnknownType.getInstance(), Collections.emptyList()); + JavaJimple.newLocal("$stack" + idx, type, Collections.emptyList()); locals.set(idx, l); return l; } @@ -1213,7 +1223,7 @@ private void convertVarStoreInsn(@Nonnull VarInsnNode insn) { OperandMerging merging = operandStack.getOrCreateMerging(insn); Operand opr = dword ? operandStack.popDual() : operandStack.pop(); merging.mergeInputs(opr); - Local local = getOrCreateLocal(insn.var); + Local local = getOrCreateLocal(insn.var, opr.value.getType()); AbstractDefinitionStmt as; if (opr.stackLocal == null || opr.stackLocal == local) { // Can skip creating a new stack local for the operand diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/Operand.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/Operand.java index 5f185ce9224..a2ef2b58853 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/Operand.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/Operand.java @@ -67,7 +67,7 @@ class Operand { Local getOrAssignValueToStackLocal() { if (stackLocal == null) { - changeStackLocal(methodSource.newStackLocal()); + changeStackLocal(methodSource.newStackLocal(value.getType())); } return stackLocal; diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/typeresolving/CastCounterTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/typeresolving/CastCounterTest.java index f6f4e1482aa..e11df897308 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/typeresolving/CastCounterTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/typeresolving/CastCounterTest.java @@ -149,8 +149,9 @@ public void testAssignStmtWithNewCasts() { Assert.assertEquals( Stream.of( "CastCounterDemos $l0", - "Super1[] $#l0, $#l1", - "unknown $l1, $l2, $stack3", + "Sub1 $stack3", + "Super1 $l2", + "Super1[] $#l0, $#l1, $l1", "$l0 := @this: CastCounterDemos", "$l1 = newarray (Super1)[10]", "$stack3 = new Sub1",