mirror of
https://github.com/ziglang/zig.git
synced 2026-02-21 16:54:52 +00:00
ubsan_rt: port to new std.io.BufferedWriter API
This commit is contained in:
parent
d76c8d0bd2
commit
5d22c588e2
@ -121,28 +121,26 @@ const Value = extern struct {
|
||||
|
||||
pub fn format(
|
||||
value: Value,
|
||||
bw: *std.io.BufferedWriter,
|
||||
comptime fmt: []const u8,
|
||||
_: std.fmt.FormatOptions,
|
||||
writer: anytype,
|
||||
) !void {
|
||||
) anyerror!usize {
|
||||
comptime assert(fmt.len == 0);
|
||||
|
||||
// Work around x86_64 backend limitation.
|
||||
if (builtin.zig_backend == .stage2_x86_64 and builtin.os.tag == .windows) {
|
||||
try writer.writeAll("(unknown)");
|
||||
return;
|
||||
return bw.writeAllCount("(unknown)");
|
||||
}
|
||||
|
||||
switch (value.td.kind) {
|
||||
.integer => {
|
||||
if (value.td.isSigned()) {
|
||||
try writer.print("{}", .{value.getSignedInteger()});
|
||||
return bw.printCount("{d}", .{value.getSignedInteger()});
|
||||
} else {
|
||||
try writer.print("{}", .{value.getUnsignedInteger()});
|
||||
return bw.printCount("{d}", .{value.getUnsignedInteger()});
|
||||
}
|
||||
},
|
||||
.float => try writer.print("{}", .{value.getFloat()}),
|
||||
.unknown => try writer.writeAll("(unknown)"),
|
||||
.float => return bw.printCount("{d}", .{value.getFloat()}),
|
||||
.unknown => return bw.writeAllCount("(unknown)"),
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -174,8 +172,8 @@ fn overflowHandler(
|
||||
const rhs: Value = .{ .handle = rhs_handle, .td = data.td };
|
||||
|
||||
const is_signed = data.td.isSigned();
|
||||
const fmt = "{s} integer overflow: " ++ "{} " ++
|
||||
operator ++ " {} cannot be represented in type {s}";
|
||||
const fmt = "{s} integer overflow: " ++ "{f} " ++
|
||||
operator ++ " {f} cannot be represented in type {s}";
|
||||
|
||||
panic(@returnAddress(), fmt, .{
|
||||
if (is_signed) "signed" else "unsigned",
|
||||
@ -203,7 +201,7 @@ fn negationHandler(
|
||||
const value: Value = .{ .handle = value_handle, .td = data.td };
|
||||
panic(
|
||||
@returnAddress(),
|
||||
"negation of {} cannot be represented in type {s}",
|
||||
"negation of {f} cannot be represented in type {s}",
|
||||
.{ value, data.td.getName() },
|
||||
);
|
||||
}
|
||||
@ -227,7 +225,7 @@ fn divRemHandler(
|
||||
if (rhs.isMinusOne()) {
|
||||
panic(
|
||||
@returnAddress(),
|
||||
"division of {} by -1 cannot be represented in type {s}",
|
||||
"division of {f} by -1 cannot be represented in type {s}",
|
||||
.{ lhs, data.td.getName() },
|
||||
);
|
||||
} else panic(@returnAddress(), "division by zero", .{});
|
||||
@ -269,8 +267,8 @@ fn alignmentAssumptionHandler(
|
||||
if (maybe_offset) |offset| {
|
||||
panic(
|
||||
@returnAddress(),
|
||||
"assumption of {} byte alignment (with offset of {} byte) for pointer of type {s} failed\n" ++
|
||||
"offset address is {} aligned, misalignment offset is {} bytes",
|
||||
"assumption of {f} byte alignment (with offset of {d} byte) for pointer of type {s} failed\n" ++
|
||||
"offset address is {d} aligned, misalignment offset is {d} bytes",
|
||||
.{
|
||||
alignment,
|
||||
@intFromPtr(offset),
|
||||
@ -282,8 +280,8 @@ fn alignmentAssumptionHandler(
|
||||
} else {
|
||||
panic(
|
||||
@returnAddress(),
|
||||
"assumption of {} byte alignment for pointer of type {s} failed\n" ++
|
||||
"address is {} aligned, misalignment offset is {} bytes",
|
||||
"assumption of {f} byte alignment for pointer of type {s} failed\n" ++
|
||||
"address is {d} aligned, misalignment offset is {d} bytes",
|
||||
.{
|
||||
alignment,
|
||||
data.td.getName(),
|
||||
@ -320,21 +318,21 @@ fn shiftOob(
|
||||
rhs.getPositiveInteger() >= data.lhs_type.getIntegerSize())
|
||||
{
|
||||
if (rhs.isNegative()) {
|
||||
panic(@returnAddress(), "shift exponent {} is negative", .{rhs});
|
||||
panic(@returnAddress(), "shift exponent {f} is negative", .{rhs});
|
||||
} else {
|
||||
panic(
|
||||
@returnAddress(),
|
||||
"shift exponent {} is too large for {}-bit type {s}",
|
||||
"shift exponent {f} is too large for {d}-bit type {s}",
|
||||
.{ rhs, data.lhs_type.getIntegerSize(), data.lhs_type.getName() },
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (lhs.isNegative()) {
|
||||
panic(@returnAddress(), "left shift of negative value {}", .{lhs});
|
||||
panic(@returnAddress(), "left shift of negative value {f}", .{lhs});
|
||||
} else {
|
||||
panic(
|
||||
@returnAddress(),
|
||||
"left shift of {} by {} places cannot be represented in type {s}",
|
||||
"left shift of {f} by {f} places cannot be represented in type {s}",
|
||||
.{ lhs, rhs, data.lhs_type.getName() },
|
||||
);
|
||||
}
|
||||
@ -361,7 +359,7 @@ fn outOfBounds(
|
||||
const index: Value = .{ .handle = index_handle, .td = data.index_type };
|
||||
panic(
|
||||
@returnAddress(),
|
||||
"index {} out of bounds for type {s}",
|
||||
"index {f} out of bounds for type {s}",
|
||||
.{ index, data.array_type.getName() },
|
||||
);
|
||||
}
|
||||
@ -387,7 +385,7 @@ fn pointerOverflow(
|
||||
if (result == 0) {
|
||||
panic(@returnAddress(), "applying zero offset to null pointer", .{});
|
||||
} else {
|
||||
panic(@returnAddress(), "applying non-zero offset {} to null pointer", .{result});
|
||||
panic(@returnAddress(), "applying non-zero offset {d} to null pointer", .{result});
|
||||
}
|
||||
} else {
|
||||
if (result == 0) {
|
||||
@ -483,7 +481,7 @@ fn typeMismatch(
|
||||
} else if (!std.mem.isAligned(handle, alignment)) {
|
||||
panic(
|
||||
@returnAddress(),
|
||||
"{s} misaligned address 0x{x} for type {s}, which requires {} byte alignment",
|
||||
"{s} misaligned address 0x{x} for type {s}, which requires {d} byte alignment",
|
||||
.{ data.kind.getName(), handle, data.td.getName(), alignment },
|
||||
);
|
||||
} else {
|
||||
@ -531,7 +529,7 @@ fn nonNullArgAbort(data: *const NonNullArgData) callconv(.c) noreturn {
|
||||
fn nonNullArg(data: *const NonNullArgData) callconv(.c) noreturn {
|
||||
panic(
|
||||
@returnAddress(),
|
||||
"null pointer passed as argument {}, which is declared to never be null",
|
||||
"null pointer passed as argument {d}, which is declared to never be null",
|
||||
.{data.arg_index},
|
||||
);
|
||||
}
|
||||
@ -555,7 +553,7 @@ fn loadInvalidValue(
|
||||
const value: Value = .{ .handle = value_handle, .td = data.td };
|
||||
panic(
|
||||
@returnAddress(),
|
||||
"load of value {}, which is not valid for type {s}",
|
||||
"load of value {f}, which is not valid for type {s}",
|
||||
.{ value, data.td.getName() },
|
||||
);
|
||||
}
|
||||
@ -598,7 +596,7 @@ fn vlaBoundNotPositive(
|
||||
const bound: Value = .{ .handle = bound_handle, .td = data.td };
|
||||
panic(
|
||||
@returnAddress(),
|
||||
"variable length array bound evaluates to non-positive value {}",
|
||||
"variable length array bound evaluates to non-positive value {f}",
|
||||
.{bound},
|
||||
);
|
||||
}
|
||||
@ -631,13 +629,13 @@ fn floatCastOverflow(
|
||||
if (@as(u16, ptr[0]) + @as(u16, ptr[1]) < 2 or ptr[0] == 0xFF or ptr[1] == 0xFF) {
|
||||
const data: *const FloatCastOverflowData = @ptrCast(data_handle);
|
||||
const from_value: Value = .{ .handle = from_handle, .td = data.from };
|
||||
panic(@returnAddress(), "{} is outside the range of representable values of type {s}", .{
|
||||
panic(@returnAddress(), "{f} is outside the range of representable values of type {s}", .{
|
||||
from_value, data.to.getName(),
|
||||
});
|
||||
} else {
|
||||
const data: *const FloatCastOverflowDataV2 = @ptrCast(data_handle);
|
||||
const from_value: Value = .{ .handle = from_handle, .td = data.from };
|
||||
panic(@returnAddress(), "{} is outside the range of representable values of type {s}", .{
|
||||
panic(@returnAddress(), "{f} is outside the range of representable values of type {s}", .{
|
||||
from_value, data.to.getName(),
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user