diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2023-06-11 04:14:17 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-06-11 03:01:37 -0700 |
| commit | 2afc689060e1d14e039f3c439d42f22ba09768a3 (patch) | |
| tree | d21f693ca782fb5ded76ffba090e0c0e7dbe747c | |
| parent | 7507a76879bbfb53c170f130ea836b10bc2a42e1 (diff) | |
| download | zig-2afc689060e1d14e039f3c439d42f22ba09768a3.tar.gz zig-2afc689060e1d14e039f3c439d42f22ba09768a3.zip | |
Sema: fix condition for emitting noreturn safety check
| -rw-r--r-- | src/Sema.zig | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 5cec8c19f9..21c0402c04 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -7170,23 +7170,24 @@ fn analyzeCall( try sema.ensureResultUsed(block, sema.typeOf(func_inst), call_src); } return sema.handleTailCall(block, call_src, func_ty, func_inst); - } else if (block.wantSafety() and func_ty_info.return_type == .noreturn_type) { + } + if (block.wantSafety() and func_ty_info.return_type == .noreturn_type) skip_safety: { // Function pointers and extern functions aren't guaranteed to // actually be noreturn so we add a safety check for them. - check: { - const func_val = (try sema.resolveMaybeUndefVal(func)) orelse break :check; + if (try sema.resolveMaybeUndefVal(func)) |func_val| { switch (mod.intern_pool.indexToKey(func_val.toIntern())) { - .func, .extern_func, .ptr => { - _ = try block.addNoOp(.unreach); - return Air.Inst.Ref.unreachable_value; + .func => break :skip_safety, + .ptr => |ptr| switch (ptr.addr) { + .decl => |decl| if (!mod.declPtr(decl).isExtern(mod)) break :skip_safety, + else => {}, }, - else => break :check, + else => {}, } } - try sema.safetyPanic(block, .noreturn_returned); return Air.Inst.Ref.unreachable_value; - } else if (func_ty_info.return_type == .noreturn_type) { + } + if (func_ty_info.return_type == .noreturn_type) { _ = try block.addNoOp(.unreach); return Air.Inst.Ref.unreachable_value; } |
