diff --git a/releasenotes.md b/releasenotes.md index b3cfccbcb..ea0cc7811 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -10,6 +10,7 @@ - List.remove_at would incorrectly trigger ASAN. - With avx512, passing a 512 bit vector in a union would be lowered incorrectly, causing an assert. #2362 - Codegen error in `if (try x = (true ? io::EOF? : 1))`, i.e. using if-try with a known Empty. +- Codegen error in `if (try x = (false ? io::EOF? : 1))`, i.e. using if-try with a CT known value. ### Stdlib changes - Add `==` to `Pair`, `Triple` and TzDateTime. Add print to `Pair` and `Triple`. diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c index 7bffbaecf..2d98c8bce 100644 --- a/src/compiler/llvm_codegen_expr.c +++ b/src/compiler/llvm_codegen_expr.c @@ -4284,9 +4284,16 @@ void llvm_emit_try_assign_try_catch(GenContext *c, bool is_try, BEValue *be_valu return; } + if (llvm_basic_block_is_unused(catch_block)) + { + llvm_value_set(be_value, LLVMConstInt(c->bool_type, is_try ? 1 : 0, false), type_bool); + return; + } + // 10. Jump to the phi llvm_emit_br(c, phi_catch); + // 11. Emit the catch and jump. llvm_emit_block(c, catch_block); llvm_emit_br(c, phi_catch); diff --git a/test/test_suite/errors/try_known_optional.c3t b/test/test_suite/errors/try_known_optional2.c3t similarity index 57% rename from test/test_suite/errors/try_known_optional.c3t rename to test/test_suite/errors/try_known_optional2.c3t index b2557a097..8797f2041 100644 --- a/test/test_suite/errors/try_known_optional.c3t +++ b/test/test_suite/errors/try_known_optional2.c3t @@ -3,18 +3,17 @@ module test; import std; fn int main() { - if (try x = (true ? io::EOF? : 3)) + if (try x = (false ? io::EOF? : 3)) {} return 0; } /* #expect: test.ll +define i32 @main() #0 { entry: %x = alloca i32, align 4 store i32 0, ptr %x, align 4 - br label %catch_landing - -catch_landing: ; preds = %entry + store i32 3, ptr %x, align 4 ret i32 0 -} +} \ No newline at end of file