Skip to content

Commit

Permalink
Merge branch 'master' into jspecify-mode-wala-util
Browse files Browse the repository at this point in the history
  • Loading branch information
msridhar committed Mar 2, 2024
2 parents 6f598d8 + be01a46 commit 2867d19
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ val mavenRepository: MavenArtifactRepository =
"https://oss.sonatype.org/service/local/staging/deploy/maven2/"))
as String)
credentials {
username = properties["SONATYPE_NEXUS_USERNAME"] as String?
password = properties["SONATYPE_NEXUS_PASSWORD"] as String?
username = findProperty("SONATYPE_NEXUS_USERNAME") as String?
password = findProperty("SONATYPE_NEXUS_PASSWORD") as String?
}
}

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ JavaVersion.current().let {

group = name

version = properties["VERSION_NAME"] as String
version = property("VERSION_NAME") as String

// version of Eclipse JARs to use for Eclipse-integrated WALA components.
val eclipseVersion: EclipseRelease by extra {
Expand Down
3 changes: 1 addition & 2 deletions cast/js/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ val processTestResources by tasks.existing(Copy::class) { from(unpackAjaxslt) {
val testResources: Configuration by configurations.creating { isCanBeResolved = false }

artifacts {
val java: JavaPluginExtension by extensions
add(javadocDestinationDirectory.name, file("${java.docsDir}/javadoc"))
add(javadocDestinationDirectory.name, tasks.javadoc)
add(packageListDirectory.name, createPackageList)
add(testResources.name, processTestResources)
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ public Iterator<NewSiteReference> iterateNewSites(CGNode node) {
throw new IllegalArgumentException("node is null");
}
assert understands(node);
GetMethodContext context = (GetMethodContext) node.getContext();
TypeReference tr = context.getType().getTypeReference();
TypeReference tr =
((TypeAbstraction) node.getContext().get(ContextKey.RECEIVER)).getTypeReference();
if (tr != null) {
return new NonNullSingletonIterator<>(NewSiteReference.make(0, tr));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.Language;
import com.ibm.wala.classLoader.NewSiteReference;
import com.ibm.wala.core.tests.demandpa.AbstractPtrTest;
import com.ibm.wala.core.tests.util.TestConstants;
import com.ibm.wala.core.tests.util.WalaTestCase;
Expand All @@ -30,13 +31,15 @@
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.ipa.callgraph.CallGraphBuilder;
import com.ibm.wala.ipa.callgraph.CallGraphBuilderCancelException;
import com.ibm.wala.ipa.callgraph.CallGraphStats;
import com.ibm.wala.ipa.callgraph.Entrypoint;
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
import com.ibm.wala.ipa.callgraph.impl.AllApplicationEntrypoints;
import com.ibm.wala.ipa.callgraph.impl.DefaultEntrypoint;
import com.ibm.wala.ipa.callgraph.impl.Util;
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
import com.ibm.wala.ipa.callgraph.propagation.LocalPointerKey;
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
import com.ibm.wala.ipa.callgraph.propagation.PointerKey;
import com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder;
Expand All @@ -48,12 +51,14 @@
import com.ibm.wala.ipa.cha.ClassHierarchyFactory;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.ssa.ISSABasicBlock;
import com.ibm.wala.types.ClassLoaderReference;
import com.ibm.wala.types.Descriptor;
import com.ibm.wala.types.MethodReference;
import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.collections.Iterator2Iterable;
import com.ibm.wala.util.collections.IteratorUtil;
import com.ibm.wala.util.collections.Pair;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.graph.Graph;
import com.ibm.wala.util.graph.GraphIntegrity;
Expand Down Expand Up @@ -361,6 +366,44 @@ public void testZeroOneContainerStaticMethods()
"did not find call to valueOf");
}

/** Testing that there is no crash during iteration of points to sets */
@Test
public void testIteratingPointsToSetsForCreationSites()
throws CallGraphBuilderCancelException, IOException, ClassHierarchyException {
AnalysisScope scope =
CallGraphTestUtil.makeJ2SEAnalysisScope(
TestConstants.WALA_TESTDATA, CallGraphTestUtil.REGRESSION_EXCLUSIONS);
ClassHierarchy cha = ClassHierarchyFactory.make(scope);
Iterable<Entrypoint> entrypoints = Util.makeMainEntrypoints(cha, "Lsimple/Example");
AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);
IAnalysisCacheView cache = new AnalysisCacheImpl();
CallGraphBuilder<InstanceKey> builder =
Util.makeZeroCFABuilder(Language.JAVA, options, cache, cha);
CallGraph cg = builder.makeCallGraph(options, null);
PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
for (PointerKey pk : pointerAnalysis.getPointerKeys()) {
if (pk instanceof LocalPointerKey) {
LocalPointerKey lpk = (LocalPointerKey) pk;
String className = lpk.getNode().getMethod().getDeclaringClass().getName().toString();
String methodName = lpk.getNode().getMethod().getName().toString();
ClassLoaderReference clr =
lpk.getNode().getMethod().getDeclaringClass().getClassLoader().getReference();
if (clr.equals(ClassLoaderReference.Application)
&& className.equals("Lsimple/Example")
&& methodName.equals("foo")) {
if (lpk.isParameter()) {
for (InstanceKey ik : pointerAnalysis.getPointsToSet(lpk)) {
Iterator<Pair<CGNode, NewSiteReference>> iterator = ik.getCreationSites(cg);
while (iterator.hasNext()) {
iterator.next(); // making sure there is no crash here
}
}
}
}
}
}
}

/** make main entrypoints, even in the primordial loader. */
public static Iterable<Entrypoint> makePrimordialMainEntrypoints(ClassHierarchy cha) {
final Atom mainMethod = Atom.findOrCreateAsciiAtom("main");
Expand Down
19 changes: 19 additions & 0 deletions core/src/testSubjects/java/simple/Example.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package simple;

public class Example {
private static int i = 0;

public static void main(String[] args) {
Object obj1 = new Object();
Object obj2 = "1";
Object obj3 = 1;
if (i == 0) {
obj1 = obj3;
} else if (i == 1) {
obj2 = obj3;
}
foo(obj1, obj2);
}

private static void foo(Object o1, Object o2) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,23 @@ public Iterator<AbstractStatement> getStatements() {
}

@Override
@SuppressWarnings("rawtypes")
public void addStatement(IFixedPointStatement statement)
public void addStatement(IFixedPointStatement<T> statement)
throws IllegalArgumentException, UnimplementedError {
if (statement == null) {
throw new IllegalArgumentException("statement == null");
}
if (statement instanceof UnaryStatement) {
addStatement((UnaryStatement) statement);
addStatement((UnaryStatement<T>) statement);
} else if (statement instanceof NullaryStatement) {
addStatement((NullaryStatement) statement);
addStatement((NullaryStatement<T>) statement);
} else if (statement instanceof GeneralStatement) {
addStatement((GeneralStatement) statement);
addStatement((GeneralStatement<T>) statement);
} else {
Assertions.UNREACHABLE("unexpected: " + statement.getClass());
}
}

public void addStatement(GeneralStatement<?> s) {
public void addStatement(GeneralStatement<T> s) {
if (s == null) {
throw new IllegalArgumentException("s is null");
}
Expand Down Expand Up @@ -134,7 +133,7 @@ public void addStatement(GeneralStatement<?> s) {
}
}

public void addStatement(UnaryStatement<?> s) {
public void addStatement(UnaryStatement<T> s) {
if (s == null) {
throw new IllegalArgumentException("s is null");
}
Expand All @@ -157,7 +156,7 @@ public void addStatement(UnaryStatement<?> s) {
}
}

public void addStatement(NullaryStatement<?> s) {
public void addStatement(NullaryStatement<T> s) {
if (s == null) {
throw new IllegalArgumentException("s is null");
}
Expand Down

0 comments on commit 2867d19

Please sign in to comment.