Commit 9fae8f2b authored by Henrich Lauko's avatar Henrich Lauko

lart: Test taints before calling freeze or thaw.

parent d37d9ed1
......@@ -39,40 +39,10 @@ namespace lart::abstract
}
if ( auto store = llvm::dyn_cast< llvm::StoreInst >( inst ) ) {
/*if ( meta.scalar() ) {
return construct< Type::Freeze >( store );
}
if ( meta.pointer() ) {
}
if ( meta.content() ) {
if ( is_base_type_in_domain( m, store->getValueOperand(), dom ) )
return construct< Type::Freeze >( store );
else
return construct< Type::Store >( store );
}*/
UNREACHABLE( "not implemented" );
}
if ( auto load = llvm::dyn_cast< llvm::LoadInst >( inst ) ) {
/*if ( meta.scalar() ) {
if ( is_base_type_in_domain( m, inst, dom ) ) {
return construct< Type::Thaw >( load );
}
}
if ( meta.pointer() ) {
}
if ( meta.content() ) {
if ( is_base_type_in_domain( m, load, dom ) )
return construct< Type::Thaw >( load );
else
return construct< Type::Load >( load );
}*/
UNREACHABLE( "not implemented" );
}
......@@ -125,15 +95,6 @@ namespace lart::abstract
abstract[ c ] = a;
concrete[ a ] = c;
}
auto tag = meta::tag::operation::thaw;
for ( auto load : meta::enumerate< llvm::LoadInst >( m, tag ) ) {
auto c = load;
auto a = load->getNextNode()->getNextNode();
ASSERT( llvm::isa< llvm::CallInst >( a ) ); // is thaw
abstract[ c ] = a;
concrete[ a ] = c;
}
}
void Matched::match( Operation::Type type, llvm::Value * a, llvm::Value * c )
......
......@@ -15,57 +15,31 @@ DIVINE_UNRELAX_WARNINGS
namespace lart::abstract
{
struct ThawPass {
struct ThawPass
{
void run( llvm::Module &m )
{
thawFn = llvm::cast< llvm::Function >( m.getFunction( "__lart_thaw" ) );
ASSERT( thawFn, "Missing implementation of 'thaw' function." );
OperationBuilder builder;
const auto tag = meta::tag::operation::thaw;
for ( auto l : meta::enumerate< llvm::LoadInst >( m, tag ) )
thaw( l );
constexpr auto Thaw = Operation::Type::Thaw;
for ( auto load : meta::enumerate< llvm::LoadInst >( m, tag ) )
builder.construct< Thaw >( load );
}
void thaw( llvm::LoadInst *load ) const noexcept
{
llvm::IRBuilder<> irb( load->getNextNode() );
auto fty = thawFn->getFunctionType();
auto addr = irb.CreateBitCast( load->getPointerOperand(), fty->getParamType( 0 ) );
irb.CreateCall( thawFn, { addr } );
}
llvm::Function * thawFn = nullptr;
};
struct FreezePass {
struct FreezePass
{
void run( llvm::Module &m )
{
freezeFn = llvm::cast< llvm::Function >( m.getFunction( "__lart_freeze" ) );
ASSERT( freezeFn, "Missing implementation of 'freeze' function." );
_matched.init( m );
OperationBuilder builder;
const auto tag = meta::tag::operation::freeze;
for ( auto s : meta::enumerate< llvm::StoreInst >( m, tag ) )
freeze( s );
constexpr auto Freeze = Operation::Type::Freeze;
for ( auto store : meta::enumerate< llvm::StoreInst >( m, tag ) )
builder.construct< Freeze >( store );
}
void freeze( llvm::StoreInst *store ) const noexcept
{
auto abs = _matched.abstract.at( store->getValueOperand() );
auto fty = freezeFn->getFunctionType();
llvm::IRBuilder<> irb( store->getNextNode() );
auto addr = irb.CreateBitCast( store->getPointerOperand(), fty->getParamType( 1 ) );
irb.CreateCall( freezeFn, { abs, addr } );
}
Matched _matched;
llvm::Function * freezeFn = nullptr;
};
......
......@@ -105,6 +105,30 @@ namespace lart::abstract
return get_function_from_domain( irb, index, _domain );
}
template< typename IRB >
auto thaw( IRB & irb, llvm::Value * value ) const
{
auto thawFn = llvm::cast< llvm::Function >( module->getFunction( "__lart_thaw" ) );
ASSERT( thawFn, "Missing implementation of 'thaw' function." );
auto fty = thawFn->getFunctionType();
auto addr = irb.CreateBitCast( value, fty->getParamType( 0 ) );
return irb.CreateCall( thawFn, { addr } );
}
template< typename IRB >
auto freeze( IRB & irb, llvm::Value * value, llvm::Value * addr ) const
{
auto freezeFn = llvm::cast< llvm::Function >( module->getFunction( "__lart_freeze" ) );
ASSERT( freezeFn, "Missing implementation of 'freeze' function." );
auto fty = freezeFn->getFunctionType();
auto v = irb.CreateBitCast( value, fty->getParamType( 0 ) );
auto a = irb.CreateBitCast( addr, fty->getParamType( 1 ) );
return irb.CreateCall( freezeFn, { v, a } );
}
void construct()
{
......@@ -242,6 +266,22 @@ namespace lart::abstract
UNREACHABLE( "not implemented" );
}
if constexpr ( Taint::freeze( T ) )
{
auto val = args[ 1 ].value;
auto addr = args[ 2 ].value;
freeze( irb, val, addr );
irb.CreateRet( undef( function()->getReturnType() ) );
return;
}
if constexpr ( Taint::thaw( T ) )
{
auto t = thaw( irb, args[ 1 ].value );
irb.CreateRet( t );
return;
}
if constexpr ( Taint::cast( T ) )
{
auto paired = paired_arguments().front();
......@@ -394,6 +434,8 @@ namespace lart::abstract
DISPATCH( Assume )
DISPATCH( Store )
DISPATCH( Load )
DISPATCH( Freeze )
DISPATCH( Thaw )
DISPATCH( Cmp )
DISPATCH( Cast )
DISPATCH( Binary )
......
......@@ -46,9 +46,10 @@ namespace lart::abstract {
template< Type T_ = T >
static auto suffix( llvm::Value * val ) noexcept
-> typename std::enable_if_t< Taint::thaw( T_ ), std::string >
-> typename std::enable_if_t< Taint::freeze( T_ ), std::string >
{
return result() + "." + llvm_name( val->getType()->getPointerElementType() );
auto store = llvm::cast< llvm::StoreInst >( val );
return result() + "." + llvm_name( store->getValueOperand()->getType() );
}
template< Type T_ = T >
......@@ -79,9 +80,9 @@ namespace lart::abstract {
-> typename std::enable_if_t<
Taint::toBool( T_ ) ||
Taint::assume( T_ ) ||
Taint::thaw( T_ ) ||
Taint::store( T_ ) ||
Taint::load( T_ ) ||
Taint::freeze( T_ ) ||
Taint::gep( T_ )
,std::string >
{
......@@ -452,13 +453,16 @@ namespace lart::abstract {
return null();
}
auto return_type( llvm::Instruction * inst ) const
auto return_type( llvm::Instruction * inst ) const -> llvm::Type *
{
if constexpr ( Operation::freeze( T ) || Operation::store( T ) || Operation::mem( T ) )
{
if constexpr ( Operation::mem( T ) ) {
UNREACHABLE( " not implemented" );
}
if constexpr ( Operation::freeze( T ) || Operation::store( T ) ) {
return i8PTy();
}
return inst->getType();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment