authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-19 16:29:45-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-28 18:07:13-07:00
logdf52073681bdb332bef6b8a17576d80ab277c947
tree01b325b7947cb82d0e0bdb0d4eff61e546d026fc
parent6a21875ddbe0f509122fbd220f1abb015cc7bac7

llvm.Builder: add !nosanitize API

see #20992 Co-authored-by: Jacob Young <jacobly0@users.noreply.github.com>

1 files changed, 39 insertions(+), 3 deletions(-)

src/codegen/llvm/Builder.zig+39-3
......@@ -3994,6 +3994,7 @@ pub const Function = struct {
39943994 names: [*]const String = &[0]String{},
39953995 value_indices: [*]const u32 = &[0]u32{},
39963996 strip: bool,
3997 any_nosanitize: bool,
39973998 debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, DebugLocation) = .{},
39983999 debug_values: []const Instruction.Index = &.{},
39994000 extra: []const u32 = &.{},
......@@ -4090,6 +4091,7 @@ pub const Function = struct {
40904091 block,
40914092 br,
40924093 br_cond,
4094 br_cond_nosanitize,
40934095 call,
40944096 @"call fast",
40954097 cmpxchg,
......@@ -4345,6 +4347,13 @@ pub const Function = struct {
43454347 else => unreachable,
43464348 };
43474349 }
4350
4351 pub fn isNosanitize(self: Tag) bool {
4352 return switch (self) {
4353 .br_cond_nosanitize => true,
4354 else => false,
4355 };
4356 }
43484357 };
43494358
43504359 pub const Index = enum(u32) {
......@@ -4367,6 +4376,7 @@ pub const Function = struct {
43674376 return switch (wip.instructions.items(.tag)[@intFromEnum(self)]) {
43684377 .br,
43694378 .br_cond,
4379 .br_cond_nosanitize,
43704380 .ret,
43714381 .@"ret void",
43724382 .@"switch",
......@@ -4380,6 +4390,7 @@ pub const Function = struct {
43804390 return switch (wip.instructions.items(.tag)[@intFromEnum(self)]) {
43814391 .br,
43824392 .br_cond,
4393 .br_cond_nosanitize,
43834394 .fence,
43844395 .ret,
43854396 .@"ret void",
......@@ -4470,6 +4481,7 @@ pub const Function = struct {
44704481 .block => .label,
44714482 .br,
44724483 .br_cond,
4484 .br_cond_nosanitize,
44734485 .fence,
44744486 .ret,
44754487 .@"ret void",
......@@ -4656,6 +4668,7 @@ pub const Function = struct {
46564668 .block => .label,
46574669 .br,
46584670 .br_cond,
4671 .br_cond_nosanitize,
46594672 .fence,
46604673 .ret,
46614674 .@"ret void",
......@@ -5100,6 +5113,7 @@ pub const WipFunction = struct {
51005113 instructions: std.MultiArrayList(Instruction),
51015114 names: std.ArrayListUnmanaged(String),
51025115 strip: bool,
5116 any_nosanitize: bool,
51035117 debug_locations: std.AutoArrayHashMapUnmanaged(Instruction.Index, DebugLocation),
51045118 debug_values: std.AutoArrayHashMapUnmanaged(Instruction.Index, void),
51055119 extra: std.ArrayListUnmanaged(u32),
......@@ -5146,6 +5160,7 @@ pub const WipFunction = struct {
51465160 .instructions = .{},
51475161 .names = .{},
51485162 .strip = options.strip,
5163 .any_nosanitize = false,
51495164 .debug_locations = .{},
51505165 .debug_values = .{},
51515166 .extra = .{},
......@@ -6437,7 +6452,7 @@ pub const WipFunction = struct {
64376452 .@"ret void",
64386453 .@"unreachable",
64396454 => {},
6440 .br_cond => {
6455 .br_cond, .br_cond_nosanitize => {
64416456 const extra = self.extraData(Instruction.BrCond, instruction.data);
64426457 instruction.data = wip_extra.addExtra(Instruction.BrCond{
64436458 .cond = instructions.map(extra.cond),
......@@ -6624,6 +6639,7 @@ pub const WipFunction = struct {
66246639 function.names = names.ptr;
66256640 function.value_indices = value_indices.ptr;
66266641 function.strip = self.strip;
6642 function.any_nosanitize = self.any_nosanitize;
66276643 function.debug_locations = debug_locations;
66286644 function.debug_values = debug_values;
66296645 }
......@@ -8537,6 +8553,7 @@ pub fn init(options: Options) Allocator.Error!Builder {
85378553
85388554 try self.metadata_string_indices.append(self.gpa, 0);
85398555 assert(try self.metadataString("") == .none);
8556 assert(try self.debugTuple(&.{}) == .empty_tuple);
85408557
85418558 return self;
85428559}
......@@ -8934,6 +8951,7 @@ pub fn addFunctionAssumeCapacity(
89348951 .kind = .{ .function = function_index },
89358952 }),
89368953 .strip = undefined,
8954 .any_nosanitize = false,
89378955 });
89388956 return function_index;
89398957}
......@@ -9581,6 +9599,12 @@ pub fn printUnbuffered(
95819599 });
95829600 }
95839601 if (function.instructions.len > 0) {
9602 const maybe_empty_tuple: ?u32 = if (!function.any_nosanitize) null else b: {
9603 const gop = try metadata_formatter.map.getOrPut(self.gpa, .{
9604 .metadata = .empty_tuple,
9605 });
9606 break :b @intCast(gop.index);
9607 };
95849608 var block_incoming_len: u32 = undefined;
95859609 try writer.writeAll(" {\n");
95869610 var maybe_dbg_index: ?u32 = null;
......@@ -9770,6 +9794,14 @@ pub fn printUnbuffered(
97709794 }),
97719795 }
97729796 },
9797 .br_cond_nosanitize => {
9798 const extra = function.extraData(Function.Instruction.BrCond, instruction.data);
9799 try writer.print(" br {%}, {%}, {%}", .{
9800 extra.cond.fmt(function_index, self),
9801 extra.then.toInst(&function).fmt(function_index, self),
9802 extra.@"else".toInst(&function).fmt(function_index, self),
9803 });
9804 },
97739805 .call,
97749806 .@"call fast",
97759807 .@"musttail call",
......@@ -10046,8 +10078,12 @@ pub fn printUnbuffered(
1004610078 }
1004710079
1004810080 if (maybe_dbg_index) |dbg_index| {
10049 try writer.print(", !dbg !{}\n", .{dbg_index});
10050 } else try writer.writeByte('\n');
10081 try writer.print(", !dbg !{}", .{dbg_index});
10082 }
10083 if (instruction.tag.isNosanitize()) {
10084 try writer.print(", !nosanitize !{d}", .{maybe_empty_tuple.?});
10085 }
10086 try writer.writeByte('\n');
1005110087 }
1005210088 try writer.writeByte('}');
1005310089 }