From 7fe49fbffbcb30f242de2f8eed6dff48d92aa7c5 Mon Sep 17 00:00:00 2001 From: kalsprite Date: Fri, 21 Aug 2026 16:38:56 -0700 Subject: [PATCH] Fix compiler panic on a selector into --- src/llvm_backend_expr.cpp | 5 +++++ tests/internal/test_branch_location.odin | 26 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/internal/test_branch_location.odin diff --git a/src/llvm_backend_expr.cpp b/src/llvm_backend_expr.cpp index f12965197..74cb46ceb 100644 --- a/src/llvm_backend_expr.cpp +++ b/src/llvm_backend_expr.cpp @@ -6546,6 +6546,11 @@ gb_internal lbAddr lb_build_addr_internal(lbProcedure *p, Ast *expr) { return lb_build_addr_from_entity(p, e, expr); case_end; + case_ast_node(bd, BasicDirective, expr); + lbValue ptr = lb_address_from_load_or_generate_local(p, lb_build_expr(p, expr)); + return lb_addr(ptr); + case_end; + case_ast_node(se, SelectorExpr, expr); Ast *sel_node = unparen_expr(se->selector); if (sel_node->kind == Ast_Ident) { diff --git a/tests/internal/test_branch_location.odin b/tests/internal/test_branch_location.odin new file mode 100644 index 000000000..999657943 --- /dev/null +++ b/tests/internal/test_branch_location.odin @@ -0,0 +1,26 @@ +package test_internal + +import "core:testing" + +@(private="file") +returns_at :: proc(early: bool, got: ^i32) -> (expected: i32) { + defer got^ = #branch_location.line + + if early { + return #line + } + + return #line +} + +// A selector on `#branch_location` reached `lb_build_addr`, which had no case for a directive +@(test) +branch_location_field_access :: proc(t: ^testing.T) { + got: i32 + + expected := returns_at(true, &got) + testing.expect_value(t, got, expected) + + expected = returns_at(false, &got) + testing.expect_value(t, got, expected) +}