From 2b580da3472e3f7f1bc79b3b0766c00010307453 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Wed, 28 Sep 2016 21:05:46 +0800 Subject: Const Eval - Allow pointer casts --- src/hir_conv/constant_evaluation.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/hir_conv/constant_evaluation.cpp') diff --git a/src/hir_conv/constant_evaluation.cpp b/src/hir_conv/constant_evaluation.cpp index 286c124f..2d2736fe 100644 --- a/src/hir_conv/constant_evaluation.cpp +++ b/src/hir_conv/constant_evaluation.cpp @@ -771,6 +771,7 @@ namespace { uint64_t mask; switch(te) { + // Integers mask down case ::HIR::CoreType::I8: case ::HIR::CoreType::U8: mask = 0xFF; @@ -800,6 +801,15 @@ namespace { default: TODO(sp, "RValue::Cast to " << e.type << ", val = " << inval); } + ), + // Allow casting any integer value to a pointer (TODO: Ensure that the pointer is sized?) + (Pointer, + TU_IFLET( ::HIR::Literal, inval, Integer, i, + val = ::HIR::Literal(i); + ) + else { + BUG(sp, "Invalid cast of " << inval.tag_str() << " to " << e.type); + } ) ) ), -- cgit v1.2.3