aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2025-06-05 14:02:56 +0200
committerGitHub <noreply@github.com>2025-06-05 14:02:56 +0200
commit8cd5d01dad7f388dd91d061a6af6d74f8488d77a (patch)
tree7c7b89a429bf9b2f37410b8ae8cd0128296728fe /src
parent9eefa2006eccdf942c01fc1421784edea78c5591 (diff)
parent36b41ce163843c9524d789e6edbc171c1d723e85 (diff)
Merge pull request #5282 from Feoramund/fix-4364
Let compound literal array be broadcast to a struct field of arrays
Diffstat (limited to 'src')
-rw-r--r--src/llvm_backend_const.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/llvm_backend_const.cpp b/src/llvm_backend_const.cpp
index 02bb7473c..e897ae282 100644
--- a/src/llvm_backend_const.cpp
+++ b/src/llvm_backend_const.cpp
@@ -1056,7 +1056,18 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, lb
res.value = lb_build_constant_array_values(m, type, elem_type, cast(isize)type->Array.count, values, cc);
return res;
+ } else if (value.value_compound->tav.type == elem_type) {
+ // Compound is of array item type; expand its value to all items in array.
+ LLVMValueRef* values = gb_alloc_array(temporary_allocator(), LLVMValueRef, cast(isize)type->Array.count);
+
+ for (isize i = 0; i < type->Array.count; i++) {
+ values[i] = lb_const_value(m, elem_type, value, cc).value;
+ }
+
+ res.value = lb_build_constant_array_values(m, type, elem_type, cast(isize)type->Array.count, values, cc);
+ return res;
} else {
+ // Assume that compound value is an array literal
GB_ASSERT_MSG(elem_count == type->Array.count, "%td != %td", elem_count, type->Array.count);
LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, cast(isize)type->Array.count);