From 44d8d654a0ba463a1d4cf34d435c8422bfcd1c81 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 5 Feb 2018 09:26:39 -0500 Subject: fix test failure, organize code, add new compile error --- src/ir.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index 9d5f59d187..1dc717286a 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -6193,6 +6193,15 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc if (other_type->id == TypeTableEntryIdFloat) { return true; } else if (other_type->id == TypeTableEntryIdInt && const_val_is_int) { + if (!other_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) { + Buf *val_buf = buf_alloc(); + bigint_append_buf(val_buf, &const_val->data.x_bigint, 10); + ir_add_error(ira, instruction, + buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'", + buf_ptr(val_buf), + buf_ptr(&other_type->name))); + return false; + } if (bigint_fits_in_bits(&const_val->data.x_bigint, other_type->data.integral.bit_count, other_type->data.integral.is_signed)) { @@ -6205,6 +6214,15 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc if (const_val_fits_in_num_lit(const_val, child_type)) { return true; } else if (child_type->id == TypeTableEntryIdInt && const_val_is_int) { + if (!child_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) { + Buf *val_buf = buf_alloc(); + bigint_append_buf(val_buf, &const_val->data.x_bigint, 10); + ir_add_error(ira, instruction, + buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'", + buf_ptr(val_buf), + buf_ptr(&child_type->name))); + return false; + } if (bigint_fits_in_bits(&const_val->data.x_bigint, child_type->data.integral.bit_count, child_type->data.integral.is_signed)) -- cgit v1.2.3