aboutsummaryrefslogtreecommitdiff
path: root/src/AstGen.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2023-09-15 01:12:03 +0100
committerAndrew Kelley <andrew@ziglang.org>2023-09-15 01:05:02 -0700
commitcba7e8a4e95aa2a2031d0fbaa8247de37e61fd78 (patch)
treef6e7c7139d90aa41ace1498475d6a56f4c40956f /src/AstGen.zig
parent8592c5cdac41e4e04034e4f9a0fd8cb51e8c4257 (diff)
downloadzig-cba7e8a4e95aa2a2031d0fbaa8247de37e61fd78.tar.gz
zig-cba7e8a4e95aa2a2031d0fbaa8247de37e61fd78.zip
AstGen: do not forward result pointers through @as
The `coerce_result_ptr` instruction is highly problematic and leads to unintentional memory reinterpretation in some cases. It is more correct to simply not forward result pointers through this builtin. `coerce_result_ptr` is still used for struct and array initializations, where it can still cause issues. Eliminating this usage will be a future change. Resolves: #16991
Diffstat (limited to 'src/AstGen.zig')
-rw-r--r--src/AstGen.zig32
1 files changed, 2 insertions, 30 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig
index c93bab8294..81cb93671e 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -7526,18 +7526,8 @@ fn as(
rhs: Ast.Node.Index,
) InnerError!Zir.Inst.Ref {
const dest_type = try typeExpr(gz, scope, lhs);
- switch (ri.rl) {
- .none, .discard, .ref, .ty, .coerced_ty => {
- const result = try reachableExpr(gz, scope, .{ .rl = .{ .ty = dest_type } }, rhs, node);
- return rvalue(gz, ri, result, node);
- },
- .ptr => |result_ptr| {
- return asRlPtr(gz, scope, ri, node, result_ptr.inst, rhs, dest_type);
- },
- .inferred_ptr => |result_ptr| {
- return asRlPtr(gz, scope, ri, node, result_ptr, rhs, dest_type);
- },
- }
+ const result = try reachableExpr(gz, scope, .{ .rl = .{ .ty = dest_type } }, rhs, node);
+ return rvalue(gz, ri, result, node);
}
fn unionInit(
@@ -7562,24 +7552,6 @@ fn unionInit(
return rvalue(gz, ri, result, node);
}
-fn asRlPtr(
- gz: *GenZir,
- scope: *Scope,
- ri: ResultInfo,
- src_node: Ast.Node.Index,
- result_ptr: Zir.Inst.Ref,
- operand_node: Ast.Node.Index,
- dest_type: Zir.Inst.Ref,
-) InnerError!Zir.Inst.Ref {
- if (gz.astgen.nodes_need_rl.contains(src_node)) {
- const casted_ptr = try gz.addPlNode(.coerce_result_ptr, src_node, Zir.Inst.Bin{ .lhs = dest_type, .rhs = result_ptr });
- return reachableExpr(gz, scope, .{ .rl = .{ .ptr = .{ .inst = casted_ptr } } }, operand_node, src_node);
- } else {
- const result = try reachableExpr(gz, scope, .{ .rl = .{ .ty = dest_type } }, operand_node, src_node);
- return rvalue(gz, ri, result, src_node);
- }
-}
-
fn bitCast(
gz: *GenZir,
scope: *Scope,