diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-11-08 21:44:10 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-11-08 21:44:10 -0500 |
| commit | 4f8c26d2c605f24cdeb1a4c7154662b2552640ef (patch) | |
| tree | 926037a3a45f58d191a589d4ed137f4c1bb81bdf /src/codegen.cpp | |
| parent | 53b18c8542d6d40c3aa41e9d97290a4ca46eaa15 (diff) | |
| download | zig-4f8c26d2c605f24cdeb1a4c7154662b2552640ef.tar.gz zig-4f8c26d2c605f24cdeb1a4c7154662b2552640ef.zip | |
fix enum sizes too large
closes #598
Diffstat (limited to 'src/codegen.cpp')
| -rw-r--r-- | src/codegen.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
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[] = { |
