diff --git a/releasenotes.md b/releasenotes.md index be0981473..da50ea91a 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -39,6 +39,7 @@ - Bit shift operation fails with inline uint enum despite matching underlying type #2279. - Fix to codegen when using a bitstruct constant defined using a cast with an operator #2248. - Function pointers are now compile time constants. +- Splat 8 arguments can sometimes cause incorrect behaviour in the compiler. #2283 ### Stdlib changes - Improve contract for readline. #2280 diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 33c55d592..f21451caf 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -6369,7 +6369,7 @@ Expr **sema_expand_vasplat_exprs(SemaContext *context, Expr **exprs) } Expr **new_args = sema_splat_arraylike_insert(context, exprs, inner, len, i); if (!new_args) return false; - if (!exprs) return NULL; + exprs = new_args; count = vec_size(exprs); expand = true; break; diff --git a/test/test_suite/functions/splat_8.c3t b/test/test_suite/functions/splat_8.c3t new file mode 100644 index 000000000..fd529e56b --- /dev/null +++ b/test/test_suite/functions/splat_8.c3t @@ -0,0 +1,33 @@ +// #target: linux-aarch64 +module test; +import std; +macro @do_splat_thing(#args) +{ + String[] args = { "program-name", ...(String[])#args }; +} + +fn int main() +{ + @do_splat_thing({ "str1","str1","str1","str1","str1","str1","str3" }); + @do_splat_thing({ "str1","str1","str1","str1","str1","str1","str1","str2" }); + return 0; +} + +/* #expect: test.ll + +define i32 @main() #0 { +entry: + %args = alloca %"char[][]", align 8 + %literal = alloca [8 x %"char[]"], align 8 + %args1 = alloca %"char[][]", align 8 + %literal2 = alloca [9 x %"char[]"], align 8 + call void @llvm.memcpy.p0.p0.i32(ptr align 8 %literal, ptr align 8 @.__const, i32 128, i1 false) + %0 = insertvalue %"char[][]" undef, ptr %literal, 0 + %1 = insertvalue %"char[][]" %0, i64 8, 1 + store %"char[][]" %1, ptr %args, align 8 + call void @llvm.memcpy.p0.p0.i32(ptr align 8 %literal2, ptr align 8 @.__const.17, i32 144, i1 false) + %2 = insertvalue %"char[][]" undef, ptr %literal2, 0 + %3 = insertvalue %"char[][]" %2, i64 9, 1 + store %"char[][]" %3, ptr %args1, align 8 + ret i32 0 +}