Skip to content

Commit 12bbcbc

Browse files
maleadtclaude
andauthored
Harden compiler-error display against disposed LLVM modules (#854)
InvalidIRError retained a live LLVM.Instruction (from check_ir_values), so showing a caught error after its module was disposed segfaulted in Value::getName (e.g. Test rendering a failed test's exception). Snapshot the instruction to a string at construction, and route `show` through `showerror` for InvalidIRError/KernelError so display never field-dumps internal IR refs. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent e107287 commit 12bbcbc

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/error.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ function Base.showerror(io::IO, err::KernelError)
2121
Base.show_backtrace(io, err.bt)
2222
end
2323

24+
# `show` via `showerror` (cf. InvalidIRError)
25+
Base.show(io::IO, err::KernelError) = showerror(io, err)
26+
2427

2528
struct InternalCompilerError <: Exception
2629
job::CompilerJob

src/validation.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ function Base.showerror(io::IO, err::InvalidIRError)
160160
return
161161
end
162162

163+
# `show` via `showerror`, avoiding the default field-dump that derefs disposed IR
164+
Base.show(io::IO, err::InvalidIRError) = showerror(io, err)
165+
163166
function check_ir(job, args...)
164167
errors = check_ir!(job, IRError[], args...)
165168
unique!(errors)
@@ -365,7 +368,9 @@ function check_ir_values(mod::LLVM.Module, predicate, msg="value")
365368
for fun in functions(mod), bb in blocks(fun), inst in instructions(bb)
366369
if predicate(inst) || any(predicate, operands(inst))
367370
bt = backtrace(inst)
368-
push!(errors, (msg, bt, inst))
371+
# snapshot to a string: the error may outlive the module, and showing a
372+
# disposed LLVM value segfaults
373+
push!(errors, (msg, bt, string(inst)))
369374
end
370375
end
371376
return errors

0 commit comments

Comments
 (0)