Skip to content

Commit 72914ba

Browse files
CaelmBleiddLipen
andauthored
More fixes for real applications (#283)
--------- Co-authored-by: Konstantin Chukharev <lipen00@gmail.com>
1 parent c9d843a commit 72914ba

49 files changed

Lines changed: 1398 additions & 856 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

buildSrc/src/main/kotlin/Dependencies.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ object Versions {
66
const val clikt = "5.0.0"
77
const val detekt = "1.23.7"
88
const val ini4j = "0.5.4"
9-
const val jacodb = "4ff7243d3a"
9+
const val jacodb = "5889d3c784"
1010
const val juliet = "1.3.2"
1111
const val junit = "5.9.3"
1212
const val kotlin = "2.1.0"

usvm-ts/src/main/kotlin/org/usvm/machine/TsContext.kt

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import org.jacodb.ets.model.EtsAliasType
66
import org.jacodb.ets.model.EtsAnyType
77
import org.jacodb.ets.model.EtsArrayType
88
import org.jacodb.ets.model.EtsBooleanType
9+
import org.jacodb.ets.model.EtsEnumValueType
10+
import org.jacodb.ets.model.EtsGenericType
911
import org.jacodb.ets.model.EtsNullType
1012
import org.jacodb.ets.model.EtsNumberType
1113
import org.jacodb.ets.model.EtsRefType
@@ -29,10 +31,12 @@ import org.usvm.api.allocateConcreteRef
2931
import org.usvm.api.typeStreamOf
3032
import org.usvm.collection.field.UFieldLValue
3133
import org.usvm.isTrue
34+
import org.usvm.machine.Constants.Companion.MAGIC_OFFSET
3235
import org.usvm.machine.expr.TsUndefinedSort
3336
import org.usvm.machine.expr.TsUnresolvedSort
3437
import org.usvm.machine.expr.TsVoidSort
3538
import org.usvm.machine.expr.TsVoidValue
39+
import org.usvm.machine.expr.tctx
3640
import org.usvm.machine.interpreter.TsStepScope
3741
import org.usvm.machine.types.EtsFakeType
3842
import org.usvm.memory.UReadOnlyMemory
@@ -76,6 +80,16 @@ class TsContext(
7680
is EtsAnyType -> unresolvedSort
7781
is EtsUnknownType -> unresolvedSort
7882
is EtsAliasType -> typeToSort(type.originalType)
83+
is EtsEnumValueType -> unresolvedSort
84+
85+
is EtsGenericType -> {
86+
if (type.constraint == null && type.defaultType == null) {
87+
unresolvedSort
88+
} else {
89+
TODO("Not yet implemented")
90+
}
91+
}
92+
7993
else -> TODO("${type::class.simpleName} is not yet supported: $type")
8094
}
8195

@@ -152,6 +166,22 @@ class TsContext(
152166
}
153167
}
154168

169+
fun UHeapRef.unwrapRef(scope: TsStepScope): UHeapRef {
170+
if (isFakeObject()) {
171+
return extractRef(scope)
172+
}
173+
return this
174+
}
175+
176+
fun UHeapRef.unwrapRefWithPathConstraint(scope: TsStepScope): UHeapRef = with(tctx) {
177+
if (this@unwrapRefWithPathConstraint.isFakeObject()) {
178+
scope.assert(getFakeType(scope).refTypeExpr)
179+
extractRef(scope)
180+
} else {
181+
asExpr(addressSort)
182+
}
183+
}
184+
155185
fun createFakeObjectRef(): UConcreteHeapRef {
156186
val address = mkAddressCounter().freshAllocatedAddress() + MAGIC_OFFSET
157187
return mkConcreteHeapRef(address)
@@ -235,7 +265,13 @@ class TsContext(
235265
}
236266
}
237267

238-
const val MAGIC_OFFSET = 1000000
268+
class Constants {
269+
companion object {
270+
const val STATIC_METHODS_FORK_LIMIT = 5
271+
const val MAGIC_OFFSET = 1000000
272+
}
273+
}
274+
239275

240276
enum class IntermediateLValueField {
241277
BOOL, FP, REF

usvm-ts/src/main/kotlin/org/usvm/machine/TsInterpreterObserver.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ interface TsInterpreterObserver : UInterpreterObserver {
2424

2525
fun onCallWithUnresolvedArguments(
2626
simpleValueResolver: TsSimpleValueResolver,
27-
stmt: EtsCallExpr,
27+
expr: EtsCallExpr,
2828
scope: TsStepScope,
2929
) {
3030
// default empty implementation

usvm-ts/src/main/kotlin/org/usvm/machine/TsMachine.kt

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ import org.usvm.statistics.collectors.TargetsReachedStatesCollector
2626
import org.usvm.statistics.constraints.SoftConstraintsObserver
2727
import org.usvm.statistics.distances.CfgStatisticsImpl
2828
import org.usvm.statistics.distances.PlainCallGraphStatistics
29+
import org.usvm.stopstrategies.StopStrategy
2930
import org.usvm.stopstrategies.createStopStrategy
31+
import org.usvm.util.TsStateVisualizer
3032
import org.usvm.util.humanReadableSignature
3133
import kotlin.time.Duration.Companion.seconds
3234

@@ -95,20 +97,36 @@ class TsMachine(
9597
val observers = mutableListOf<UMachineObserver<TsState>>(coverageStatistics)
9698
observers.add(statesCollector)
9799

100+
if (tsOptions.enableVisualization) {
101+
observers += TsStateVisualizer()
102+
}
103+
98104
if (options.useSoftConstraints) {
99105
observers.add(SoftConstraintsObserver())
100106
}
101107

102108
val stepsStatistics = StepsStatistics<EtsMethod, TsState>()
103109

104-
val stopStrategy = createStopStrategy(
105-
options,
106-
targets,
107-
timeStatisticsFactory = { timeStatistics },
108-
stepsStatisticsFactory = { stepsStatistics },
109-
coverageStatisticsFactory = { coverageStatistics },
110-
getCollectedStatesCount = { statesCollector.collectedStates.size }
111-
)
110+
val stopStrategy = object : StopStrategy {
111+
val strategy = createStopStrategy(
112+
options,
113+
targets,
114+
timeStatisticsFactory = { timeStatistics },
115+
stepsStatisticsFactory = { stepsStatistics },
116+
coverageStatisticsFactory = { coverageStatistics },
117+
getCollectedStatesCount = { statesCollector.collectedStates.size },
118+
)
119+
120+
override fun shouldStop(): Boolean {
121+
val result = strategy.shouldStop()
122+
123+
if (result) {
124+
logger.warn { "Stop strategy finished execution: ${strategy.stopReason()}" }
125+
}
126+
127+
return result
128+
}
129+
}
112130

113131
observers.add(timeStatistics)
114132
observers.add(stepsStatistics)

usvm-ts/src/main/kotlin/org/usvm/machine/TsOptions.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ package org.usvm.machine
22

33
data class TsOptions(
44
val interproceduralAnalysis: Boolean = true,
5+
val enableVisualization: Boolean = false,
56
)

0 commit comments

Comments
 (0)