diff options
| author | gingerBill <bill@gingerbill.org> | 2021-09-12 16:45:57 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-09-12 16:45:57 +0100 |
| commit | 15921d032cfff6994289d1f299bef168f0a49a4e (patch) | |
| tree | b67dd1eec65eb8ac096272f775f9d583224677b9 /src/llvm_backend_utility.cpp | |
| parent | 9e018b642e3f1b4e9e400d3f09284ce763763d66 (diff) | |
Correct endianness on slicing
Diffstat (limited to 'src/llvm_backend_utility.cpp')
| -rw-r--r-- | src/llvm_backend_utility.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/llvm_backend_utility.cpp b/src/llvm_backend_utility.cpp index 6f08ddf5f..db3cb443e 100644 --- a/src/llvm_backend_utility.cpp +++ b/src/llvm_backend_utility.cpp @@ -38,6 +38,16 @@ bool lb_is_type_aggregate(Type *t) { } +lbValue lb_correct_endianness(lbProcedure *p, lbValue value) { + Type *src = core_type(value.type); + GB_ASSERT(is_type_integer(src) || is_type_float(src)); + if (is_type_different_to_arch_endianness(src)) { + Type *platform_src_type = integer_endian_type_to_platform_type(src); + value = lb_emit_byte_swap(p, value, platform_src_type); + } + return value; +} + void lb_mem_zero_ptr_internal(lbProcedure *p, LLVMValueRef ptr, LLVMValueRef len, unsigned alignment) { bool is_inlinable = false; @@ -1125,6 +1135,7 @@ lbValue lb_emit_array_epi(lbProcedure *p, lbValue s, isize index) { } lbValue lb_emit_ptr_offset(lbProcedure *p, lbValue ptr, lbValue index) { + index = lb_correct_endianness(p, index); LLVMValueRef indices[1] = {index.value}; lbValue res = {}; res.type = ptr.type; |