From c3b2c9a9b388c355eaa9faa5dfb33e80158966ca Mon Sep 17 00:00:00 2001 From: ARay Date: Thu, 18 Jun 2026 18:05:54 +0300 Subject: [PATCH 1/3] add test for the pr --- tests/issues/test_issue_6853.odin | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/issues/test_issue_6853.odin diff --git a/tests/issues/test_issue_6853.odin b/tests/issues/test_issue_6853.odin new file mode 100644 index 000000000..af0bcebe5 --- /dev/null +++ b/tests/issues/test_issue_6853.odin @@ -0,0 +1,25 @@ +package test_issues + +import "core:testing" + +@(test) +test_issue_6853 :: proc(t: ^testing.T) { + + test_s :: struct { + a, b, c, d, e: u64, + } + + expected := test_s{1, 2, 3, 4, 5} + + case0 :: proc() -> (u64, u64) {return 1, 2} + test0 := test_s{case0(), 3, 4, 5} + testing.expect_value(t, test0, expected) + + case1 :: proc() -> (u64, u64, u64) {return 1, 2, 3} + test1 := test_s{case1(), 4, 5} + testing.expect_value(t, test1, expected) + + case2 :: proc() -> (u64, u64) {return 2, 3} + test2 := test_s{1, case2(), 4, 5} + testing.expect_value(t, test2, expected) +} From 3db074900fac9341a6df40824b310a9f1c9152bf Mon Sep 17 00:00:00 2001 From: ARay Date: Fri, 19 Jun 2026 15:05:23 +0300 Subject: [PATCH 2/3] comment out dead code: val is not used anywhere else in that scope --- src/llvm_backend_const.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/llvm_backend_const.cpp b/src/llvm_backend_const.cpp index 0f0d458dc..20df5fdd0 100644 --- a/src/llvm_backend_const.cpp +++ b/src/llvm_backend_const.cpp @@ -1970,10 +1970,13 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, Ty for_array(i, cl->elems) { Entity *f = type->Struct.fields[i]; TypeAndValue tav = cl->elems[i]->tav; - ExactValue val = {}; - if (tav.mode != Addressing_Invalid) { - val = tav.value; - } + + // INFO: dead code: + + // ExactValue val = {}; + // if (tav.mode != Addressing_Invalid) { + // val = tav.value; + // } i32 index = field_remapping[f->Variable.field_index]; if (elem_type_can_be_constant(f->type)) { From 912a45769bc95f248fd9b1dda14535f4eca9463c Mon Sep 17 00:00:00 2001 From: ARay Date: Fri, 19 Jun 2026 15:39:24 +0300 Subject: [PATCH 3/3] fix issue 6853: when iterating the values of an array literal,if one of the values is a function with multiple returns, it doesn't offset the struct field index by the number of values. --- src/llvm_backend_const.cpp | 13 +++++++++++-- tests/issues/test_issue_6853.odin | 5 +++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/llvm_backend_const.cpp b/src/llvm_backend_const.cpp index 20df5fdd0..a59ed4401 100644 --- a/src/llvm_backend_const.cpp +++ b/src/llvm_backend_const.cpp @@ -1967,8 +1967,9 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, Ty } } } else { + isize multiple_return_offset = 0; for_array(i, cl->elems) { - Entity *f = type->Struct.fields[i]; + Entity *f = type->Struct.fields[i+multiple_return_offset]; TypeAndValue tav = cl->elems[i]->tav; // INFO: dead code: @@ -1978,11 +1979,19 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, Ty // val = tav.value; // } + if (is_type_tuple(tav.type)){ + multiple_return_offset += tav.type->Tuple.variables.count-1; + } + i32 index = field_remapping[f->Variable.field_index]; + + if (elem_type_can_be_constant(f->type)) { lbValue value = lb_const_value(m, f->type, tav.value, tav.type, cc); LLVMTypeRef value_type = LLVMTypeOf(value.value); - GB_ASSERT_MSG(lb_sizeof(value_type) == type_size_of(f->type), "%s vs %s", LLVMPrintTypeToString(value_type), type_to_string(f->type)); + isize lb_sizeof_value_type = lb_sizeof(value_type); + isize type_size_of_f_type = type_size_of(f->type); + GB_ASSERT_MSG(lb_sizeof_value_type ==type_size_of_f_type, "%s vs %s", LLVMPrintTypeToString(value_type), type_to_string(f->type)); values[index] = value.value; visited[index] = true; } diff --git a/tests/issues/test_issue_6853.odin b/tests/issues/test_issue_6853.odin index af0bcebe5..fec4951a5 100644 --- a/tests/issues/test_issue_6853.odin +++ b/tests/issues/test_issue_6853.odin @@ -22,4 +22,9 @@ test_issue_6853 :: proc(t: ^testing.T) { case2 :: proc() -> (u64, u64) {return 2, 3} test2 := test_s{1, case2(), 4, 5} testing.expect_value(t, test2, expected) + + case3_1 :: proc() -> (u64, u64) {return 1, 2} + case3_2 :: proc() -> (u64, u64) {return 3, 4} + test3 := test_s{case3_1(), case3_2(), 5} + testing.expect_value(t, test3, expected) }