Skip to content

Commit

Permalink
Named vector component access would not fold at compile time. #1574
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Oct 26, 2024
1 parent 83f8d24 commit b187d5a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
- `(uptr)&((Foo*)null).a` incorrectly inserts a null check. #1544
- Incorrect error message when `$eval` is provided an invalid string. #1570
- `HashMap.copy_keys` did not properly copy keys which needed to be allocated #1569
- Named vector component access would not fold at compile time. #1574

### Stdlib changes
- Remove unintended print of `char[]` as String
Expand Down
11 changes: 4 additions & 7 deletions src/compiler/sema_expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -4599,7 +4599,7 @@ static bool sema_expr_rewrite_to_type_property(SemaContext *context, Expr *expr,
UNREACHABLE
}

static inline bool sema_expr_analyse_swizzle(SemaContext *context, Expr *expr, Expr *parent, Type *flat_type, const char *kw, unsigned len)
static inline bool sema_expr_analyse_swizzle(SemaContext *context, Expr *expr, Expr *parent, Type *flat_type, const char *kw, unsigned len, CheckType check)
{
unsigned vec_len = flat_type->array.len;
Type *indexed_type = type_get_indexed_type(parent->type);
Expand All @@ -4624,15 +4624,12 @@ static inline bool sema_expr_analyse_swizzle(SemaContext *context, Expr *expr, E
index &= 0xF;
if (len == 1)
{
expr->expr_kind = EXPR_SUBSCRIPT_ADDR;
expr->expr_kind = EXPR_SUBSCRIPT;
expr->subscript_expr = (ExprSubscript) {
.index.expr = exprid(expr_new_const_int(expr->span, type_usz, index)),
.expr = exprid(parent)
};
expr->resolve_status = RESOLVE_DONE;
expr->type = type_get_ptr(indexed_type);
expr_rewrite_insert_deref(expr);
return true;
return sema_expr_analyse_subscript(context, expr, check, false);
}
Type *result = type_get_vector(indexed_type, len);
expr->expr_kind = EXPR_SWIZZLE;
Expand Down Expand Up @@ -4836,7 +4833,7 @@ static inline bool sema_expr_analyse_access(SemaContext *context, Expr *expr, bo
if (!swizzle[(int)kw[i]]) goto NOT_SWIZZLE;
}
// TODO should we do a missing for this as well?
return sema_expr_analyse_swizzle(context, expr, parent, flat_type, kw, len);
return sema_expr_analyse_swizzle(context, expr, parent, flat_type, kw, len, check);
NOT_SWIZZLE:;
}
}
Expand Down
4 changes: 3 additions & 1 deletion test/test_suite/assignment/alignment_index.c3t
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ entry:
%0 = load <2 x i32>, ptr @test.foo, align 1
%elemset = insertelement <2 x i32> %0, i32 2, i64 1
store <2 x i32> %elemset, ptr @test.foo, align 1
store i32 4, ptr getelementptr inbounds (i8, ptr @test.foo, i64 4), align 1
%1 = load <2 x i32>, ptr @test.foo, align 1
%elemset1 = insertelement <2 x i32> %1, i32 4, i64 1
store <2 x i32> %elemset1, ptr @test.foo, align 1
ret void
}
11 changes: 11 additions & 0 deletions test/test_suite/vector/swizzling.c3
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ fn void! swizzle_test()

}



fn int main()
{
int[<2>] $test = {3, 3};
int[<2>] $test2 = {4, 4};
$if ($test2.x != $test.x):
y++; // #error: did you spell it
$endif
return 0;
}

0 comments on commit b187d5a

Please sign in to comment.