From 667ad9250f7250670778beedcebc45f5c0284446 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 14 Jul 2022 16:48:44 -0700 Subject: Sema: fix coerce_result_ptr in case of inferred result type Previously, the logic for analyzing coerce_result_ptr would generate invalid bitcast instructions which did not include coercion logic, such as optional wrapping, resulting in miscompilations. Now, the logic of resolve_inferred_alloc goes back over all the placeholders inserted by coerce_result_ptr, and replaces them with logic doing the proper coercions. Closes #12045 --- src/value.zig | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/value.zig') diff --git a/src/value.zig b/src/value.zig index b52e67e31c..46624a822d 100644 --- a/src/value.zig +++ b/src/value.zig @@ -4935,7 +4935,16 @@ pub const Value = extern union { /// peer type resolution. This is stored in a separate list so that /// the items are contiguous in memory and thus can be passed to /// `Module.resolvePeerTypes`. - stored_inst_list: std.ArrayListUnmanaged(Air.Inst.Ref) = .{}, + prongs: std.MultiArrayList(struct { + /// The dummy instruction used as a peer to resolve the type. + /// Although this has a redundant type with placeholder, this is + /// needed in addition because it may be a constant value, which + /// affects peer type resolution. + stored_inst: Air.Inst.Ref, + /// The bitcast instruction used as a placeholder when the + /// new result pointer type is not yet known. + placeholder: Air.Inst.Index, + }) = .{}, /// 0 means ABI-aligned. alignment: u32, }, -- cgit v1.2.3