Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

llvm: Don't emit extra debug instructions for dbg_var_val in naked functions #21070

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions src/codegen/llvm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6709,8 +6709,6 @@ pub const FuncGen = struct {
const operand_ty = self.typeOf(pl_op.operand);
const name = self.air.nullTerminatedString(pl_op.payload);

if (needDbgVarWorkaround(o)) return .none;

const debug_local_var = try o.builder.debugLocalVar(
try o.builder.metadataString(name),
self.file,
Expand All @@ -6734,7 +6732,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);
Expand Down Expand Up @@ -8815,7 +8816,6 @@ pub const FuncGen = struct {
if (self.is_naked) return arg_val;

const inst_ty = self.typeOfIndex(inst);
if (needDbgVarWorkaround(o)) return arg_val;

const name = self.air.instructions.items(.data)[@intFromEnum(inst)].arg.name;
if (name == .none) return arg_val;
Expand Down Expand Up @@ -11804,16 +11804,6 @@ const optional_layout_version = 3;

const lt_errors_fn_name = "__zig_lt_errors_len";

/// Without this workaround, LLVM crashes with "unknown codeview register H1"
/// https://github.com/llvm/llvm-project/issues/56484
fn needDbgVarWorkaround(o: *Object) bool {
const target = o.pt.zcu.getTarget();
if (target.os.tag == .windows and target.cpu.arch == .aarch64) {
return true;
}
return false;
}

fn compilerRtIntBits(bits: u16) u16 {
inline for (.{ 32, 64, 128 }) |b| {
if (bits <= b) {
Expand Down