Skip to content

Commit

Permalink
more cases & fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kadirayk committed Mar 6, 2023
1 parent 639b430 commit 2e3fb93
Show file tree
Hide file tree
Showing 36 changed files with 528 additions and 82 deletions.
4 changes: 2 additions & 2 deletions src/main/java/analysis/IDELinearConstantAnalysisProblem.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public class IDELinearConstantAnalysisProblem extends DefaultJimpleIDETabulation

protected InterproceduralCFG<Unit, SootMethod> icfg;

protected final static Integer TOP = Integer.MIN_VALUE; // Unknown
public final static Integer TOP = Integer.MIN_VALUE; // Unknown

protected final static Integer BOTTOM = Integer.MAX_VALUE; // Not Constant
public final static Integer BOTTOM = Integer.MAX_VALUE; // Not Constant


public IDELinearConstantAnalysisProblem(InterproceduralCFG<Unit, SootMethod> icfg) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package analysis.edgefunctions;

import analysis.IDELinearConstantAnalysisProblem;
import analysis.data.DFF;
import analysis.edgefunctions.normal.IntegerAssign;
import analysis.edgefunctions.normal.IntegerBinop;
Expand All @@ -14,7 +15,7 @@

public class CPANormalEdgeFunctionProvider {

private final static EdgeFunction<Integer> ALL_BOTTOM = new AllBottom<>(Integer.MAX_VALUE);
private final static EdgeFunction<Integer> ALL_BOTTOM = new IntegerAllBottom(IDELinearConstantAnalysisProblem.BOTTOM);

private EdgeFunction<Integer> edgeFunction;

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/analysis/edgefunctions/IntegerAllBottom.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package analysis.edgefunctions;

import heros.EdgeFunction;
import heros.edgefunc.AllBottom;

public class IntegerAllBottom extends AllBottom<Integer> {

public IntegerAllBottom(Integer bottomElement) {
super(bottomElement);
}

@Override
public EdgeFunction<Integer> meetWith(EdgeFunction<Integer> otherFunction) {
return this; // this should override everything
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package analysis.edgefunctions.normal;

import analysis.IDELinearConstantAnalysisProblem;
import analysis.edgefunctions.IntegerAllBottom;
import heros.EdgeFunction;
import heros.edgefunc.AllBottom;
import heros.edgefunc.EdgeIdentity;
Expand Down Expand Up @@ -66,11 +68,11 @@ public EdgeFunction<Integer> meetWith(EdgeFunction<Integer> otherFunction) {
if(valueFromOtherBranch==valueFromThisBranch){
return this;
}else{
return new AllBottom<>(Integer.MAX_VALUE);
return new IntegerAllBottom(IDELinearConstantAnalysisProblem.BOTTOM);
}
}else if(otherFunction instanceof IntegerBinop){
return new AllBottom<>(Integer.MAX_VALUE);
}else if(otherFunction instanceof AllBottom){
return new IntegerAllBottom(IDELinearConstantAnalysisProblem.BOTTOM);
}else if(otherFunction instanceof IntegerAllBottom){
return otherFunction;
}
throw new RuntimeException("can't meeet: " + this.toString() + " and " + otherFunction.toString());
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/analysis/edgefunctions/normal/IntegerBinop.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package analysis.edgefunctions.normal;

import analysis.IDELinearConstantAnalysisProblem;
import analysis.data.DFF;
import analysis.edgefunctions.IntegerAllBottom;
import heros.EdgeFunction;
import heros.edgefunc.EdgeIdentity;
import soot.Value;
Expand Down Expand Up @@ -65,8 +67,16 @@ public static int executeBinOperation(String op, int lhs, int rhs) {

@Override
public EdgeFunction<Integer> meetWith(EdgeFunction otherFunction) {
throw new UnsupportedOperationException("int i = j op const .meetWith()");
// return this;
if(otherFunction instanceof EdgeIdentity){
return this;
}else if(otherFunction instanceof IntegerAssign){
return new IntegerAllBottom(IDELinearConstantAnalysisProblem.BOTTOM);
}else if(otherFunction instanceof IntegerBinop){
return new IntegerAllBottom(IDELinearConstantAnalysisProblem.BOTTOM);
}else if(otherFunction instanceof IntegerAllBottom){
return otherFunction;
}
throw new RuntimeException("can't meeet: " + this.toString() + " and " + otherFunction.toString());
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/analysis/edgefunctions/normal/IntegerTop.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package analysis.edgefunctions.normal;

import analysis.IDELinearConstantAnalysisProblem;
import heros.EdgeFunction;

/**
Expand All @@ -9,7 +10,7 @@ public class IntegerTop implements EdgeFunction<Integer> {

private static final IntegerTop instance = new IntegerTop();

Integer value = Integer.MIN_VALUE;
Integer value = IDELinearConstantAnalysisProblem.TOP;

private IntegerTop(){
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package target.constant;

public class SimpleAssignment4 {
public class Assignment {

/**
* Simple assignment
*/
public void entryPoint() {
int a = 100;
int b = 200;
int c = a * 4 + 13;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package target.constant;

public class SimpleAssignment2 {
public class Assignment2 {

/**
* Assignment with binop of constants
*/
public void entryPoint() {
int a = 100;
int b = 200;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package target.constant;

public class SimpleAssignment3 {
public class Assignment3 {

/**
* Assignment with binop of linear value
*/
public void entryPoint() {
int a = 100;
int b = 200;
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/target/constant/Assignment4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package target.constant;

public class Assignment4 {

/**
* Assignment with linear value multi const
*/
public void entryPoint() {
int a = 100;
int b = 200;
int c = a * 4 + 13;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package target.constant;

public class SimpleAssignment5 {
public class Assignment5 {

/**
* Assignment with overwrite
*/
public void entryPoint() {
int a = 100;
int b = 200;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package target.constant;

public class SimpleAssignment6 {
public class Assignment6 {

/**
* Increment value
*/
public void entryPoint() {
int a = 100;
int b = 200;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package target.constant;

public class SimpleAssignment7 {
public class Assignment7 {

/**
* various operators
*/
public void entryPoint() {
int a = 100;
int b = a + 10;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package target.constant;

public class SimpleAssignment8 {
public class Assignment8 {

/**
* assignment chain
*/
public void entryPoint() {
int a = 100;
int b = a;
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/target/constant/Branching.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

public class Branching {

/**
* Same value in different branches used in the end
* @param p unknown
*/
void entryPoint(boolean p) {
int a = 0;
int b = 1;
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/target/constant/Branching2.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

public class Branching2 {

/**
* same value in different branches not used in the end
* @param p unknown
*/
void entryPoint(boolean p) {
int a = 0;
int b = 0;
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/target/constant/Branching3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package target.constant;

public class Branching3 {

/**
* different values in different branches used in the end
* @param p unknown
*/
void entryPoint(boolean p) {
int a = 0;
if (p) {
a = 23;
} else {
a = 42;
}
int c = a;
}

}
20 changes: 20 additions & 0 deletions src/test/java/target/constant/Branching4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package target.constant;

public class Branching4 {

/**
* different values in different branches not used in the end
* @param p unknown
*/
void entryPoint(boolean p) {
int a = 0;
int b = 10;
if (p) {
a = 23;
} else {
a = 42;
}
int c = b;
}

}
20 changes: 20 additions & 0 deletions src/test/java/target/constant/Branching5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package target.constant;

public class Branching5 {

/**
* different values in different branches meet with linear op
* @param p unknown
*/
void entryPoint(boolean p) {
int a = 0;
int b = 10;
if (p) {
a = 23;
} else {
a = 42;
}
int c = a + 3;
}

}
20 changes: 20 additions & 0 deletions src/test/java/target/constant/Branching6.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package target.constant;

public class Branching6 {

/**
* same values in different branches meet with linear op
* @param p unknown
*/
void entryPoint(boolean p) {
int a = 0;
int b = 10;
if (p) {
a = 23;
} else {
a = 23;
}
int c = a + 3;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package target.constant;

public class FunctionCall {
public class Context {

int id(int a) {
return a;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package target.constant;

public class FunctionCall2 {
public class Context2 {

int increment(int a) {
return a + 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package target.constant;

public class FunctionCall3 {
public class Context3 {

int add(int a, int b) {
return a + 13;
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/target/constant/Context4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package target.constant;


public class Context4 {

int increment(int a) {
return a + 1;
}

int nestedCaller(int a){
return nestedCaller1(a);
}

int nestedCaller1(int a){
return increment(a);
}

/**
* nested calls
*/
public void entryPoint() {
int a = 100;
int b = 200;
int c = increment(a);
int d = nestedCaller(b);
}

}
3 changes: 3 additions & 0 deletions src/test/java/target/constant/Field.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ public class Field {
int x;
int y;

/**
* Field loaded with constant
*/
public void entryPoint() {
Field field = new Field();
field.x = 100;
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/target/constant/Field2.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ public class Field2 {
int x;
int y;

/**
* field stored to local
*/
public void entryPoint() {
Field2 field = new Field2();
field.x = 100;
Expand Down
Loading

0 comments on commit 2e3fb93

Please sign in to comment.