| ... | @@ -3522,6 +3522,15 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir | ... | @@ -3522,6 +3522,15 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir |
| 3522 | assert(ptr_type->id == ZigTypeIdPointer); | 3522 | assert(ptr_type->id == ZigTypeIdPointer); |
| 3523 | if (!type_has_bits(ptr_type)) | 3523 | if (!type_has_bits(ptr_type)) |
| 3524 | return nullptr; | 3524 | return nullptr; |
| | 3525 | if (instruction->ptr->ref_count == 0) { |
| | 3526 | // In this case, this StorePtr instruction should be elided. Something happened like this: |
| | 3527 | // var t = true; |
| | 3528 | // const x = if (t) Num.Two else unreachable; |
| | 3529 | // The if condition is a runtime value, so the StorePtr for `x = Num.Two` got generated |
| | 3530 | // (this instruction being rendered) but because of `else unreachable` the result ended |
| | 3531 | // up being a comptime const value. |
| | 3532 | return nullptr; |
| | 3533 | } |
| 3525 | | 3534 | |
| 3526 | bool have_init_expr = !value_is_all_undef(&instruction->value->value); | 3535 | bool have_init_expr = !value_is_all_undef(&instruction->value->value); |
| 3527 | if (have_init_expr) { | 3536 | if (have_init_expr) { |