Skip to content

Commit fa3fed0

Browse files
authored
Merge pull request #325 from MchKosticyn/master
Concrete memory and unsafe operations fixes
2 parents 96661dc + 3e06213 commit fa3fed0

File tree

28 files changed

+239
-167
lines changed

28 files changed

+239
-167
lines changed

.github/workflows/build_vsharp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55

66
jobs:
77
build:
8-
runs-on: ubuntu-latest
8+
runs-on: ubuntu-22.04
99
steps:
1010
- name: Checkout VSharp
1111
uses: actions/checkout@v3

VSharp.API/VSharpOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public readonly record struct VSharpOptions
8989
private const string DefaultOutputDirectory = "";
9090
private const string DefaultRenderedTestsDirectory = "";
9191
private const bool DefaultRenderTests = false;
92-
private const SearchStrategy DefaultSearchStrategy = SearchStrategy.BFS;
92+
private const SearchStrategy DefaultSearchStrategy = SearchStrategy.ExecutionTreeContributedCoverage;
9393
private const Verbosity DefaultVerbosity = Verbosity.Quiet;
9494
private const uint DefaultRecursionThreshold = 0u;
9595
private const ExplorationMode DefaultExplorationMode = ExplorationMode.Sili;

VSharp.Explorer/Explorer.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ type private SVMExplorer(explorationOptions: ExplorationOptions, statistics: SVM
7575
let emptyState = Memory.EmptyIsolatedState()
7676
let interpreter = ILInterpreter()
7777

78-
7978
do
8079
if options.visualize then
8180
DotVisualizer explorationOptions.outputDirectory :> IVisualizer |> Application.setVisualizer

VSharp.Explorer/Statistics.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ open VSharp.Interpreter.IL
1616
open VSharp.Utils
1717

1818
open CilState
19-
open IpOperations
2019
open CodeLocation
2120

2221
type pob = {loc : codeLocation; lvl : uint; pc : pathCondition}

VSharp.IL/MethodBody.fs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@ type MethodWithBody internal (m : MethodBase) =
8484

8585
let actualMethod =
8686
if not isCSharpInternalCall.Value then m
87-
else Loader.CSharpImplementations[fullGenericMethodName.Value]
87+
else
88+
let method = Loader.CSharpImplementations[fullGenericMethodName.Value]
89+
if method.IsGenericMethod && (m.DeclaringType.IsGenericType || m.IsGenericMethod) then
90+
let _, genericArgs, _ = Reflection.generalizeMethodBase m
91+
method.MakeGenericMethod(genericArgs)
92+
else method
93+
8894
let methodBodyBytes =
8995
if isFSharpInternalCall.Value then null
9096
else actualMethod.GetMethodBody()

VSharp.InternalCalls/Buffer.fs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ module internal Buffer =
5353
let checkDst (info, cilState : cilState) =
5454
match info with
5555
| Some (dstAddress : address) ->
56-
let checkSrc (info, cilState : cilState) =
56+
let checkSrc info (cilState : cilState) =
5757
match info with
5858
| Some (srcAddress : address) ->
5959
let dstType = lazy dstAddress.TypeOfLocation
@@ -71,28 +71,26 @@ module internal Buffer =
7171
match dstAddress, srcAddress with
7272
| _ when allSafe() ->
7373
let value = cilState.Read (Ref srcAddress)
74-
let cilStates = cilState.Write (Ref dstAddress) value
75-
assert(List.length cilStates = 1)
76-
List.head cilStates
74+
cilState.Write (Ref dstAddress) value
7775
| _ when dstSafe.Value ->
7876
let ptr = Types.Cast (Ref srcAddress) (dstType.Value.MakePointerType())
7977
let value = cilState.Read ptr
80-
let cilStates = cilState.Write (Ref dstAddress) value
81-
assert(List.length cilStates = 1)
82-
List.head cilStates
78+
cilState.Write (Ref dstAddress) value
8379
| _ when srcSafe.Value ->
8480
let value = cilState.Read (Ref srcAddress)
8581
let ptr = Types.Cast (Ref dstAddress) (srcType.Value.MakePointerType())
86-
let cilStates = cilState.Write ptr value
87-
assert(List.length cilStates = 1)
88-
List.head cilStates
82+
cilState.Write ptr value
8983
| ArrayIndex(dstAddress, dstIndices, dstArrayType), ArrayIndex(srcAddress, srcIndices, srcArrayType) ->
9084
Copy dstAddress dstIndex dstIndices dstArrayType srcAddress srcIndex srcIndices srcArrayType state bytesCount
91-
cilState
9285
// TODO: implement unsafe copy
9386
| _ -> internalfail $"CommonMemmove unexpected addresses {srcAddress}, {dstAddress}"
94-
| None -> cilState
95-
getAddress cilState src |> List.map checkSrc
87+
| None -> ()
88+
let addressesWithStates = getAddress cilState src
89+
let mutable resultCilStates = List.empty
90+
for address, cilState in addressesWithStates do
91+
checkSrc address cilState
92+
resultCilStates <- cilState :: resultCilStates
93+
resultCilStates
9694
| None -> cilState |> List.singleton
9795
getAddress cilState dst |> List.collect checkDst
9896

VSharp.InternalCalls/IntPtr.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ module IntPtr =
1212
let ptr = MakeIntPtr term
1313
Memory.Write state this ptr
1414
Nop()
15-
1615

1716
let internal intPtrCtorFromInt (state : state) (args : term list) : term =
1817
assert(List.length args = 2)

VSharp.InternalCalls/Interlocked.fs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace VSharp.System
22

33
open global.System
4-
open VSharp
4+
55
open VSharp.Core
66
open VSharp.Interpreter.IL
77
open VSharp.Interpreter.IL.CilState
@@ -11,10 +11,9 @@ module internal Interlocked =
1111
let exchange (interpreter : IInterpreter) (cilState : cilState) location value =
1212
let exchange (cilState : cilState) k =
1313
let currentValue = cilState.Read location
14-
let cilStates = cilState.Write location value
15-
for cilState in cilStates do
16-
cilState.Push currentValue
17-
k cilStates
14+
cilState.Write location value
15+
cilState.Push currentValue
16+
List.singleton cilState |> k
1817
interpreter.NpeOrInvoke cilState location exchange id
1918

2019
let commonCompareExchange (interpreter : IInterpreter) (cilState : cilState) location value compared =
@@ -23,7 +22,7 @@ module internal Interlocked =
2322
let cilStates =
2423
cilState.StatedConditionalExecutionCIL
2524
(fun cilState k -> k (currentValue === compared, cilState))
26-
(fun cilState k -> k (cilState.Write location value))
25+
(fun cilState k -> k (cilState.Write location value; List.singleton cilState))
2726
(fun cilState k -> k (List.singleton cilState))
2827
id
2928
for cilState in cilStates do

VSharp.InternalCalls/Object.fs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,8 @@ module internal Object =
4141
else t
4242
let newObject = Memory.AllocateDefaultClass state t
4343
let fields = Reflection.fieldsOf false t
44-
let copyField cilStates (field, _) =
45-
let copyForState (cilState : cilState) =
46-
let v = cilState.ReadField object field
47-
cilState.WriteClassField newObject field v
48-
List.collect copyForState cilStates
49-
let cilStates = Array.fold copyField (List.singleton cilState) fields
50-
for cilState in cilStates do
51-
cilState.Push newObject
52-
cilStates
44+
for field, _ in fields do
45+
let v = cilState.ReadField object field
46+
cilState.WriteClassField newObject field v
47+
cilState.Push newObject
48+
List.singleton cilState

VSharp.InternalCalls/Span.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ module internal ReadOnlySpan =
137137
let span = cilState.Read this
138138
let initializedSpan = InitSpanStruct cilState span refToFirst length
139139
cilState.Write this initializedSpan
140+
List.singleton cilState
140141

141142
let CtorFromPtr (i : IInterpreter) (cilState : cilState) (args : term list) : cilState list =
142143
assert(List.length args = 4)
@@ -237,8 +238,7 @@ module internal ReadOnlySpan =
237238
let arrayRef = Memory.AllocateConcreteObject state rawData arrayType
238239
let refToFirstElement = Memory.ReferenceArrayIndex state arrayRef [MakeNumber 0] None
239240
let count = MakeNumber rawData.Length
240-
let cilStates = cilState.Write countRef count
241-
assert(List.length cilStates = 1 && cilStates[0] = cilState)
241+
cilState.Write countRef count
242242
cilState.Push refToFirstElement
243243
List.singleton cilState
244244
| _ -> internalfail $"GetSpanDataFrom: unexpected field handle {fieldHandleTerm} or type handle {typeHandleTerm}"

0 commit comments

Comments
 (0)