From 8481c4bfc2601d1aa12ec4937c34d15f34f90d4e Mon Sep 17 00:00:00 2001 From: Christian Banse Date: Sun, 31 Dec 2023 20:00:16 +0100 Subject: [PATCH] Use information of operand value to determine type for java locals This PR uses the already existing information of the operand's value type to determine the type for java locals. Previously, most of the stack variables were of "unknown" type . Fixes #635 --- .../sootup/java/bytecode/frontend/AsmMethodSource.java | 7 ++++++- .../main/java/sootup/java/bytecode/frontend/Operand.java | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) 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..adee45052ad 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 @@ -291,9 +291,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; } 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;