1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
-
-
-
+
-
+
-
-
-
-
-
+
-
+
|
#include "verify.h"
#include "builtins/builtins.h"
#include "helpers.inl"
using namespace goose::diagnostics;
namespace goose::verify
{
Z3Val BuildZ3ValFromConstant( Builder& b, const Value& val )
{
optional< TypeInfo > tinfo;
auto loweredVal = LowerConstantForVerification( b.context(), val );
if( loweredVal && !loweredVal->isPoison() )
tinfo = TypeCache::GetInstance().getTypeInfo( b.context(), loweredVal->type() );
tinfo = TypeCache::GetInstance().getTypeInfo( b.context(), val.type() );
if( !tinfo )
tinfo = TypeCache::GetInstance().uninterpretedTypeInfo();
auto zexpr = tinfo->build( b, *loweredVal );
auto zexpr = tinfo->build( b, val );
return Z3Val { move( zexpr ), *EIRToValue( val.type() ), val.locationId() };
}
optional< Z3Val > TryBuildZ3ValFromConstant( Builder& b, const Value& val )
{
auto loweredVal = LowerConstantForVerification( b.context(), val );
if( !loweredVal || loweredVal->isPoison() )
return nullopt;
auto tinfo = TypeCache::GetInstance().getTypeInfo( b.context(), loweredVal->type() );
auto tinfo = TypeCache::GetInstance().getTypeInfo( b.context(), val.type() );
if( !tinfo )
return nullopt;
auto zexpr = tinfo->build( b, *loweredVal );
auto zexpr = tinfo->build( b, val );
return Z3Val { move( zexpr ), *EIRToValue( val.type() ), val.locationId() };
}
Z3Val BuildZ3ConstantFromType( Builder& b, const Value& type, const string& name )
{
auto tinfo = TypeCache::GetInstance().getTypeInfo( b.context(), ValueToEIR( type ) );
if( !tinfo )
|
| ︙ | | |
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
+
|
{
assert( rhs->expr.is_int() );
b.push( Z3Val{ func( lhs->expr, GetAsBitVec( *rhs ), lhs->type ), *EIRToValue( GetValueType< bool >() ), instr.locationId() } );
return true;
}
else
{
cout << lhs->expr << endl;
assert( lhs->expr.is_int() );
b.push( Z3Val{ func( GetAsBitVec( *lhs ), rhs->expr, lhs->type ), *EIRToValue( GetValueType< bool >() ), instr.locationId() } );
return true;
}
return false;
}
|
| ︙ | | |
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
|
-
+
-
+
-
+
-
+
|
}
bool BuildZ3Op( Builder& b, const Load& instr )
{
optional< Z3Val > zv;
if( auto cstAddr = b.pop< Address >() )
zv = LoadFromAddress( b, *cstAddr, instr.type() );
zv = LoadFromAddress( b, *cstAddr, instr.type().get() );
else if( auto gfa = b.pop< GhostFuncApplication >() )
zv = LoadFromAddress( b, *gfa );
else if( auto symAddr = b.pop< Z3Val >() )
zv = BuildZ3ConstantFromType( b, instr.type(), format( "val{}", b.newUniqueId() ) );
zv = BuildZ3ConstantFromType( b, instr.type().get(), format( "val{}", b.newUniqueId() ) );
if( !zv )
return false;
if( b.mustLoadAssume() )
ForEachPredicate( b, instr.type(), zv->expr, [&]( auto&& z3expr, auto locId )
ForEachPredicate( b, instr.type().get(), zv->expr, [&]( auto&& z3expr, auto locId )
{
b.assume( z3expr );
} );
zv->loc = instr.locationId();
b.push( move( *zv ) );
return true;
}
bool BuildZ3Op( Builder& b, const Store& instr )
{
auto addr = b.pop< Stack::Slot >();
if( !addr )
return false;
auto zv = b.pop();
if( !zv )
return false;
ForEachPredicate( b, instr.type(), zv->expr, [&]( auto&& z3expr, auto locId )
ForEachPredicate( b, instr.type().get(), zv->expr, [&]( auto&& z3expr, auto locId )
{
if( !instr.srcLocId().invalid() && !instr.destLocId().invalid() )
{
DiagnosticsContext dc( instr.destLocId(), "...to this." );
DiagnosticsContext dc2( instr.srcLocId(), "When assigning this..." );
b.checkAssertion( z3expr, locId );
}
|
| ︙ | | |
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
|
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
|
-
+
-
+
|
b.push( move( *zv ) );
return true;
}
bool BuildZ3Op( Builder& b, const AllocVar& instr )
{
auto tinfo = TypeCache::GetInstance().getTypeInfo( b.context(), ValueToEIR( instr.type() ) );
auto tinfo = TypeCache::GetInstance().getTypeInfo( b.context(), instr.type().get() );
if( !tinfo )
tinfo = TypeCache::GetInstance().uninterpretedTypeInfo();
b.setVar( instr.index(), Z3Val{ tinfo->undefined( b ), instr.type(), instr.locationId() } );
b.setVar( instr.index(), Z3Val{ tinfo->undefined( b ), *EIRToValue( instr.type().get() ), instr.locationId() } );
return true;
}
// Implemented in phi.cpp
bool BuildZ3Op( Builder& b, const Phi& instr );
bool BuildZ3Op( Builder& b, const Not& instr )
|
| ︙ | | |
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
|
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
|
-
+
-
+
|
}
bool BuildZ3Op( Builder& b, const Placeholder& instr )
{
const auto* expr = b.retrievePlaceholder( instr.name() );
if( expr )
{
b.push( Z3Val{ *expr, *EIRToValue( instr.type() ), instr.locationId() } );
b.push( Z3Val{ *expr, *EIRToValue( instr.type().get() ), instr.locationId() } );
return true;
}
auto result = BuildZ3ConstantFromType( b, instr.type(), format( "p{}", instr.name().str() ) );
auto result = BuildZ3ConstantFromType( b, instr.type().get(), format( "p{}", instr.name().str() ) );
b.push( move( result ) );
return true;
}
bool BuildZ3Op( Builder& b, const PHOverrideSet& instr )
{
auto phExpr = b.pop();
|
| ︙ | | |
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
|
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
|
-
+
-
+
|
{
b.unsetPlaceholder( instr.name() );
return true;
}
bool BuildZ3Op( Builder& b, const PushConstant& instr )
{
auto v = TryBuildZ3ExprFromValue( b, instr.value() );
auto v = TryBuildZ3ExprFromValue( b, instr.value().get() );
if( v )
b.push( move( *v ) );
else
b.push( instr.value() );
b.push( instr.value().get() );
return true;
}
bool BuildZ3Op( Builder& b, const VarAddr& instr )
{
b.push( Address( {}, Address::Origin::Stack, instr.varIndex(), instr.locationId() ) );
return true;
|
| ︙ | | |