mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
Fix string16 literal length set in LLVM
This commit is contained in:
@@ -782,9 +782,12 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, lb
|
|||||||
lbValue res = {};
|
lbValue res = {};
|
||||||
res.type = default_type(original_type);
|
res.type = default_type(original_type);
|
||||||
|
|
||||||
|
isize len = value.value_string.len;
|
||||||
|
|
||||||
if (is_type_string16(res.type) || is_type_cstring16(res.type)) {
|
if (is_type_string16(res.type) || is_type_cstring16(res.type)) {
|
||||||
TEMPORARY_ALLOCATOR_GUARD();
|
TEMPORARY_ALLOCATOR_GUARD();
|
||||||
String16 s16 = string_to_string16(temporary_allocator(), value.value_string);
|
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);
|
ptr = lb_find_or_add_entity_string16_ptr(m, s16, custom_link_section);
|
||||||
} else {
|
} else {
|
||||||
ptr = lb_find_or_add_entity_string_ptr(m, value.value_string, custom_link_section);
|
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)) {
|
if (is_type_cstring(res.type) || is_type_cstring16(res.type)) {
|
||||||
res.value = ptr;
|
res.value = ptr;
|
||||||
} else {
|
} else {
|
||||||
if (value.value_string.len == 0) {
|
if (len == 0) {
|
||||||
ptr = LLVMConstNull(lb_type(m, t_u8_ptr));
|
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));
|
GB_ASSERT(is_type_string(original_type));
|
||||||
|
|
||||||
if (is_type_string16(res.type)) {
|
if (is_type_string16(res.type)) {
|
||||||
|
|||||||
@@ -2758,7 +2758,7 @@ gb_internal LLVMValueRef lb_find_or_add_entity_string16_ptr(lbModule *m, String1
|
|||||||
LLVMValueRef global_data = LLVMAddGlobal(m->mod, type, name);
|
LLVMValueRef global_data = LLVMAddGlobal(m->mod, type, name);
|
||||||
LLVMSetInitializer(global_data, data);
|
LLVMSetInitializer(global_data, data);
|
||||||
lb_make_global_private_const(global_data);
|
lb_make_global_private_const(global_data);
|
||||||
LLVMSetAlignment(global_data, 1);
|
LLVMSetAlignment(global_data, 2);
|
||||||
|
|
||||||
LLVMValueRef ptr = LLVMConstInBoundsGEP2(type, global_data, indices, 2);
|
LLVMValueRef ptr = LLVMConstInBoundsGEP2(type, global_data, indices, 2);
|
||||||
if (!custom_link_section) {
|
if (!custom_link_section) {
|
||||||
@@ -2855,7 +2855,7 @@ gb_internal lbValue lb_find_or_add_entity_string16_slice_with_type(lbModule *m,
|
|||||||
LLVMValueRef global_data = LLVMAddGlobal(m->mod, type, name);
|
LLVMValueRef global_data = LLVMAddGlobal(m->mod, type, name);
|
||||||
LLVMSetInitializer(global_data, data);
|
LLVMSetInitializer(global_data, data);
|
||||||
lb_make_global_private_const(global_data);
|
lb_make_global_private_const(global_data);
|
||||||
LLVMSetAlignment(global_data, 1);
|
LLVMSetAlignment(global_data, 2);
|
||||||
|
|
||||||
i64 data_len = str.len;
|
i64 data_len = str.len;
|
||||||
LLVMValueRef ptr = nullptr;
|
LLVMValueRef ptr = nullptr;
|
||||||
|
|||||||
@@ -658,7 +658,6 @@ gb_internal String normalize_path(gbAllocator a, String const &path, String cons
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO(bill): Make this non-windows specific
|
|
||||||
gb_internal String16 string_to_string16(gbAllocator a, String s) {
|
gb_internal String16 string_to_string16(gbAllocator a, String s) {
|
||||||
int len, len1;
|
int len, len1;
|
||||||
u16 *text;
|
u16 *text;
|
||||||
@@ -680,7 +679,6 @@ gb_internal String16 string_to_string16(gbAllocator a, String s) {
|
|||||||
return make_string16(nullptr, 0);
|
return make_string16(nullptr, 0);
|
||||||
}
|
}
|
||||||
text[len] = 0;
|
text[len] = 0;
|
||||||
|
|
||||||
return make_string16(text, len);
|
return make_string16(text, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user