summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2019-08-07 18:48:04 +0800
committerJohn Hodge <tpg@ucc.asn.au>2019-08-07 18:48:04 +0800
commit7980ff17aa557d5546d920271f47c68ab498714b (patch)
treef0b1d12ebb079f983401026a0dd70d9f798a6249
parent4488ad815467790f63a6eed6a127d0e658cbd631 (diff)
downloadmrust-7980ff17aa557d5546d920271f47c68ab498714b.tar.gz
Standalone MIRI - Rough panic support
-rw-r--r--src/trans/codegen_mmir.cpp12
-rw-r--r--tools/standalone_miri/miri.cpp42
-rw-r--r--tools/standalone_miri/miri.hpp4
3 files changed, 45 insertions, 13 deletions
diff --git a/src/trans/codegen_mmir.cpp b/src/trans/codegen_mmir.cpp
index 2f6a2f2e..5ed12418 100644
--- a/src/trans/codegen_mmir.cpp
+++ b/src/trans/codegen_mmir.cpp
@@ -1103,11 +1103,6 @@ namespace
::MIR::TypeResolve mir_res { sp, m_resolve, FMT_CB(ss, ss << p;), ret_type, arg_types, *code };
m_mir_res = &mir_res;
- if( item.m_linkage.name != "" )
- {
- // TODO: Save the linkage name.
- }
-
// - Signature
m_of << "fn " << p << "(";
for(unsigned int i = 0; i < item.m_args.size(); i ++)
@@ -1115,7 +1110,12 @@ namespace
if( i != 0 ) m_of << ", ";
m_of << params.monomorph(m_resolve, item.m_args[i].second);
}
- m_of << "): " << ret_type << " {\n";
+ m_of << "): " << ret_type;
+ if( item.m_linkage.name != "" )
+ {
+ m_of << " = \"" << item.m_linkage.name << "\":\"" << item.m_abi << "\"";
+ }
+ m_of << " {\n";
// - Locals
for(unsigned int i = 0; i < code->locals.size(); i ++) {
DEBUG("var" << i << " : " << code->locals[i]);
diff --git a/tools/standalone_miri/miri.cpp b/tools/standalone_miri/miri.cpp
index 6c611382..957a69f1 100644
--- a/tools/standalone_miri/miri.cpp
+++ b/tools/standalone_miri/miri.cpp
@@ -1533,7 +1533,9 @@ bool InterpreterThread::step_one(Value& out_thread_result)
TU_ARM(bb.terminator, Incomplete, _te)
LOG_TODO("Terminator::Incomplete hit");
TU_ARM(bb.terminator, Diverge, _te)
- LOG_TODO("Terminator::Diverge hit");
+ LOG_DEBUG("DIVERGE (continue panic)");
+ assert(m_thread.panic_active);
+ return this->pop_stack(out_thread_result);
TU_ARM(bb.terminator, Panic, _te)
LOG_TODO("Terminator::Panic");
TU_ARM(bb.terminator, Goto, te)
@@ -1700,9 +1702,19 @@ bool InterpreterThread::step_one(Value& out_thread_result)
return false;
}
}
- LOG_DEBUG(te.ret_val << " = " << rv << " (resume " << cur_frame.fcn->my_path << ")");
- state.write_lvalue(te.ret_val, rv);
- cur_frame.bb_idx = te.ret_block;
+ // If a panic is in progress (in thread state), take the panic block instead
+ if( m_thread.panic_active )
+ {
+ //m_thread.panic_active = false;
+ LOG_DEBUG("Panic into " << cur_frame.fcn->my_path);
+ cur_frame.bb_idx = te.panic_block;
+ }
+ else
+ {
+ LOG_DEBUG(te.ret_val << " = " << rv << " (resume " << cur_frame.fcn->my_path << ")");
+ state.write_lvalue(te.ret_val, rv);
+ cur_frame.bb_idx = te.ret_block;
+ }
} break;
}
cur_frame.stmt_idx = 0;
@@ -1754,9 +1766,19 @@ bool InterpreterThread::pop_stack(Value& out_thread_result)
LOG_DEBUG(te.ret_val << " = " << res_v << " (resume " << cur_frame.fcn->my_path << ")");
- state.write_lvalue(te.ret_val, res_v);
cur_frame.stmt_idx = 0;
- cur_frame.bb_idx = te.ret_block;
+ // If a panic is in progress (in thread state), take the panic block instead
+ if( m_thread.panic_active )
+ {
+ //m_thread.panic_active = false;
+ LOG_DEBUG("Panic into " << cur_frame.fcn->my_path);
+ cur_frame.bb_idx = te.panic_block;
+ }
+ else
+ {
+ state.write_lvalue(te.ret_val, res_v);
+ cur_frame.bb_idx = te.ret_block;
+ }
}
return false;
@@ -1969,8 +1991,10 @@ bool InterpreterThread::call_extern(Value& rv, const ::std::string& link_name, c
// GCC unwinding panics
else if( link_name == "_Unwind_RaiseException" )
{
- LOG_TODO("_Unwind_RaiseException(" << args.at(0) << ")");
+ LOG_DEBUG("_Unwind_RaiseException(" << args.at(0) << ")");
// Save the first argument in TLS, then return a status that indicates unwinding should commence.
+ m_thread.panic_active = true;
+ m_thread.panic_value = ::std::move(args.at(0));
}
#ifdef _WIN32
// WinAPI functions used by libstd
@@ -2783,6 +2807,10 @@ bool InterpreterThread::call_intrinsic(Value& rv, const RcString& name, const ::
sub_args.push_back( ::std::move(arg) );
this->m_stack.push_back(StackFrame::make_wrapper([=](Value& out_rv, Value /*rv*/)->bool{
+ if( m_thread.panic_active )
+ {
+ LOG_TODO("Panic caught in `try` - " << m_thread.panic_value);
+ }
out_rv = Value::new_u32(0);
return true;
}));
diff --git a/tools/standalone_miri/miri.hpp b/tools/standalone_miri/miri.hpp
index e6830679..9c3da72b 100644
--- a/tools/standalone_miri/miri.hpp
+++ b/tools/standalone_miri/miri.hpp
@@ -15,8 +15,12 @@ struct ThreadState
unsigned call_stack_depth;
::std::vector< ::std::pair<uint64_t, RelocationPtr> > tls_values;
+ bool panic_active;
+ Value panic_value;
+
ThreadState():
call_stack_depth(0)
+ ,panic_active(false)
{
}