diff --git a/releasenotes.md b/releasenotes.md index c9611f0dc..b16146ee5 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -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 diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 901ca2138..311b1a186 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -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); @@ -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; @@ -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:; } } diff --git a/test/test_suite/assignment/alignment_index.c3t b/test/test_suite/assignment/alignment_index.c3t index 9685ced18..5674c7b96 100644 --- a/test/test_suite/assignment/alignment_index.c3t +++ b/test/test_suite/assignment/alignment_index.c3t @@ -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 } \ No newline at end of file diff --git a/test/test_suite/vector/swizzling.c3 b/test/test_suite/vector/swizzling.c3 index eaf9e69e1..e7b4c72b4 100644 --- a/test/test_suite/vector/swizzling.c3 +++ b/test/test_suite/vector/swizzling.c3 @@ -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; +} \ No newline at end of file