authorgravatar for sin-ack@users.noreply.github.comsin-ack <sin-ack@users.noreply.github.com> 2022-08-12 21:51:07+00:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-15 11:34:12+03:00
loga9c4dc84f487c4764c5787439ea87962f698d511
tree79f795fe801b9fe79dd80bcbf4eb155806331a4b
parent40eac90280db34afd31da5ad0e6be8a4795f858b

Sema: Revert sema.err to null if the Decl already has an error

Previously we would assign the error message to Sema and then never clear it even when destroying the error message, which caused memory corruption. Closes #12437

1 files changed, 2 insertions(+), 2 deletions(-)

src/Sema.zig+2-2
......@@ -1906,8 +1906,6 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError {
19061906 }
19071907
19081908 const mod = sema.mod;
1909 sema.err = err_msg;
1910
19111909 {
19121910 errdefer err_msg.destroy(mod.gpa);
19131911 if (err_msg.src_loc.lazy == .unneeded) {
......@@ -1925,8 +1923,10 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError {
19251923 const gop = mod.failed_decls.getOrPutAssumeCapacity(sema.owner_decl_index);
19261924 if (gop.found_existing) {
19271925 // If there are multiple errors for the same Decl, prefer the first one added.
1926 sema.err = null;
19281927 err_msg.destroy(mod.gpa);
19291928 } else {
1929 sema.err = err_msg;
19301930 gop.value_ptr.* = err_msg;
19311931 }
19321932 return error.AnalysisFail;