astgen: pass struct_init_empty through rvalue for proper RL handling
Typed struct init empty (SomeType{}) was returning the result directly
without going through rvalue(), missing STORE_NODE/STORE_TO_INFERRED_PTR/
COERCE_PTR_ELEM_TY+REF emissions when result location requires storage.
Reduces parser_test.zig corpus diff from 5 to 1 instruction.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
15
astgen.c
15
astgen.c
@@ -3790,8 +3790,10 @@ static uint32_t structInitExpr(
|
||||
uint32_t array_type_inst
|
||||
= addPlNodeBin(gz, ZIR_INST_ARRAY_TYPE, type_expr_node,
|
||||
ZIR_REF_ZERO_USIZE, elem_type);
|
||||
return addUnNode(
|
||||
gz, ZIR_INST_STRUCT_INIT_EMPTY, array_type_inst, node);
|
||||
return rvalue(gz, rl,
|
||||
addUnNode(gz, ZIR_INST_STRUCT_INIT_EMPTY,
|
||||
array_type_inst, node),
|
||||
node);
|
||||
}
|
||||
// ARRAY_TYPE_SENTINEL: extra[rhs] = sentinel, extra[rhs+1]
|
||||
// = elem_type
|
||||
@@ -3808,12 +3810,15 @@ static uint32_t structInitExpr(
|
||||
uint32_t array_type_inst = addPlNodeTriple(gz,
|
||||
ZIR_INST_ARRAY_TYPE_SENTINEL, type_expr_node,
|
||||
ZIR_REF_ZERO_USIZE, elem_type, sentinel);
|
||||
return addUnNode(
|
||||
gz, ZIR_INST_STRUCT_INIT_EMPTY, array_type_inst, node);
|
||||
return rvalue(gz, rl,
|
||||
addUnNode(
|
||||
gz, ZIR_INST_STRUCT_INIT_EMPTY, array_type_inst, node),
|
||||
node);
|
||||
}
|
||||
}
|
||||
uint32_t ty_inst = typeExpr(gz, scope, type_expr_node);
|
||||
return addUnNode(gz, ZIR_INST_STRUCT_INIT_EMPTY, ty_inst, node);
|
||||
return rvalue(gz, rl,
|
||||
addUnNode(gz, ZIR_INST_STRUCT_INIT_EMPTY, ty_inst, node), node);
|
||||
}
|
||||
|
||||
// Typed struct init with fields (AstGen.zig:1808-1818).
|
||||
|
||||
@@ -798,8 +798,8 @@ test "astgen: corpus tokenizer_test.zig" {
|
||||
}
|
||||
|
||||
test "astgen: corpus parser_test.zig" {
|
||||
// TODO: 5 inst diff — 2 STORE_TO_INFERRED_PTR, 1 REF, 1 STORE_NODE,
|
||||
// 1 COERCE_PTR_ELEM_TY.
|
||||
// TODO: 1 inst diff — 1 STORE_NODE inside ptr-based struct init with
|
||||
// block field init expression.
|
||||
if (true) return error.SkipZigTest;
|
||||
const gpa = std.testing.allocator;
|
||||
try corpusCheck(gpa, @embedFile("parser_test.zig"));
|
||||
|
||||
Reference in New Issue
Block a user