From 1aacb1fa6029b63f6675ac03fe3a3165698d106e Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 10 Jun 2025 16:26:08 +0200 Subject: [PATCH] Fixed regression compiler crash when using && for untyped parameters #2197. --- src/compiler/sema_expr.c | 2 +- .../macros/untyped_arg_inference.c3t | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/test_suite/macros/untyped_arg_inference.c3t diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index efe7b6a09..42d6e6fa4 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -11094,7 +11094,7 @@ RETRY: if (!sema_expr_analyse_ct_arg(context, to, expr)) return expr_poison(expr); break; case EXPR_UNARY: - if (expr->unary_expr.operator == UNARYOP_TADDR && to->canonical->type_kind == TYPE_POINTER && to->canonical != type_voidptr) + if (to && expr->unary_expr.operator == UNARYOP_TADDR && to->canonical->type_kind == TYPE_POINTER && to->canonical != type_voidptr) { if (!sema_analyse_inferred_expr(context, type_get_indexed_type(to), expr->unary_expr.expr)) return expr_poison(expr); } diff --git a/test/test_suite/macros/untyped_arg_inference.c3t b/test/test_suite/macros/untyped_arg_inference.c3t new file mode 100644 index 000000000..6376d7bc9 --- /dev/null +++ b/test/test_suite/macros/untyped_arg_inference.c3t @@ -0,0 +1,18 @@ +// #target: macos-x64 +module test; +macro foo(x) { return x; } +fn void main() +{ + int* x = foo(&&1); +} + +/* #expect: test.ll + +define void @test.main() #0 { +entry: + %x = alloca ptr, align 8 + %taddr = alloca i32, align 4 + store i32 1, ptr %taddr, align 4 + store ptr %taddr, ptr %x, align 8 + ret void +} \ No newline at end of file