mirror of
https://github.com/odin-lang/Odin.git
synced 2026-01-07 13:33:13 +00:00
Correct endianness on slicing
This commit is contained in:
@@ -888,7 +888,6 @@ lbValue lb_build_binary_expr(lbProcedure *p, Ast *expr) {
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) {
|
||||
lbModule *m = p->module;
|
||||
t = reduce_tuple_to_single_type(t);
|
||||
@@ -2981,8 +2980,12 @@ lbAddr lb_build_addr(lbProcedure *p, Ast *expr) {
|
||||
lbValue low = lb_const_int(p->module, t_int, 0);
|
||||
lbValue high = {};
|
||||
|
||||
if (se->low != nullptr) low = lb_build_expr(p, se->low);
|
||||
if (se->high != nullptr) high = lb_build_expr(p, se->high);
|
||||
if (se->low != nullptr) {
|
||||
low = lb_correct_endianness(p, lb_build_expr(p, se->low));
|
||||
}
|
||||
if (se->high != nullptr) {
|
||||
high = lb_correct_endianness(p, lb_build_expr(p, se->high));
|
||||
}
|
||||
|
||||
bool no_indices = se->low == nullptr && se->high == nullptr;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user