From 4f8c26d2c605f24cdeb1a4c7154662b2552640ef Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 8 Nov 2017 21:44:10 -0500 Subject: fix enum sizes too large closes #598 --- src/codegen.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/codegen.cpp') diff --git a/src/codegen.cpp b/src/codegen.cpp index 976b20405e..38a1a2cbea 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -2666,9 +2666,16 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable if (ir_want_debug_safety(g, &instruction->base)) { TypeTableEntry *enum_type = enum_tag_type->data.enum_tag.enum_type; size_t field_count = enum_type->data.enumeration.src_field_count; - LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(enum_tag_value)); - LLVMValueRef end_val = LLVMConstInt(LLVMTypeOf(enum_tag_value), field_count, false); - add_bounds_check(g, enum_tag_value, LLVMIntUGE, zero, LLVMIntULT, end_val); + + // if the field_count can't fit in the bits of the enum_tag_type, then it can't possibly + // be the wrong value + BigInt field_bi; + bigint_init_unsigned(&field_bi, field_count); + TypeTableEntry *tag_int_type = enum_tag_type->data.enum_tag.int_type; + if (bigint_fits_in_bits(&field_bi, tag_int_type->data.integral.bit_count, false)) { + LLVMValueRef end_val = LLVMConstInt(LLVMTypeOf(enum_tag_value), field_count, false); + add_bounds_check(g, enum_tag_value, LLVMIntEQ, nullptr, LLVMIntULT, end_val); + } } LLVMValueRef indices[] = { -- cgit v1.2.3