Splat 8 arguments can sometimes cause incorrect behaviour in the compiler. #2283

This commit is contained in:
Christoffer Lerno
2025-07-09 16:35:56 +02:00
parent 123b1c8f44
commit bf0ff8abbc
3 changed files with 35 additions and 1 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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
}