aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend_const.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2023-06-07 00:10:39 +0100
committergingerBill <bill@gingerbill.org>2023-06-07 00:10:39 +0100
commit2bc5e0ebd71f1337cf5c3820cb4b623a29e90fbe (patch)
treedd396912c18c8ef663ef041ea905a6647a5a2874 /src/llvm_backend_const.cpp
parentca6cef9a7ddb1e3714cc9f5a43053bc7a240b115 (diff)
Fix non-constant compound literals of slices
Diffstat (limited to 'src/llvm_backend_const.cpp')
-rw-r--r--src/llvm_backend_const.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/llvm_backend_const.cpp b/src/llvm_backend_const.cpp
index c8f1fea0f..c9d2f5b26 100644
--- a/src/llvm_backend_const.cpp
+++ b/src/llvm_backend_const.cpp
@@ -131,6 +131,25 @@ gb_internal lbValue lb_const_ptr_cast(lbModule *m, lbValue value, Type *t) {
return res;
}
+
+gb_internal LLVMValueRef llvm_const_string_internal(lbModule *m, Type *t, LLVMValueRef data, LLVMValueRef len) {
+ if (build_context.metrics.ptr_size < build_context.metrics.int_size) {
+ LLVMValueRef values[3] = {
+ data,
+ LLVMConstNull(lb_type(m, t_i32)),
+ len,
+ };
+ return llvm_const_named_struct_internal(lb_type(m, t), values, 3);
+ } else {
+ LLVMValueRef values[2] = {
+ data,
+ len,
+ };
+ return llvm_const_named_struct_internal(lb_type(m, t), values, 2);
+ }
+}
+
+
gb_internal LLVMValueRef llvm_const_named_struct(lbModule *m, Type *t, LLVMValueRef *values, isize value_count_) {
LLVMTypeRef struct_type = lb_type(m, t);
GB_ASSERT(LLVMGetTypeKind(struct_type) == LLVMStructTypeKind);
@@ -659,10 +678,9 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo
ptr = LLVMConstNull(lb_type(m, t_u8_ptr));
}
LLVMValueRef str_len = LLVMConstInt(lb_type(m, t_int), value.value_string.len, true);
- LLVMValueRef values[2] = {ptr, str_len};
GB_ASSERT(is_type_string(original_type));
- res.value = llvm_const_named_struct(m, original_type, values, 2);
+ res.value = llvm_const_string_internal(m, original_type, ptr, str_len);
}
return res;