2828import soot .MethodOrMethodContext ;
2929import soot .PackManager ;
3030import soot .PatchingChain ;
31+ import soot .PointsToAnalysis ;
3132import soot .Scene ;
3233import soot .SootMethod ;
3334import soot .Unit ;
9899import soot .jimple .infoflow .util .SootMethodRepresentationParser ;
99100import soot .jimple .infoflow .util .SystemClassHandler ;
100101import soot .jimple .toolkits .callgraph .ReachableMethods ;
102+ import soot .jimple .toolkits .pointer .DumbPointerAnalysis ;
101103import soot .options .Options ;
102104
103105/**
@@ -1095,6 +1097,10 @@ protected void eliminateDeadCode(ISourceSinkManager sourcesSinks) {
10951097 icfgFactory .buildBiDirICFG (config .getCallgraphAlgorithm (), config .getEnableExceptionTracking ()), null ,
10961098 null , null , new AccessPathFactory (config ), null );
10971099
1100+ // Dead code elimination may drop the points-to analysis. We need to restore it.
1101+ final Scene scene = Scene .v ();
1102+ PointsToAnalysis pta = scene .getPointsToAnalysis ();
1103+
10981104 // We need to exclude the dummy main method and all other artificial methods
10991105 // that the entry point creator may have generated as well
11001106 Set <SootMethod > excludedMethods = new HashSet <>();
@@ -1105,6 +1111,16 @@ protected void eliminateDeadCode(ISourceSinkManager sourcesSinks) {
11051111 ICodeOptimizer dce = new DeadCodeEliminator ();
11061112 dce .initialize (config );
11071113 dce .run (dceManager , excludedMethods , sourcesSinks , taintWrapper );
1114+
1115+ // Restore the points-to analysis. This may restore a PAG that contains outdated
1116+ // methods, but it's still better than running the entire callgraph algorithm
1117+ // again. Continuing with the DumbPointerAnalysis is not a viable solution
1118+ // either, since it heavily over-approximates.
1119+ if (pta != null && !(pta instanceof DumbPointerAnalysis )) {
1120+ PointsToAnalysis newPta = scene .getPointsToAnalysis ();
1121+ if (newPta == null || newPta instanceof DumbPointerAnalysis )
1122+ scene .setPointsToAnalysis (pta );
1123+ }
11081124 }
11091125
11101126 protected Collection <SootMethod > getMethodsForSeeds (IInfoflowCFG icfg ) {
0 commit comments