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

port intraprocedural analysis and fix the long tail.. #664

Merged
merged 56 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
9d30a1f
initial commit for intraprocedural analysis
swissiety Aug 8, 2023
7d7dda0
progress on priority queue backed by indexed universe
swissiety Sep 1, 2023
992975a
refactor copy() as a ctor
swissiety Sep 1, 2023
4fdc123
refactor getDefsOfLocal; JFieldref as leftOp of an assignment is not …
swissiety Sep 15, 2023
377cd31
improve comment
swissiety Sep 15, 2023
543bde6
set default BodyInterceptors
swissiety Sep 15, 2023
42803b3
add comment
swissiety Sep 15, 2023
ebf120f
remove obsolete BodyGenerator reference which could lead to confusion…
swissiety Sep 15, 2023
e8ab497
style
swissiety Sep 15, 2023
a280859
make Aggregator work as in the description
swissiety Sep 15, 2023
38b9734
replace generics in JIdentityStmt, JAssignStmt with covariant return …
swissiety Sep 15, 2023
443db38
fix MutableBlockStmtGraph.insertBefore() : indexing of Stmt->Block wa…
swissiety Sep 15, 2023
a921226
fix Interceptors.. and Introduce a new marker interface LhsValuewhich…
swissiety Sep 15, 2023
a2782cc
fix LhsValue leftovers
swissiety Sep 15, 2023
cdd7c10
fix TypeResolver handling of incomplete information in View
swissiety Sep 15, 2023
b789f9a
fix wrong assumption - and simplified the code.
swissiety Sep 15, 2023
6a1b86c
more LhsValue typesafety..
swissiety Sep 15, 2023
46069c3
fix porting bug: soot used getUses() and not getDefs()
swissiety Sep 15, 2023
01368ed
refactor: LhsValue to LValue; Local.getDefsOfLocal(...) to Local.getD…
swissiety Sep 21, 2023
94659fd
progress
swissiety Sep 26, 2023
a374cd4
colon without a mandatory whitespace should be parsed as well
swissiety Sep 27, 2023
5d3c01d
remove SourceType.Phantom as it does not make sence in SootUp anymore…
swissiety Oct 4, 2023
366b3e8
add FallsThroughStmt interface; make BranchingStmt and Stmt an interf…
swissiety Oct 4, 2023
0cd3e40
handle nullType Local naming
swissiety Oct 4, 2023
4e213ce
bugfix input
swissiety Oct 4, 2023
d0facc1
progress; add FallsThroughStmt and refactored Branching/-Stmt
swissiety Oct 4, 2023
2264537
refactor methodname
swissiety Oct 5, 2023
08b6ee4
fix missing mapping info
swissiety Oct 6, 2023
cd42555
fix TypeAssigner: don't fail completely if type is not augmentable
swissiety Oct 6, 2023
fe673b5
fix testcases: adapting to fixed local naming..
swissiety Oct 6, 2023
637fbd9
fix aggregator combining variables even when conflicting uses exist
Timbals Oct 6, 2023
6f25a81
fix tests; add Category
swissiety Oct 6, 2023
e8c1cb0
Merge pull request #700 from Timbals/fix/aggregator
swissiety Oct 7, 2023
cf724db
improve `removeEdge`
Timbals Oct 10, 2023
bec430e
re-enable `modifyStmtToBlockAtTail` test and fix removing edges of loops
Timbals Oct 10, 2023
3c36753
add a test for block merging in `removeEdge`
Timbals Oct 10, 2023
9154b7a
fix not setting the predecessor correctly when dividing blocks
Timbals Oct 10, 2023
94bfeb3
improve `removeNode`
Timbals Oct 10, 2023
94ce405
test for a conditional followed by a block that gets removed by the `…
Timbals Oct 10, 2023
7e8a121
fix flaky tests by removing usages of `getBlocksSorted`
Timbals Oct 17, 2023
2aa4b2b
apply formatting
Timbals Oct 17, 2023
f1d453a
Merge pull request #708 from Timbals/fix/MutableBlockStmtGraph
swissiety Oct 18, 2023
f953837
style
swissiety Oct 18, 2023
596b6dd
fix Iterator in getBlocksSorted()
swissiety Oct 18, 2023
3795d35
wip: fixing Stmt edge connection modification.. theres a problem with…
swissiety Oct 20, 2023
8957a17
fix core; multiple NPEs
swissiety Oct 20, 2023
fa04b05
adapting tests
swissiety Oct 20, 2023
e528214
add deprecation notices..
swissiety Oct 20, 2023
6717701
elaborate api with improved typing: Stmts with zero expected successo…
swissiety Oct 23, 2023
c84bd22
Merge branch 'develop' into add/intraprocedural
swissiety Oct 23, 2023
9f52504
fix merge leftover
swissiety Oct 23, 2023
c0d4a80
remove an unnecessary Fix me comment
JonasKlauke Oct 25, 2023
3ed4a06
added removed licence header
JonasKlauke Oct 25, 2023
85d97c4
fmt
JonasKlauke Oct 25, 2023
36153fe
cleanup
swissiety Oct 26, 2023
4669188
Merge branch 'develop' into add/intraprocedural
swissiety Oct 26, 2023
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 @@ -28,9 +28,10 @@
import java.util.Set;
import sootup.core.graph.StmtGraph;
import sootup.core.jimple.basic.Value;
import sootup.core.jimple.common.stmt.AbstractStmt;

/**
* @param <N> Nodes in the CFG, e.g. {@link sootup.core.jimple.common.stmt.Stmt}
* @param <N> Nodes in the CFG, e.g. {@link AbstractStmt}
* @param <M> Method representation, e.g. {@link sootup.core.model.SootMethod}
*/
public interface BiDiInterproceduralCFG<N, M> extends InterproceduralCFG<N, M> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package sootup.analysis.intraprocedural;

/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/

import java.util.IdentityHashMap;
import java.util.Map;
import javax.annotation.Nonnull;
import sootup.core.graph.BasicBlock;
import sootup.core.graph.StmtGraph;
import sootup.core.jimple.common.stmt.Stmt;

/**
* An abstract class providing a meta-framework for carrying out dataflow analysis. This class
* provides common methods and fields required by the BranchedFlowAnalysis and FlowAnalysis abstract
* classes.
*
* @param <F> abstraction type for the Facts
*/
public abstract class AbstractFlowAnalysis<F> {

/** The graph being analysed. */
protected final StmtGraph<? extends BasicBlock<?>> graph;

/** Maps graph nodes to IN sets. */
protected final Map<Stmt, F> stmtToBeforeFlow;

/** Constructs a flow analysis on the given <code>StmtGraph</code>. */
public AbstractFlowAnalysis(StmtGraph<? extends BasicBlock<?>> graph) {
this.graph = graph;
this.stmtToBeforeFlow = new IdentityHashMap<>(graph.getNodes().size() * 2 + 1);
}

Check warning on line 51 in sootup.analysis/src/main/java/sootup/analysis/intraprocedural/AbstractFlowAnalysis.java

View check run for this annotation

Codecov / codecov/patch

sootup.analysis/src/main/java/sootup/analysis/intraprocedural/AbstractFlowAnalysis.java#L48-L51

Added lines #L48 - L51 were not covered by tests

/** Returns the flow object corresponding to the initial values for each graph node. */
@Nonnull
protected abstract F newInitialFlow();

/** Determines whether <code>entryInitialFlow()</code> is applied to trap handlers. */
// FIXME: [ms] implement as an option
protected boolean treatTrapHandlersAsEntries() {
return false;

Check warning on line 60 in sootup.analysis/src/main/java/sootup/analysis/intraprocedural/AbstractFlowAnalysis.java

View check run for this annotation

Codecov / codecov/patch

sootup.analysis/src/main/java/sootup/analysis/intraprocedural/AbstractFlowAnalysis.java#L60

Added line #L60 was not covered by tests
}

/** Returns true if this analysis is forwards. */
protected abstract boolean isForward();

/**
* Compute the merge of the <code>in1</code> and <code>in2</code> sets, putting the result into
* <code>out</code>. The behavior of this function depends on the implementation ( it may be
* necessary to check whether <code>in1</code> and <code>in2</code> are equal or aliased ). Used
* by the doAnalysis method.
*/
protected abstract void merge(@Nonnull F in1, @Nonnull F in2, @Nonnull F out);

/**
* Merges in1 and in2 into out, just before node succNode. By default, this method just calls
* merge(A,A,A), ignoring the node.
*/
protected void merge(@Nonnull Stmt succNode, @Nonnull F in1, @Nonnull F in2, @Nonnull F out) {
merge(in1, in2, out);
}

Check warning on line 80 in sootup.analysis/src/main/java/sootup/analysis/intraprocedural/AbstractFlowAnalysis.java

View check run for this annotation

Codecov / codecov/patch

sootup.analysis/src/main/java/sootup/analysis/intraprocedural/AbstractFlowAnalysis.java#L79-L80

Added lines #L79 - L80 were not covered by tests

/** Creates a copy of the <code>source</code> flow object in <code>dest</code>. */
protected abstract void copy(@Nonnull F source, @Nonnull F dest);

/**
* Carries out the actual flow analysis. Typically called from a concrete FlowAnalysis's
* constructor.
*/
protected abstract void execute();

/** Accessor function returning value of IN set for s. */
@Nonnull
public F getFlowBefore(@Nonnull Stmt s) {
return stmtToBeforeFlow.get(s);

Check warning on line 94 in sootup.analysis/src/main/java/sootup/analysis/intraprocedural/AbstractFlowAnalysis.java

View check run for this annotation

Codecov / codecov/patch

sootup.analysis/src/main/java/sootup/analysis/intraprocedural/AbstractFlowAnalysis.java#L94

Added line #L94 was not covered by tests
}

/** Merges in into inout, just before node succNode. */
protected void mergeInto(@Nonnull Stmt succNode, @Nonnull F inout, @Nonnull F in) {
F tmp = newInitialFlow();
merge(succNode, inout, in, tmp);
copy(tmp, inout);
}

Check warning on line 102 in sootup.analysis/src/main/java/sootup/analysis/intraprocedural/AbstractFlowAnalysis.java

View check run for this annotation

Codecov / codecov/patch

sootup.analysis/src/main/java/sootup/analysis/intraprocedural/AbstractFlowAnalysis.java#L99-L102

Added lines #L99 - L102 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package sootup.analysis.intraprocedural;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import javax.annotation.Nonnull;
import sootup.core.jimple.basic.Local;

/** simple dataflow fact for interprocedural dataflow analysis adaptable with a state enum * */
public class Fact<S> {

/** The aliases that point to the same object. */
@Nonnull private final Set<Local> aliases;

/** The state of the object. */
@Nonnull private S state;

public Fact(@Nonnull S initialState) {
this(new HashSet<>(), initialState);
}

Check warning on line 20 in sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java

View check run for this annotation

Codecov / codecov/patch

sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java#L19-L20

Added lines #L19 - L20 were not covered by tests

public Fact(@Nonnull Fact<S> originFact) {
this(new HashSet<>(originFact.aliases), originFact.state);
}

Check warning on line 24 in sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java

View check run for this annotation

Codecov / codecov/patch

sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java#L23-L24

Added lines #L23 - L24 were not covered by tests

protected Fact(@Nonnull Set<Local> aliases, @Nonnull S initialState) {
this.aliases = aliases;
this.state = initialState;
}

Check warning on line 29 in sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java

View check run for this annotation

Codecov / codecov/patch

sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java#L26-L29

Added lines #L26 - L29 were not covered by tests

public void updateState(@Nonnull S state) {
this.state = state;
}

Check warning on line 33 in sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java

View check run for this annotation

Codecov / codecov/patch

sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java#L32-L33

Added lines #L32 - L33 were not covered by tests

public void addAlias(@Nonnull Local alias) {
this.aliases.add(alias);
}

Check warning on line 37 in sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java

View check run for this annotation

Codecov / codecov/patch

sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java#L36-L37

Added lines #L36 - L37 were not covered by tests

public boolean containsAlias(@Nonnull Local value) {
return aliases.contains(value);

Check warning on line 40 in sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java

View check run for this annotation

Codecov / codecov/patch

sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java#L40

Added line #L40 was not covered by tests
}

@Nonnull
public S getState() {
return state;

Check warning on line 45 in sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java

View check run for this annotation

Codecov / codecov/patch

sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java#L45

Added line #L45 was not covered by tests
}

@Override
public String toString() {
return "(" + aliases + ", " + state + ")";

Check warning on line 50 in sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java

View check run for this annotation

Codecov / codecov/patch

sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java#L50

Added line #L50 was not covered by tests
}

@Override
public int hashCode() {
return Objects.hash(aliases, state);

Check warning on line 55 in sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java

View check run for this annotation

Codecov / codecov/patch

sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java#L55

Added line #L55 was not covered by tests
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;

Check warning on line 61 in sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java

View check run for this annotation

Codecov / codecov/patch

sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java#L61

Added line #L61 was not covered by tests
}
if (obj == null) {
return false;

Check warning on line 64 in sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java

View check run for this annotation

Codecov / codecov/patch

sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java#L64

Added line #L64 was not covered by tests
}
if (getClass() != obj.getClass()) {
return false;

Check warning on line 67 in sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java

View check run for this annotation

Codecov / codecov/patch

sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java#L67

Added line #L67 was not covered by tests
}

Fact other = (Fact) obj;

Check warning on line 70 in sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java

View check run for this annotation

Codecov / codecov/patch

sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java#L70

Added line #L70 was not covered by tests
if (!aliases.equals(other.aliases)) {
return false;

Check warning on line 72 in sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java

View check run for this annotation

Codecov / codecov/patch

sootup.analysis/src/main/java/sootup/analysis/intraprocedural/Fact.java#L72

Added line #L72 was not covered by tests
}

return state == other.state;
}
}
Loading