diff options
| author | dimenus <ryan.saunderson88@gmail.com> | 2017-11-10 09:49:45 -0600 |
|---|---|---|
| committer | dimenus <ryan.saunderson88@gmail.com> | 2017-11-10 09:49:45 -0600 |
| commit | e9d7623e1f0300b1b652373f2e0e7b605eaf13d1 (patch) | |
| tree | 65470f2c68466ddc9f1663dc1b91f89324ebb2bd /src/codegen.cpp | |
| parent | 3a600297ca3f99ee57630c44900eec1fe7c92804 (diff) | |
| parent | 336d81894da2c34a77cffd1bf903ad9e4dcaa7aa (diff) | |
| download | zig-e9d7623e1f0300b1b652373f2e0e7b605eaf13d1.tar.gz zig-e9d7623e1f0300b1b652373f2e0e7b605eaf13d1.zip | |
Merge remote-tracking branch 'origin/master' into llvm6
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[] = { |
