Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use information of operand value to determine type for java locals #789

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Operand {

Local getOrAssignValueToStackLocal() {
if (stackLocal == null) {
changeStackLocal(methodSource.newStackLocal());
changeStackLocal(methodSource.newStackLocal(value.getType()));
}

return stackLocal;
Expand Down
Loading