aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend_const.cpp
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2025-08-02 13:11:34 +0100
committergingerBill <gingerBill@users.noreply.github.com>2025-08-02 13:11:34 +0100
commitdca9bf0b0c8a3ad2ac6854c901d99868d3a296d5 (patch)
tree20a17e438b0409e45e293264ea7f76fafdd6e13e /src/llvm_backend_const.cpp
parente049dde582ac6525b9ce470a4af89075408c8de9 (diff)
Fix string16 literal length set in LLVM
Diffstat (limited to 'src/llvm_backend_const.cpp')
-rw-r--r--src/llvm_backend_const.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/llvm_backend_const.cpp b/src/llvm_backend_const.cpp
index cba0000cd..e64be49f2 100644
--- a/src/llvm_backend_const.cpp
+++ b/src/llvm_backend_const.cpp
@@ -782,9 +782,12 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, lb
lbValue res = {};
res.type = default_type(original_type);
+ isize len = value.value_string.len;
+
if (is_type_string16(res.type) || is_type_cstring16(res.type)) {
TEMPORARY_ALLOCATOR_GUARD();
String16 s16 = string_to_string16(temporary_allocator(), value.value_string);
+ len = s16.len;
ptr = lb_find_or_add_entity_string16_ptr(m, s16, custom_link_section);
} else {
ptr = lb_find_or_add_entity_string_ptr(m, value.value_string, custom_link_section);
@@ -797,10 +800,14 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, lb
if (is_type_cstring(res.type) || is_type_cstring16(res.type)) {
res.value = ptr;
} else {
- if (value.value_string.len == 0) {
- ptr = LLVMConstNull(lb_type(m, t_u8_ptr));
+ if (len == 0) {
+ if (is_type_string16(res.type)) {
+ ptr = LLVMConstNull(lb_type(m, t_u16_ptr));
+ } else {
+ ptr = LLVMConstNull(lb_type(m, t_u8_ptr));
+ }
}
- LLVMValueRef str_len = LLVMConstInt(lb_type(m, t_int), value.value_string.len, true);
+ LLVMValueRef str_len = LLVMConstInt(lb_type(m, t_int), len, true);
GB_ASSERT(is_type_string(original_type));
if (is_type_string16(res.type)) {