Skip to content

Commit f478a08

Browse files
authored
Merge pull request #314 from lisa-analyzer/release-roundup
Release roundup
2 parents 94adcde + e07d916 commit f478a08

File tree

14 files changed

+354
-8
lines changed

14 files changed

+354
-8
lines changed

lisa/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# project properties
22
group = 'it.unive'
3-
version = 0.1b9
3+
version = 0.1
44

55
# gradle build properties
66
org.gradle.caching=true

lisa/lisa-analyses/src/main/java/it/unive/lisa/analysis/heap/TypeBasedHeap.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ public ExpressionSet visit(
259259
ProgramPoint pp = (ProgramPoint) params[0];
260260
SemanticOracle oracle = (SemanticOracle) params[1];
261261

262-
for (SymbolicExpression rec : receiver)
262+
for (SymbolicExpression rec : receiver) {
263+
rec = removeTypingExpressions(rec);
263264
if (rec instanceof MemoryPointer) {
264265
MemoryPointer pid = (MemoryPointer) rec;
265266
for (Type t : oracle.getRuntimeTypesOf(pid, pp, oracle))
@@ -270,6 +271,7 @@ public ExpressionSet visit(
270271
result.add(e);
271272
}
272273
}
274+
}
273275
return new ExpressionSet(result);
274276
}
275277

