Skip to content

Commit bdfa31d

Browse files
committed
Fix debug intrinsic locations
1 parent 0fca4c7 commit bdfa31d

1 file changed

Lines changed: 48 additions & 27 deletions

File tree

src/backend/llvm/Builder.zig

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6111,7 +6111,7 @@ pub const WipFunction = struct {
61116111
args: []const Value,
61126112
name: []const u8,
61136113
) Allocator.Error!Value {
6114-
return self.callInner(kind, call_conv, function_attributes, ty, callee, args, name, false);
6114+
return self.callInner(kind, call_conv, function_attributes, ty, callee, args, name, false, false);
61156115
}
61166116

61176117
fn callInner(
@@ -6124,6 +6124,7 @@ pub const WipFunction = struct {
61246124
args: []const Value,
61256125
name: []const u8,
61266126
has_op_bundle_cold: bool,
6127+
force_debug_location: bool,
61276128
) Allocator.Error!Value {
61286129
const ret_ty = ty.functionReturn(self.builder);
61296130
assert(ty.isFunction(self.builder));
@@ -6132,31 +6133,35 @@ pub const WipFunction = struct {
61326133
for (params, args[0..params.len]) |param, arg_val| assert(param == arg_val.typeOfWip(self));
61336134

61346135
try self.ensureUnusedExtraCapacity(1, Instruction.Call, args.len);
6135-
const instruction = try self.addInst(switch (ret_ty) {
6136-
.void => null,
6137-
else => name,
6138-
}, .{
6139-
.tag = switch (kind) {
6140-
.normal => .call,
6141-
.fast => .@"call fast",
6142-
.musttail => .@"musttail call",
6143-
.musttail_fast => .@"musttail call fast",
6144-
.notail => .@"notail call",
6145-
.notail_fast => .@"notail call fast",
6146-
.tail => .@"tail call",
6147-
.tail_fast => .@"tail call fast",
6148-
},
6149-
.data = self.addExtraAssumeCapacity(Instruction.Call{
6150-
.info = .{
6151-
.call_conv = call_conv,
6152-
.has_op_bundle_cold = has_op_bundle_cold,
6136+
const instruction = try self.addInstInner(
6137+
switch (ret_ty) {
6138+
.void => null,
6139+
else => name,
6140+
},
6141+
.{
6142+
.tag = switch (kind) {
6143+
.normal => .call,
6144+
.fast => .@"call fast",
6145+
.musttail => .@"musttail call",
6146+
.musttail_fast => .@"musttail call fast",
6147+
.notail => .@"notail call",
6148+
.notail_fast => .@"notail call fast",
6149+
.tail => .@"tail call",
6150+
.tail_fast => .@"tail call fast",
61536151
},
6154-
.attributes = function_attributes,
6155-
.ty = ty,
6156-
.callee = callee,
6157-
.args_len = @intCast(args.len),
6158-
}),
6159-
});
6152+
.data = self.addExtraAssumeCapacity(Instruction.Call{
6153+
.info = .{
6154+
.call_conv = call_conv,
6155+
.has_op_bundle_cold = has_op_bundle_cold,
6156+
},
6157+
.attributes = function_attributes,
6158+
.ty = ty,
6159+
.callee = callee,
6160+
.args_len = @intCast(args.len),
6161+
}),
6162+
},
6163+
force_debug_location,
6164+
);
61606165
self.extra.appendSliceAssumeCapacity(@ptrCast(args));
61616166
return instruction.toValue();
61626167
}
@@ -6185,14 +6190,19 @@ pub const WipFunction = struct {
61856190
name: []const u8,
61866191
) Allocator.Error!Value {
61876192
const intrinsic = try self.builder.getIntrinsic(id, overload);
6188-
return self.call(
6193+
return self.callInner(
61896194
fast.toCallKind(),
61906195
CallConv.default,
61916196
function_attributes,
61926197
intrinsic.typeOf(self.builder),
61936198
intrinsic.toValue(self.builder),
61946199
args,
61956200
name,
6201+
false,
6202+
switch (id) {
6203+
.@"dbg.declare", .@"dbg.value" => self.debug_location != .no_location,
6204+
else => false,
6205+
},
61966206
);
61976207
}
61986208

@@ -6207,6 +6217,7 @@ pub const WipFunction = struct {
62076217
&.{try self.builder.intValue(.i1, 1)},
62086218
"",
62096219
true,
6220+
false,
62106221
);
62116222
}
62126223

@@ -6990,6 +7001,15 @@ pub const WipFunction = struct {
69907001
self: *WipFunction,
69917002
name: ?[]const u8,
69927003
instruction: Instruction,
7004+
) Allocator.Error!Instruction.Index {
7005+
return self.addInstInner(name, instruction, false);
7006+
}
7007+
7008+
fn addInstInner(
7009+
self: *WipFunction,
7010+
name: ?[]const u8,
7011+
instruction: Instruction,
7012+
force_debug_location: bool,
69937013
) Allocator.Error!Instruction.Index {
69947014
const block_instructions = &self.cursor.block.ptr(self).instructions;
69957015
try self.instructions.ensureUnusedCapacity(self.builder.gpa, 1);
@@ -7007,7 +7027,8 @@ pub const WipFunction = struct {
70077027
self.instructions.appendAssumeCapacity(instruction);
70087028
if (!self.strip) {
70097029
self.names.appendAssumeCapacity(final_name);
7010-
if (block_instructions.items.len == 0 or
7030+
if (force_debug_location or
7031+
block_instructions.items.len == 0 or
70117032
!std.meta.eql(self.debug_location, self.prev_debug_location))
70127033
{
70137034
self.debug_locations.putAssumeCapacity(index, self.debug_location);

0 commit comments

Comments
 (0)