diff options
| author | sin-ack <sin-ack@users.noreply.github.com> | 2022-08-12 21:51:07 +0000 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-08-15 11:34:12 +0300 |
| commit | a9c4dc84f487c4764c5787439ea87962f698d511 (patch) | |
| tree | 79f795fe801b9fe79dd80bcbf4eb155806331a4b /src/Sema.zig | |
| parent | 40eac90280db34afd31da5ad0e6be8a4795f858b (diff) | |
| download | zig-a9c4dc84f487c4764c5787439ea87962f698d511.tar.gz zig-a9c4dc84f487c4764c5787439ea87962f698d511.zip | |
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
Diffstat (limited to 'src/Sema.zig')
| -rw-r--r-- | src/Sema.zig | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index ed8204b346..879ecb4e2f 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -1906,8 +1906,6 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { } const mod = sema.mod; - sema.err = err_msg; - { errdefer err_msg.destroy(mod.gpa); if (err_msg.src_loc.lazy == .unneeded) { @@ -1925,8 +1923,10 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { const gop = mod.failed_decls.getOrPutAssumeCapacity(sema.owner_decl_index); if (gop.found_existing) { // If there are multiple errors for the same Decl, prefer the first one added. + sema.err = null; err_msg.destroy(mod.gpa); } else { + sema.err = err_msg; gop.value_ptr.* = err_msg; } return error.AnalysisFail; |
