mirror of
https://github.com/odin-lang/Odin.git
synced 2026-02-17 08:34:08 +00:00
Merge pull request #4339 from laytan/fix-swizzle-in-for
fix swizzle in for in statement
This commit is contained in:
@@ -546,8 +546,11 @@ gb_internal lbValue lb_addr_get_ptr(lbProcedure *p, lbAddr const &addr) {
|
||||
break;
|
||||
|
||||
case lbAddr_Swizzle:
|
||||
GB_PANIC("lbAddr_Swizzle should be handled elsewhere");
|
||||
break;
|
||||
|
||||
case lbAddr_SwizzleLarge:
|
||||
// TOOD(bill): is this good enough logic?
|
||||
GB_PANIC("lbAddr_SwizzleLarge should be handled elsewhere");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -922,7 +925,7 @@ gb_internal void lb_addr_store(lbProcedure *p, lbAddr addr, lbValue value) {
|
||||
GB_ASSERT(value.value != nullptr);
|
||||
value = lb_emit_conv(p, value, lb_addr_type(addr));
|
||||
|
||||
lbValue dst = lb_addr_get_ptr(p, addr);
|
||||
lbValue dst = addr.addr;
|
||||
lbValue src = lb_address_from_load_or_generate_local(p, value);
|
||||
{
|
||||
lbValue src_ptrs[4] = {};
|
||||
@@ -948,7 +951,7 @@ gb_internal void lb_addr_store(lbProcedure *p, lbAddr addr, lbValue value) {
|
||||
GB_ASSERT(value.value != nullptr);
|
||||
value = lb_emit_conv(p, value, lb_addr_type(addr));
|
||||
|
||||
lbValue dst = lb_addr_get_ptr(p, addr);
|
||||
lbValue dst = addr.addr;
|
||||
lbValue src = lb_address_from_load_or_generate_local(p, value);
|
||||
for_array(i, addr.swizzle_large.indices) {
|
||||
lbValue src_ptr = lb_emit_array_epi(p, src, i);
|
||||
|
||||
@@ -1072,10 +1072,22 @@ gb_internal void lb_build_range_stmt(lbProcedure *p, AstRangeStmt *rs, Scope *sc
|
||||
break;
|
||||
}
|
||||
case Type_Array: {
|
||||
lbValue array = lb_build_addr_ptr(p, expr);
|
||||
if (is_type_pointer(type_deref(array.type))) {
|
||||
array = lb_emit_load(p, array);
|
||||
lbValue array;
|
||||
lbAddr addr = lb_build_addr(p, expr);
|
||||
switch (addr.kind) {
|
||||
case lbAddr_Swizzle:
|
||||
case lbAddr_SwizzleLarge:
|
||||
// NOTE(laytan): apply the swizzle.
|
||||
array = lb_address_from_load(p, lb_addr_load(p, addr));
|
||||
break;
|
||||
default:
|
||||
array = lb_addr_get_ptr(p, addr);
|
||||
if (is_type_pointer(type_deref(array.type))) {
|
||||
array = lb_emit_load(p, array);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
lbAddr count_ptr = lb_add_local_generated(p, t_int, false);
|
||||
lb_addr_store(p, count_ptr, lb_const_int(p->module, t_int, et->Array.count));
|
||||
lb_build_range_indexed(p, array, val0_type, count_ptr.addr, &val, &key, &loop, &done, rs->reverse);
|
||||
|
||||
@@ -9,6 +9,7 @@ set COMMON=-define:ODIN_TEST_FANCY=false -file -vet -strict-style
|
||||
|
||||
..\..\..\odin test ..\test_issue_829.odin %COMMON% || exit /b
|
||||
..\..\..\odin test ..\test_issue_1592.odin %COMMON% || exit /b
|
||||
..\..\..\odin test ..\test_issue_1730.odin %COMMON% || exit /b
|
||||
..\..\..\odin test ..\test_issue_2056.odin %COMMON% || exit /b
|
||||
..\..\..\odin build ..\test_issue_2113.odin %COMMON% -debug || exit /b
|
||||
..\..\..\odin test ..\test_issue_2466.odin %COMMON% || exit /b
|
||||
|
||||
@@ -10,6 +10,7 @@ set -x
|
||||
|
||||
$ODIN test ../test_issue_829.odin $COMMON
|
||||
$ODIN test ../test_issue_1592.odin $COMMON
|
||||
$ODIN test ../test_issue_1730.odin $COMMON
|
||||
$ODIN test ../test_issue_2056.odin $COMMON
|
||||
$ODIN build ../test_issue_2113.odin $COMMON -debug
|
||||
$ODIN test ../test_issue_2466.odin $COMMON
|
||||
|
||||
21
tests/issues/test_issue_1730.odin
Normal file
21
tests/issues/test_issue_1730.odin
Normal file
@@ -0,0 +1,21 @@
|
||||
package test_issues
|
||||
|
||||
import "core:testing"
|
||||
|
||||
// Tests issue #1730 https://github.com/odin-lang/Odin/issues/1730
|
||||
@(test)
|
||||
test_issue_1730 :: proc(t: ^testing.T) {
|
||||
ll := [4]int{1, 2, 3, 4}
|
||||
for l, i in ll.yz {
|
||||
testing.expect(t, i <= 1)
|
||||
if i == 0 {
|
||||
testing.expect_value(t, l, 2)
|
||||
} else if i == 1 {
|
||||
testing.expect_value(t, l, 3)
|
||||
}
|
||||
}
|
||||
|
||||
out: [4]int
|
||||
out.yz = ll.yz
|
||||
testing.expect_value(t, out, [4]int{0, 2, 3, 0})
|
||||
}
|
||||
Reference in New Issue
Block a user