From 7a8e86e46ceb1350509b4296c2a45af45100df41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Tue, 13 Aug 2024 05:26:30 +0200 Subject: [PATCH] llvm: Don't emit extra debug instructions for `dbg_var_val` in naked functions. --- src/codegen/llvm.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 23fdbb177b..1a62e89517 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -6743,7 +6743,10 @@ pub const FuncGen = struct { }, "", ); - } else if (owner_mod.optimize_mode == .Debug) { + } else if (owner_mod.optimize_mode == .Debug and !self.is_naked) { + // We avoid taking this path for naked functions because there's no guarantee that such + // functions even have a valid stack pointer, making the `alloca` + `store` unsafe. + const alignment = operand_ty.abiAlignment(pt).toLlvm(); const alloca = try self.buildAlloca(operand.typeOfWip(&self.wip), alignment); _ = try self.wip.store(.normal, operand, alloca, alignment);