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

fix issues with the java bytecode frontend #742

Merged
merged 14 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Binary file not shown.
33 changes: 33 additions & 0 deletions shared-test-resources/miniTestSuite/java6/source/LocalMerging.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
public class LocalMerging {
public void localMergingWithConstant(int n) {
String a = "one";
// The branch returns either a local or a constant.
// Because of the divergence neither `a` nor `"two"` should be inlined,
// but a stack local variable should be created for holding the result of the branch.
System.out.println(n == 1 ? a : "two");
}

public void localMergingWithOtherLocal(int n) {
String a = "one";
String b = "two";
// The branch returns either a local or a different local.
// Because of the divergence neither `a` nor `b` should be inlined,
// but a stack local variable should be created for holding the result of the branch.
System.out.println(n == 1 ? a : b);
}

public void localMergingWithDuplicateValue(int n) {
String a = "one";
// One of the branches for the first argument contains the constant "two"
// and the second argument also contains the constant "two".
// This test ensures that when the first argument gets replaced by a stack local,
// the second argument isn't replaced as well.
System.setProperty(n == 1 ? a : "two", "two");
}

public void localMergingWithInlining(int n) {
String[] arr = new String[] {"a", "b"};
int a = 1;
String b = arr[n == 1 ? 0 : a];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public void caseInvokeStmt(@Nonnull JInvokeStmt stmt) {

@Override
public void caseAssignStmt(@Nonnull JAssignStmt stmt) {
// fall back to the original statement when none of the cases set a result
setResult(stmt);

// uses on the def side.. e.g. a base in an JArrayRef but NOT with a simple Local!
final Value leftOp = stmt.getLeftOp();
Expand Down Expand Up @@ -106,8 +108,6 @@ public void caseAssignStmt(@Nonnull JAssignStmt stmt) {
if (exprVisitor.getResult() != rValue) {
setResult(stmt.withRValue(exprVisitor.getResult()));
}
} else {
setResult(stmt);
}
}

Expand Down
Loading
Loading