Skip to content

Commit a9c4dc8

Browse files
sin-ackVexu
authored andcommitted
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 parent 40eac90 commit a9c4dc8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Sema.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

0 commit comments

Comments
 (0)