From ac479c7e405a4d8e085242463444da3e0e172a77 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Fri, 20 Sep 2024 20:15:44 +0200 Subject: [PATCH] llvm issue with try when bool is combined #1467 --- releasenotes.md | 1 + src/compiler/llvm_codegen_expr.c | 1 + test/unit/regression/unwrapping.c3 | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 test/unit/regression/unwrapping.c3 diff --git a/releasenotes.md b/releasenotes.md index d4c6ad244..ea2669429 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -45,6 +45,7 @@ - User defined attributes could not have more than 1 parameter due to bug. - Folding a constant array of structs at compile time would cause an assert. - Enum attributes would be overwritten by enum value attributes. +- LLVM issue with try when bool is combined #1467 ### Stdlib changes - Additional init functions for hashmap. diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c index 51410d248..d590fbffa 100644 --- a/src/compiler/llvm_codegen_expr.c +++ b/src/compiler/llvm_codegen_expr.c @@ -6908,6 +6908,7 @@ void llvm_emit_try_unwrap_chain(GenContext *c, BEValue *value, Expr *expr) Expr *link = exprs[i]; BEValue res; llvm_emit_expr(c, &res, link); + llvm_value_rvalue(c, &res); assert(llvm_value_is_bool(&res)); llvm_emit_cond_br(c, &res, next_block, fail_block); } diff --git a/test/unit/regression/unwrapping.c3 b/test/unit/regression/unwrapping.c3 new file mode 100644 index 000000000..cb2be9f40 --- /dev/null +++ b/test/unit/regression/unwrapping.c3 @@ -0,0 +1,19 @@ +module unwrapping; + +fn bool! get_bool() +{ + return true; +} + +fn void! bool_chain_unwrap() @test +{ + bool b; + if (try v = get_bool() && b) + { + assert(v == true); + } + if (try v = get_bool() && v) + { + assert(v == true); + } +} \ No newline at end of file