diff --git a/releasenotes.md b/releasenotes.md index 1f140fdfb..52c2fabf1 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -4,7 +4,8 @@ ### Fixes - Assert triggered when casting from `int[2]` to `uint[2]` #2115 - +- Assert when a macro with compile time value is discarded, e.g. `foo();` where `foo()` returns an untyped list. #2117 + ### Stdlib changes - Added `String.quick_ztr` and `String.is_zstr` - std::ascii moved into std::core::ascii. Old _m variants are deprecated, as is uint methods. diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c index 9a688cac8..a6c7733f8 100644 --- a/src/compiler/llvm_codegen_expr.c +++ b/src/compiler/llvm_codegen_expr.c @@ -4757,7 +4757,9 @@ static void llvm_emit_const_expr(GenContext *c, BEValue *be_value, Expr *expr) return; case CONST_MEMBER: case CONST_UNTYPED_LIST: - UNREACHABLE + // This is valid in the case that this will be discarded anyway. + llvm_value_set(be_value, NULL, type_void); + return; } UNREACHABLE } diff --git a/test/test_suite/macros/macro_untyped_output.c3t b/test/test_suite/macros/macro_untyped_output.c3t new file mode 100644 index 000000000..6384d8661 --- /dev/null +++ b/test/test_suite/macros/macro_untyped_output.c3t @@ -0,0 +1,25 @@ +// #target: macos-x64 +module test; +fn int main() +{ + foo(); + bar(0); + int x; + bar(x++); + return 0; +} + +macro foo() => {}; +macro bar(x) => {}; + +/* #expect: test.ll + +define i32 @main() #0 { +entry: + %x = alloca i32, align 4 + store i32 0, ptr %x, align 4 + %0 = load i32, ptr %x, align 4 + %add = add i32 %0, 1 + store i32 %add, ptr %x, align 4 + ret i32 0 +}