authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-08-05 00:54:06-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-29 14:24:25-07:00
logaee3dd91af713e1c9b361fd52e4e7bfee0487391
tree95e7c4c2d34fd864bf272d9e61516bf80401e34b
parente35271856e0002ef91828918470719ca5d838d45

cbe: don't emit traps in naked functions

Closes #16680

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

src/codegen/c.zig+6-2
...@@ -2835,7 +2835,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,...@@ -2835,7 +2835,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
28352835
2836 .arg => try airArg(f, inst),2836 .arg => try airArg(f, inst),
28372837
2838 .trap => try airTrap(f.object.writer()),2838 .trap => try airTrap(f, f.object.writer()),
2839 .breakpoint => try airBreakpoint(f.object.writer()),2839 .breakpoint => try airBreakpoint(f.object.writer()),
2840 .ret_addr => try airRetAddr(f, inst),2840 .ret_addr => try airRetAddr(f, inst),
2841 .frame_addr => try airFrameAddress(f, inst),2841 .frame_addr => try airFrameAddress(f, inst),
...@@ -4591,7 +4591,11 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca...@@ -4591,7 +4591,11 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca
4591 };4591 };
4592}4592}
45934593
4594fn airTrap(writer: anytype) !CValue {4594fn airTrap(f: *Function, writer: anytype) !CValue {
4595 const mod = f.object.dg.module;
4596 // Not even allowed to call trap in a naked function.
4597 if (f.object.dg.decl) |decl| if (decl.ty.fnCallingConvention(mod) == .Naked) return .none;
4598
4595 try writer.writeAll("zig_trap();\n");4599 try writer.writeAll("zig_trap();\n");
4596 return .none;4600 return .none;
4597}4601}