@@ -298,7 +300,8 @@ public ExpressionSet visit(
298300
ProgramPoint pp = (ProgramPoint) params[0];
299301
SemanticOracle oracle = (SemanticOracle) params[1];
300302

301-
for (SymbolicExpression refExp : ref)
303+
for (SymbolicExpression refExp : ref) {
304+
refExp = removeTypingExpressions(refExp);
302305
if (refExp instanceof HeapLocation) {
303306
Set<Type> rt = oracle.getRuntimeTypesOf(refExp, pp, oracle);
304307
Type sup = Type.commonSupertype(rt, Untyped.INSTANCE);
@@ -308,6 +311,7 @@ public ExpressionSet visit(
308311
refExp.getCodeLocation());
309312
result.add(e);
310313
}
314+
}
311315

312316
return new ExpressionSet(result);
313317
}
@@ -323,6 +327,7 @@ public ExpressionSet visit(
323327
SemanticOracle oracle = (SemanticOracle) params[1];
324328

325329
for (SymbolicExpression derefExp : deref) {
330+
derefExp = removeTypingExpressions(derefExp);
326331
if (derefExp instanceof Variable) {
327332
Variable var = (Variable) derefExp;
328333
for (Type t : oracle.getRuntimeTypesOf(var, pp, oracle))

lisa/lisa-analyses/src/main/java/it/unive/lisa/analysis/heap/pointbased/AllocationSite.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,14 @@ public String getField() {
179179
*/
180180
public abstract AllocationSite withField(
181181
SymbolicExpression field);
182+
183+
/**
184+
* Yields a modified version of this allocation site with the given type.
185+
*
186+
* @param type the new type
187+
*
188+
* @return the modified allocation site
189+
*/
190+
public abstract AllocationSite withType(
191+
Type type);
182192
}

lisa/lisa-analyses/src/main/java/it/unive/lisa/analysis/heap/pointbased/AllocationSiteBasedAnalysis.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ public ExpressionSet visit(
320320
Object... params)
321321
throws SemanticException {
322322
Set<SymbolicExpression> result = new HashSet<>();
323-
for (SymbolicExpression rec : receiver)
323+
for (SymbolicExpression rec : receiver) {
324+
rec = removeTypingExpressions(rec);
324325
if (rec instanceof MemoryPointer) {
325326
MemoryPointer pid = (MemoryPointer) rec;
326327
AllocationSite site = (AllocationSite) pid.getReferencedLocation();
@@ -347,7 +348,8 @@ public ExpressionSet visit(
347348

348349
result.add(e);
349350
} else if (rec instanceof AllocationSite)
350-
result.add(rec);
351+
result.add(((AllocationSite) rec).withType(expression.getStaticType()));
352+
}
351353

352354
return new ExpressionSet(result);
353355
}
@@ -387,7 +389,8 @@ public ExpressionSet visit(
387389
throws SemanticException {
388390
Set<SymbolicExpression> result = new HashSet<>();
389391

390-
for (SymbolicExpression loc : arg)
392+
for (SymbolicExpression loc : arg) {
393+
loc = removeTypingExpressions(loc);
391394
if (loc instanceof AllocationSite) {
392395
AllocationSite allocSite = (AllocationSite) loc;
393396
MemoryPointer e = new MemoryPointer(
@@ -403,6 +406,7 @@ public ExpressionSet visit(
403406
result.add(e);
404407
} else
405408
result.add(loc);
409+
}
406410
return new ExpressionSet(result);
407411
}
408412

@@ -414,7 +418,8 @@ public ExpressionSet visit(
414418
throws SemanticException {
415419
Set<SymbolicExpression> result = new HashSet<>();
416420

417-
for (SymbolicExpression ref : arg)
421+
for (SymbolicExpression ref : arg) {
422+
ref = removeTypingExpressions(ref);
418423
if (ref instanceof MemoryPointer)
419424
result.add(((MemoryPointer) ref).getReferencedLocation());
420425
else if (ref instanceof Identifier) {
@@ -444,6 +449,7 @@ else if (id.getStaticType().isInMemoryType() || id.getStaticType().isUntyped())
444449
}
445450
} else
446451
result.add(ref);
452+
}
447453

448454
return new ExpressionSet(result);
449455
}

lisa/lisa-analyses/src/main/java/it/unive/lisa/analysis/heap/pointbased/FieldSensitivePointBasedHeap.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,16 @@ public ExpressionSet visit(
288288
throws SemanticException {
289289
Set<SymbolicExpression> result = new HashSet<>();
290290

291-
for (SymbolicExpression rec : receiver)
291+
for (SymbolicExpression rec : receiver) {
292+
rec = removeTypingExpressions(rec);
292293
if (rec instanceof MemoryPointer) {
293294
AllocationSite site = (AllocationSite) ((MemoryPointer) rec).getReferencedLocation();
294295
populate(expression, child, result, site);
295296
} else if (rec instanceof AllocationSite) {
296297
AllocationSite site = (AllocationSite) rec;
297298
populate(expression, child, result, site);
298299
}
300+
}
299301

300302
return new ExpressionSet(result);
301303
}

lisa/lisa-analyses/src/main/java/it/unive/lisa/analysis/heap/pointbased/HeapAllocationSite.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,10 @@ public AllocationSite withField(
8888
throw new IllegalStateException("Cannot add a field to an allocation site that already has one");
8989
return new HeapAllocationSite(getStaticType(), getLocationName(), field, isWeak(), getCodeLocation());
9090
}
91+
92+
@Override
93+
public AllocationSite withType(
94+
Type type) {
95+
return new HeapAllocationSite(type, getLocationName(), getField(), isWeak(), getCodeLocation());
96+
}
9197
}

lisa/lisa-analyses/src/main/java/it/unive/lisa/analysis/heap/pointbased/StackAllocationSite.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,10 @@ public AllocationSite withField(
8888
throw new IllegalStateException("Cannot add a field to an allocation site that already has one");
8989
return new StackAllocationSite(getStaticType(), getLocationName(), field, isWeak(), getCodeLocation());
9090
}
91+
92+
@Override
93+
public AllocationSite withType(
94+
Type type) {
95+
return new StackAllocationSite(type, getLocationName(), getField(), isWeak(), getCodeLocation());
96+
}
9197
}

lisa/lisa-analyses/src/test/java/it/unive/lisa/TestParameterProvider.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,16 +271,22 @@ public static <R> R provideParam(
271271
return (R) new ValueEnvironment<>(new SampleNRVD());
272272
if (param == SampleNRVD.class || param == BaseNonRelationalValueDomain.class)
273273
return (R) new SampleNRVD();
274+
if (param == BaseNonRelationalValueDomain[].class)
275+
return (R) new BaseNonRelationalValueDomain[0];
274276

275277
if (param == InferenceSystem.class)
276278
return (R) new InferenceSystem<>(new SampleIV());
277279
if (param == SampleIV.class || param == BaseInferredValue.class)
278280
return (R) new SampleIV();
281+
if (param == BaseInferredValue[].class)
282+
return (R) new BaseInferredValue[0];
279283

280284
if (param == TypeEnvironment.class)
281285
return (R) new TypeEnvironment<>(new SampleNRTD());
282286
if (param == SampleNRTD.class || param == BaseNonRelationalTypeDomain.class)
283287
return (R) new SampleNRTD();
288+
if (param == BaseNonRelationalTypeDomain[].class)
289+
return (R) new BaseNonRelationalTypeDomain[0];
284290

285291
if (param == SemanticOracle.class)
286292
return (R) DefaultConfiguration.defaultAbstractState();

lisa/lisa-analyses/src/test/java/it/unive/lisa/analysis/heap/pointbased/PointBasedHeapTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import it.unive.lisa.program.cfg.CodeLocation;
1818
import it.unive.lisa.program.cfg.ProgramPoint;
1919
import it.unive.lisa.program.type.Int32Type;
20+
import it.unive.lisa.symbolic.SymbolicExpression;
2021
import it.unive.lisa.symbolic.heap.AccessChild;
2122
import it.unive.lisa.symbolic.heap.HeapDereference;
2223
import it.unive.lisa.symbolic.heap.HeapExpression;
@@ -29,7 +30,9 @@
2930
import it.unive.lisa.symbolic.value.OutOfScopeIdentifier;
3031
import it.unive.lisa.symbolic.value.Variable;
3132
import it.unive.lisa.symbolic.value.operator.binary.NumericNonOverflowingAdd;
33+
import it.unive.lisa.symbolic.value.operator.binary.TypeConv;
3234
import it.unive.lisa.type.Type;
35+
import it.unive.lisa.type.TypeTokenType;
3336
import it.unive.lisa.type.Untyped;
3437
import java.util.Collections;
3538
import java.util.HashSet;
@@ -459,4 +462,21 @@ public void testHeapDereferenceRewrite() throws SemanticException {
459462
expectedRewritten = new ExpressionSet(expectedUnknownAlloc);
460463
assertEquals(expectedRewritten, xAssign.rewrite(deref, pp1, fakeOracle));
461464
}
465+
466+
@Test
467+
public void testIssue300() throws SemanticException {
468+
// ((type) x) rewritten in x -> pp1 -> pp1
469+
PointBasedHeap xAssign = topHeap.assign(x,
470+
new HeapReference(untyped,
471+
new MemoryAllocation(untyped, loc1), loc1),
472+
pp1, fakeOracle);
473+
SymbolicExpression e = new AccessChild(intType,
474+
new BinaryExpression(untyped,
475+
new Constant(new TypeTokenType(Collections.singleton(intType)), intType, loc1), x,
476+
TypeConv.INSTANCE,
477+
loc1),
478+
new Constant(intType, 1, loc1), loc1);
479+
ExpressionSet expectedRewritten = new ExpressionSet(alloc1);
480+
assertEquals(expectedRewritten, xAssign.rewrite(e, pp1, fakeOracle));
481+
}
462482
}

lisa/lisa-sdk/src/main/java/it/unive/lisa/analysis/heap/BaseHeapDomain.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import it.unive.lisa.symbolic.value.TernaryExpression;
1919
import it.unive.lisa.symbolic.value.UnaryExpression;
2020
import it.unive.lisa.symbolic.value.ValueExpression;
21+
import it.unive.lisa.symbolic.value.operator.TypeOperator;
22+
import it.unive.lisa.symbolic.value.operator.binary.BinaryOperator;
2123
import java.util.HashSet;
2224
import java.util.List;
2325
import java.util.Set;
@@ -148,6 +150,28 @@ public abstract H semanticsOf(
148150
*/
149151
public abstract static class Rewriter implements ExpressionVisitor<ExpressionSet> {
150152

153+
/**
154+
* Extracts the inner expressions from casts/conversions. If {@code e}
155+
* is of the form {@code (type) e1}, this method returns
156+
* {@code removeTypingExpressions(e1)}. Otherwise, {@code e} is returned
157+
* with no modifications.
158+
*
159+
* @param e the expression to strip from type operators
160+
*
161+
* @return the inner expression, if needed
162+
*/
163+
protected SymbolicExpression removeTypingExpressions(
164+
SymbolicExpression e) {
165+
if (e instanceof BinaryExpression) {
166+
BinaryExpression be = (BinaryExpression) e;
167+
BinaryOperator op = be.getOperator();
168+
if (op instanceof TypeOperator)
169+
return removeTypingExpressions(be.getRight());
170+
}
171+
172+
return e;
173+
}
174+
151175
@Override
152176
public ExpressionSet visit(
153177
UnaryExpression expression,
@@ -240,5 +264,25 @@ public ExpressionSet visit(
240264
throws SemanticException {
241265
return new ExpressionSet(expression);
242266
}
267+
268+
@Override
269+
public ExpressionSet visit(
270+
HeapExpression expression,
271+
ExpressionSet[] subExpressions,
272+
Object... params)
273+
throws SemanticException {
274+
throw new SemanticException(
275+
"No rewriting rule for heap expression of type " + expression.getClass().getName());
276+
}
277+
278+
@Override
279+
public ExpressionSet visit(
280+
ValueExpression expression,
281+
ExpressionSet[] subExpressions,
282+
Object... params)
283+
throws SemanticException {
284+
throw new SemanticException(
285+
"No rewriting rule for value expression of type " + expression.getClass().getName());
286+
}
243287
}
244288
}

0 commit comments

Comments
 (0)