Skip to content

Commit 4b8751b

Browse files
authored
Merge pull request odin-lang#5810 from LeonardoTemperanza/master
Fix: #load(<string-path>, <type>) produces unaligned accesses
2 parents 596066a + 4dd6bb2 commit 4b8751b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/llvm_backend_general.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2999,7 +2999,11 @@ gb_internal lbValue lb_find_or_add_entity_string_byte_slice_with_type(lbModule *
29992999
Type *bt = base_type(slice_type);
30003000
Type *elem = bt->Slice.elem;
30013001
i64 sz = type_size_of(elem);
3002+
i64 align = type_align_of(elem);
30023003
GB_ASSERT(sz > 0);
3004+
GB_ASSERT(align > 0);
3005+
3006+
LLVMSetAlignment(global_data, (u32)align);
30033007
ptr = LLVMConstPointerCast(ptr, lb_type(m, alloc_type_pointer(elem)));
30043008
data_len /= sz;
30053009
}
@@ -3054,7 +3058,11 @@ gb_internal lbValue lb_find_or_add_entity_string16_slice_with_type(lbModule *m,
30543058
Type *bt = base_type(slice_type);
30553059
Type *elem = bt->Slice.elem;
30563060
i64 sz = type_size_of(elem);
3061+
i64 align = type_align_of(elem);
30573062
GB_ASSERT(sz > 0);
3063+
GB_ASSERT(align > 0);
3064+
3065+
LLVMSetAlignment(global_data, (u32)align);
30583066
ptr = LLVMConstPointerCast(ptr, lb_type(m, alloc_type_pointer(elem)));
30593067
data_len /= sz;
30603068
}

0 commit comments

Comments
 (0)