- Member access on a struct returned by the assignment expression, cause crash #2947

This commit is contained in:
Christoffer Lerno
2026-02-19 20:43:39 +01:00
parent 8bb974829d
commit 585c66100d
3 changed files with 37 additions and 1 deletions

View File

@@ -46,6 +46,7 @@
- `--safe=no` disabled compile-time errors on compile-time known runtime @require checks #2936 - `--safe=no` disabled compile-time errors on compile-time known runtime @require checks #2936
- On assert known false, the message was not show for no-args. - On assert known false, the message was not show for no-args.
- Adding the incorrect sized vector to a pointer vector would cause a crash. - Adding the incorrect sized vector to a pointer vector would cause a crash.
- Member access on a struct returned by the assignment expression, cause crash #2947
## 0.7.9 Change list ## 0.7.9 Change list

View File

@@ -216,7 +216,14 @@ BEValue llvm_emit_assign_expr(GenContext *c, BEValue *ref, Expr *ref_expr, Expr
if (ref_expr && c->current_block) llvm_emit_expr(c, ref, ref_expr); if (ref_expr && c->current_block) llvm_emit_expr(c, ref, ref_expr);
} }
if (!c->current_block) goto AFTER_STORE; if (!c->current_block) goto AFTER_STORE;
if (value.type != type_void) llvm_store(c, ref, &value); if (value.type == type_void)
{
value = *ref;
}
else
{
llvm_store(c, ref, &value);
}
} }
if (optional) if (optional)

View File

@@ -0,0 +1,28 @@
// #target: macos-x64
module test;
struct Test
{
long a;
long b;
char c;
}
fn Test f() => {};
fn int main()
{
Test t;
(t = f()).b;
return 0;
}
/* #expect: test.ll
define i32 @main() #0 {
entry:
%t = alloca %Test, align 8
call void @llvm.memset.p0.i64(ptr align 8 %t, i8 0, i64 24, i1 false)
call void @test.f(ptr sret(%Test) align 8 %t)
%ptradd = getelementptr inbounds i8, ptr %t, i64 8
ret i32 0
}