summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-08-20 15:33:22 +0800
committerJohn Hodge <tpg@mutabah.net>2016-08-20 15:33:22 +0800
commit8df12b977534b11b4016b0fc4080141a4bea689e (patch)
tree2670e10bf1b687659abc36b90c802b4a188aaedd /src
parent2d10f135e8c6455feab799dedc38e2b3b70fe89c (diff)
downloadmrust-8df12b977534b11b4016b0fc4080141a4bea689e.tar.gz
MIR Gen - Fix codegen issue with use of moved LValue
Diffstat (limited to 'src')
-rw-r--r--src/mir/from_hir.cpp6
-rw-r--r--src/mir/mir.cpp35
2 files changed, 35 insertions, 6 deletions
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp
index f54ead5a..001fe62e 100644
--- a/src/mir/from_hir.cpp
+++ b/src/mir/from_hir.cpp
@@ -443,7 +443,6 @@ namespace {
ASSERT_BUG(sp, ty_slot.m_data.is_Primitive(), "Assignment operator overloads are only valid on primitives - ty_slot="<<ty_slot);
ASSERT_BUG(sp, ty_val.m_data.is_Primitive(), "Assignment operator overloads are only valid on primitives - ty_val="<<ty_val);
- ::MIR::RValue res;
#define _(v) ::HIR::ExprNode_Assign::Op::v
::MIR::eBinOp op;
switch(node.m_op)
@@ -470,8 +469,6 @@ namespace {
break;
}
#undef _
-
- m_builder.push_stmt_assign(mv$(dst), mv$(res));
}
else
{
@@ -1335,11 +1332,14 @@ void MirBuilder::set_result(const Span& sp, ::MIR::RValue val)
void MirBuilder::push_stmt_assign(::MIR::LValue dst, ::MIR::RValue val)
{
ASSERT_BUG(Span(), m_block_active, "Pushing statement with no active block");
+ ASSERT_BUG(Span(), dst.tag() != ::MIR::LValue::TAGDEAD, "");
+ ASSERT_BUG(Span(), val.tag() != ::MIR::RValue::TAGDEAD, "");
m_output.blocks.at(m_current_block).statements.push_back( ::MIR::Statement::make_Assign({ mv$(dst), mv$(val) }) );
}
void MirBuilder::push_stmt_drop(::MIR::LValue val)
{
ASSERT_BUG(Span(), m_block_active, "Pushing statement with no active block");
+ ASSERT_BUG(Span(), val.tag() != ::MIR::LValue::TAGDEAD, "");
m_output.blocks.at(m_current_block).statements.push_back( ::MIR::Statement::make_Drop({ ::MIR::eDropKind::DEEP, mv$(val) }) );
}
diff --git a/src/mir/mir.cpp b/src/mir/mir.cpp
index df6e1cde..7a201f46 100644
--- a/src/mir/mir.cpp
+++ b/src/mir/mir.cpp
@@ -38,6 +38,35 @@ namespace MIR {
::std::ostream& operator<<(::std::ostream& os, const LValue& x)
{
+ TU_MATCHA( (x), (e),
+ (Variable,
+ os << "Variable(" << e << ")";
+ ),
+ (Temporary,
+ os << "Temporary(" << e.idx << ")";
+ ),
+ (Argument,
+ os << "Argument(" << e.idx << ")";
+ ),
+ (Static,
+ os << "Static(" << e << ")";
+ ),
+ (Return,
+ os << "Return";
+ ),
+ (Field,
+ os << "Field(" << e.field_index << ", " << *e.val << ")";
+ ),
+ (Deref,
+ os << "Deref(" << *e.val << ")";
+ ),
+ (Index,
+ os << "Deref(" << *e.val << ", " << *e.idx << ")";
+ ),
+ (Downcast,
+ os << "Downcast(" << e.variant_index << ", " << *e.val << ")";
+ )
+ )
return os;
}
@@ -60,16 +89,16 @@ namespace MIR {
os << "Panic(" << e.dst << ";)";
),
(If,
- os << "If( ? : " << e.bb0 << ", " << e.bb1 << ")";
+ os << "If( " << e.cond << " : " << e.bb0 << ", " << e.bb1 << ")";
),
(Switch,
- os << "Switch( ? : ";
+ os << "Switch( " << e.val << " : ";
for(unsigned int j = 0; j < e.targets.size(); j ++)
os << j << " => bb" << e.targets[j] << ", ";
os << ")";
),
(Call,
- os << "Call( ? = ?( ";
+ os << "Call( " << e.ret_val << " = " << e.fcn_val << "( ";
for(const auto& arg : e.args)
os << arg << ", ";
os << "), bb" << e.ret_block << ", bb" << e.panic_block << ")";