Skip to content

Commit 47d8ff9

Browse files
authored
cgen: fix codegen for multi return with aliased fixed array (fix #24280) (#24295)
1 parent 0959234 commit 47d8ff9

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

‎vlib/v/gen/c/cgen.v‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5930,6 +5930,9 @@ fn (mut g Gen) return_stmt(node ast.Return) {
59305930
line := g.go_before_last_stmt().trim_space()
59315931
expr_styp := g.styp(node.types[i])
59325932
g.write('memcpy(&${tmpvar}.arg${arg_idx}, ')
5933+
if expr is ast.StructInit {
5934+
g.write('(${expr_styp})')
5935+
}
59335936
g.expr(expr)
59345937
g.writeln(', sizeof(${expr_styp}));')
59355938
final_assignments += g.go_before_last_stmt() + '\t'
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
type Bytes32 = [32]u8
2+
3+
pub fn a(x1 Bytes32, y1 Bytes32, z1 Bytes32, x2 Bytes32, y2 Bytes32, z2 Bytes32) (Bytes32, Bytes32, Bytes32) {
4+
return Bytes32{}, Bytes32{}, Bytes32{}
5+
}
6+
7+
pub fn b(x Bytes32, y Bytes32, z Bytes32) (Bytes32, Bytes32) {
8+
return Bytes32{}, Bytes32{}
9+
}
10+
11+
fn test_main() {
12+
x1 := Bytes32{}
13+
y1 := Bytes32{}
14+
z1 := Bytes32{}
15+
x2 := Bytes32{}
16+
y2 := Bytes32{}
17+
z2 := Bytes32{}
18+
19+
x3, y3, z3 := a(x1, y1, z1, x2, y2, z2)
20+
21+
xx, yy := b(x3, y3, z3)
22+
23+
assert xx == yy
24+
}

0 commit comments

Comments
 (0)