summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-08-14 12:28:10 +0800
committerJohn Hodge <tpg@mutabah.net>2016-08-14 12:28:10 +0800
commitfe2e509e2b3da555a181105d3108c685e26a8057 (patch)
tree708871cb4587d72b34a3d51711d36ec4f1b2d75e
parentd68f877e12dafeb8caaaf4f165febacf550ad20e (diff)
downloadmrust-fe2e509e2b3da555a181105d3108c685e26a8057.tar.gz
MIR Gen - Defensive checks on _Index
-rw-r--r--src/mir/from_hir.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp
index 88fb28f5..e8e72b9c 100644
--- a/src/mir/from_hir.cpp
+++ b/src/mir/from_hir.cpp
@@ -707,16 +707,18 @@ namespace {
TRACE_FUNCTION_F("_Index");
// NOTE: Calculate the index first (so if it borrows from the source, it's over by the time that's needed)
+ const auto& ty_idx = node.m_index->m_res_type;
this->visit_node_ptr(node.m_index);
- auto index = m_builder.lvalue_or_temp( node.m_index->m_res_type, m_builder.get_result(node.m_index->span()) );
+ auto index = m_builder.lvalue_or_temp( ty_idx, m_builder.get_result(node.m_index->span()) );
+ const auto& ty_val = node.m_value->m_res_type;
this->visit_node_ptr(node.m_value);
- auto value = m_builder.lvalue_or_temp( node.m_value->m_res_type, m_builder.get_result(node.m_value->span()) );
+ auto value = m_builder.lvalue_or_temp( ty_val, m_builder.get_result(node.m_value->span()) );
::MIR::RValue limit_val;
- TU_MATCH_DEF(::HIR::TypeRef::Data, (node.m_value->m_res_type.m_data), (e),
+ TU_MATCH_DEF(::HIR::TypeRef::Data, (ty_val.m_data), (e),
(
- BUG(node.span(), "Indexing unsupported type " << node.m_value->m_res_type);
+ BUG(node.span(), "Indexing unsupported type " << ty_val);
),
(Array,
limit_val = ::MIR::Constant( e.size_val );
@@ -726,6 +728,17 @@ namespace {
)
)
+ TU_MATCH_DEF(::HIR::TypeRef::Data, (ty_idx.m_data), (e),
+ (
+ BUG(node.span(), "Indexing using unsupported index type " << ty_idx);
+ ),
+ (Primitive,
+ if( e != ::HIR::CoreType::Usize ) {
+ BUG(node.span(), "Indexing using unsupported index type " << ty_idx);
+ }
+ )
+ )
+
// Range checking (DISABLED)
if( false )
{