From 343d70590763fb415495c2973f3cfd272e60a96a Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 7 Oct 2016 15:23:11 +0800 Subject: MIR Gen - Handle no-op casts --- src/mir/from_hir.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp index 8ff72d50..6d801007 100644 --- a/src/mir/from_hir.cpp +++ b/src/mir/from_hir.cpp @@ -767,14 +767,19 @@ namespace { { TRACE_FUNCTION_F("_Cast"); this->visit_node_ptr(node.m_value); - auto val = m_builder.get_result_in_lvalue(node.m_value->span(), node.m_value->m_res_type); const auto& ty_out = node.m_res_type; const auto& ty_in = node.m_value->m_res_type; + if( ty_out == ty_in ) { + return ; + } + + auto val = m_builder.get_result_in_lvalue(node.m_value->span(), node.m_value->m_res_type); + TU_MATCH_DEF( ::HIR::TypeRef::Data, (ty_out.m_data), (de), ( - BUG(node.span(), "Invalid cast to " << ty_out); + BUG(node.span(), "Invalid cast to " << ty_out << " from " << ty_in); ), (Pointer, if( ty_in.m_data.is_Primitive() ) { -- cgit v1.2.3