more CPA work
This commit is contained in:
parent
2948ecf31d
commit
3156f03145
|
@ -0,0 +1,43 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 IBM Corporation.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.ibm.wala.cast.js.test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil;
|
||||
import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder;
|
||||
import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil;
|
||||
import com.ibm.wala.cast.js.translator.CAstRhinoTranslatorFactory;
|
||||
import com.ibm.wala.ipa.callgraph.CallGraph;
|
||||
import com.ibm.wala.ipa.callgraph.propagation.CPAContextSelector;
|
||||
import com.ibm.wala.util.CancelException;
|
||||
import com.ibm.wala.util.WalaException;
|
||||
|
||||
public class TestCPA {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil.setTranslatorFactory(new CAstRhinoTranslatorFactory());
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-access")
|
||||
@Test public void testCPA() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
||||
JSCFABuilder builder = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "cpa.js");
|
||||
builder.setContextSelector(new CPAContextSelector(builder.getContextSelector()));
|
||||
CallGraph CG = builder.makeCallGraph(builder.getOptions());
|
||||
JSCallGraphUtil.AVOID_DUMP = false;
|
||||
CAstCallGraphUtil.dumpCG(builder.getPointerAnalysis(), CG);
|
||||
}
|
||||
|
||||
}
|
|
@ -18,8 +18,7 @@ import static com.ibm.wala.cast.js.test.JSCallGraphBuilderUtil.makeScriptScope;
|
|||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
|
@ -18,8 +18,6 @@ import org.junit.Test;
|
|||
import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder;
|
||||
import com.ibm.wala.cast.js.translator.CAstRhinoTranslatorFactory;
|
||||
import com.ibm.wala.cast.js.util.Util;
|
||||
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
|
||||
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
|
||||
import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder;
|
||||
import com.ibm.wala.util.CancelException;
|
||||
import com.ibm.wala.util.WalaException;
|
||||
|
@ -40,7 +38,7 @@ public class TestSimpleCallGraphShapeRhino extends TestSimpleCallGraphShape {
|
|||
public void test214631() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
||||
JSCFABuilder b = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "214631.js");
|
||||
b.makeCallGraph(b.getOptions());
|
||||
PointerAnalysis<InstanceKey> PA = b.getPointerAnalysis();
|
||||
b.getPointerAnalysis();
|
||||
// just make sure this does not crash
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
function three(a, b, c) {
|
||||
return a;
|
||||
}
|
||||
|
||||
function two_a(a, b) {
|
||||
return three(a, b, "string");
|
||||
}
|
||||
|
||||
function two_b(a, b) {
|
||||
return three(a, b, 17);
|
||||
}
|
||||
|
||||
var x = "one";
|
||||
var y = "two";
|
||||
|
||||
two_a(x, y);
|
||||
two_a(y, x);
|
||||
|
||||
for(var i = 0; i < 2; i++) {
|
||||
two_b(i==0?x:y, i==0?y:x);
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
var t = "this is a long string";
|
||||
var t = new String("this is a long string");
|
||||
|
||||
var bar = t.substring(0, 10);
|
||||
|
||||
|
|
|
@ -12,7 +12,3 @@ var p = id;
|
|||
var s = p.apply(null, [theTwo]);
|
||||
s();
|
||||
|
||||
// test invoking with non-array argsList
|
||||
p.apply(null, o);
|
||||
|
||||
|
||||
|
|
|
@ -219,6 +219,7 @@ DOMHTMLDocument = function DOMHTMLDocument() {
|
|||
}
|
||||
|
||||
Location = function Location(){
|
||||
this.hash = new String();
|
||||
this.port = new String();
|
||||
this.port.value = new String();
|
||||
this.host = new String();
|
||||
|
|
|
@ -141,7 +141,9 @@ public class JavaScriptFunctionApplyContextInterpreter extends AstContextInsensi
|
|||
|
||||
private int passActualPropertyValsAsParams(JSInstructionFactory insts, int nargs, JavaScriptSummary S, int[] paramsToPassToInvoked) {
|
||||
// read an arbitrary property name via EachElementGet
|
||||
int curValNum = nargs + 2;
|
||||
int nullVn = nargs + 2;
|
||||
S.addConstant(nullVn, new ConstantValue(null));
|
||||
int curValNum = nargs + 3;
|
||||
for (int i = 1; i < paramsToPassToInvoked.length; i++) {
|
||||
// create a String constant for i-1
|
||||
final int constVN = curValNum++;
|
||||
|
@ -152,8 +154,12 @@ public class JavaScriptFunctionApplyContextInterpreter extends AstContextInsensi
|
|||
//S.addConstant(constVN, new ConstantValue(i-1));
|
||||
int propertyReadResult = curValNum++;
|
||||
// 4 is position of arguments array
|
||||
S.addStatement(insts.PropertyWrite(S.getNumberOfStatements(), 4, constVN, nullVn));
|
||||
S.getNextProgramCounter();
|
||||
|
||||
S.addStatement(insts.PropertyRead(S.getNumberOfStatements(), propertyReadResult, 4, constVN));
|
||||
S.getNextProgramCounter();
|
||||
|
||||
paramsToPassToInvoked[i] = propertyReadResult;
|
||||
}
|
||||
return curValNum;
|
||||
|
|
|
@ -97,6 +97,10 @@ public class JavaScriptConstructorFunctions {
|
|||
|
||||
S.addConstant(new Integer(8), new ConstantValue(value));
|
||||
S.addStatement(insts.PutInstruction(S.getNumberOfStatements(), 5, 8, "$value"));
|
||||
if (value instanceof String) {
|
||||
S.addConstant(9, new ConstantValue(0));
|
||||
S.addStatement(insts.PutInstruction(S.getNumberOfStatements(), 5, 9, "length"));
|
||||
}
|
||||
S.getNextProgramCounter();
|
||||
|
||||
S.addStatement(insts.ReturnInstruction(S.getNumberOfStatements(), 5, false));
|
||||
|
@ -286,6 +290,11 @@ public class JavaScriptConstructorFunctions {
|
|||
JavaScriptSummary S = new JavaScriptSummary(ref, 1);
|
||||
|
||||
S.addConstant(new Integer(2), new ConstantValue(""));
|
||||
|
||||
S.addConstant(new Integer(3), new ConstantValue(0));
|
||||
S.addStatement(insts.PutInstruction(S.getNumberOfStatements(), 2, 3, "length"));
|
||||
S.getNextProgramCounter();
|
||||
|
||||
S.addStatement(insts.ReturnInstruction(S.getNumberOfStatements(), 2, false));
|
||||
S.getNextProgramCounter();
|
||||
|
||||
|
|
|
@ -206,6 +206,11 @@ public class JavaScriptLoader extends CAstAbstractModuleLoader {
|
|||
throw new UnsupportedOperationException("JavaScript does not permit explicit pointers");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean methodsHaveDeclaredParameterTypes() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSInstructionFactory instructionFactory() {
|
||||
return new JSInstructionFactory() {
|
||||
|
|
|
@ -754,4 +754,9 @@ public class JavaLanguage extends LanguageImpl implements BytecodeLanguage, Cons
|
|||
return MethodReference.findOrCreate(this, loader, instruction.getClassType(), instruction.getMethodName(),
|
||||
instruction.getMethodSignature());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean methodsHaveDeclaredParameterTypes() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -139,4 +139,10 @@ public interface Language {
|
|||
* @see TypeInference
|
||||
*/
|
||||
PrimitiveType getPrimitive(TypeReference reference);
|
||||
|
||||
/**
|
||||
* do MethodReference objects have declared parameter types?
|
||||
*/
|
||||
boolean methodsHaveDeclaredParameterTypes();
|
||||
|
||||
}
|
||||
|
|
|
@ -40,10 +40,10 @@ public interface ContextKey {
|
|||
* context key representing some parameter index, useful, e.g. for CPA-style
|
||||
* context-sensitivity policies.
|
||||
*/
|
||||
public static class ParameterKey implements ContextKey {
|
||||
static class ParameterKey implements ContextKey {
|
||||
public final int index;
|
||||
|
||||
public ParameterKey(int index) {
|
||||
private ParameterKey(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ public class CPAContextSelector implements ContextSelector {
|
|||
public IntSet getRelevantParameters(CGNode caller, CallSiteReference site) {
|
||||
MutableIntSet s = IntSetUtil.make();
|
||||
for(int i = 0; i < caller.getIR().getCalls(site)[0].getNumberOfUses(); i++) {
|
||||
if (dispatchIndex(site, i)) {
|
||||
if (!caller.getMethod().getDeclaringClass().getClassLoader().getLanguage().methodsHaveDeclaredParameterTypes() || dispatchIndex(site, i)) {
|
||||
s.add(i);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,6 @@ import com.ibm.wala.types.MethodReference;
|
|||
import com.ibm.wala.types.Selector;
|
||||
import com.ibm.wala.types.TypeReference;
|
||||
import com.ibm.wala.util.CancelException;
|
||||
import com.ibm.wala.util.CancelRuntimeException;
|
||||
import com.ibm.wala.util.MonitorUtil;
|
||||
import com.ibm.wala.util.MonitorUtil.IProgressMonitor;
|
||||
import com.ibm.wala.util.collections.HashSetFactory;
|
||||
|
@ -533,7 +532,6 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
|
|||
f.apply(keys);
|
||||
} else {
|
||||
final int p = params[pi];
|
||||
int vn = call.getUse(p);
|
||||
InstanceKey[] ik = invariants != null ? invariants[p] : null;
|
||||
if (ik != null) {
|
||||
if (ik.length > 0) {
|
||||
|
@ -542,12 +540,12 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
|
|||
keys[pi] = ik[i];
|
||||
rec(pi + 1, rhsi);
|
||||
}
|
||||
} else {
|
||||
} /* else {
|
||||
if (!site.isDispatch() || p != 0) {
|
||||
keys[pi] = null;
|
||||
rec(pi + 1, rhsi);
|
||||
}
|
||||
}
|
||||
}
|
||||
} */
|
||||
} else {
|
||||
IntSet s = getParamObjects(pi, rhsi);
|
||||
if (s != null && !s.isEmpty()) {
|
||||
|
@ -558,12 +556,12 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
|
|||
rec(pi + 1, rhsi + 1);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
} /*else {
|
||||
if (!site.isDispatch() || p != 0) {
|
||||
keys[pi] = null;
|
||||
rec(pi + 1, rhsi + 1);
|
||||
}
|
||||
}
|
||||
} */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue