| ... | ... | @@ -121,28 +121,26 @@ const Value = extern struct { |
| 121 | 121 | |
| 122 | 122 | pub fn format( |
| 123 | 123 | value: Value, |
| 124 | bw: *std.io.BufferedWriter, |
| 124 | 125 | comptime fmt: []const u8, |
| 125 | | _: std.fmt.FormatOptions, |
| 126 | | writer: anytype, |
| 127 | | ) !void { |
| 126 | ) anyerror!usize { |
| 128 | 127 | comptime assert(fmt.len == 0); |
| 129 | 128 | |
| 130 | 129 | // Work around x86_64 backend limitation. |
| 131 | 130 | if (builtin.zig_backend == .stage2_x86_64 and builtin.os.tag == .windows) { |
| 132 | | try writer.writeAll("(unknown)"); |
| 133 | | return; |
| 131 | return bw.writeAllCount("(unknown)"); |
| 134 | 132 | } |
| 135 | 133 | |
| 136 | 134 | switch (value.td.kind) { |
| 137 | 135 | .integer => { |
| 138 | 136 | if (value.td.isSigned()) { |
| 139 | | try writer.print("{}", .{value.getSignedInteger()}); |
| 137 | return bw.printCount("{d}", .{value.getSignedInteger()}); |
| 140 | 138 | } else { |
| 141 | | try writer.print("{}", .{value.getUnsignedInteger()}); |
| 139 | return bw.printCount("{d}", .{value.getUnsignedInteger()}); |
| 142 | 140 | } |
| 143 | 141 | }, |
| 144 | | .float => try writer.print("{}", .{value.getFloat()}), |
| 145 | | .unknown => try writer.writeAll("(unknown)"), |
| 142 | .float => return bw.printCount("{d}", .{value.getFloat()}), |
| 143 | .unknown => return bw.writeAllCount("(unknown)"), |
| 146 | 144 | } |
| 147 | 145 | } |
| 148 | 146 | }; |
| ... | ... | @@ -174,8 +172,8 @@ fn overflowHandler( |
| 174 | 172 | const rhs: Value = .{ .handle = rhs_handle, .td = data.td }; |
| 175 | 173 | |
| 176 | 174 | const is_signed = data.td.isSigned(); |
| 177 | | const fmt = "{s} integer overflow: " ++ "{} " ++ |
| 178 | | operator ++ " {} cannot be represented in type {s}"; |
| 175 | const fmt = "{s} integer overflow: " ++ "{f} " ++ |
| 176 | operator ++ " {f} cannot be represented in type {s}"; |
| 179 | 177 | |
| 180 | 178 | panic(@returnAddress(), fmt, .{ |
| 181 | 179 | if (is_signed) "signed" else "unsigned", |
| ... | ... | @@ -203,7 +201,7 @@ fn negationHandler( |
| 203 | 201 | const value: Value = .{ .handle = value_handle, .td = data.td }; |
| 204 | 202 | panic( |
| 205 | 203 | @returnAddress(), |
| 206 | | "negation of {} cannot be represented in type {s}", |
| 204 | "negation of {f} cannot be represented in type {s}", |
| 207 | 205 | .{ value, data.td.getName() }, |
| 208 | 206 | ); |
| 209 | 207 | } |
| ... | ... | @@ -227,7 +225,7 @@ fn divRemHandler( |
| 227 | 225 | if (rhs.isMinusOne()) { |
| 228 | 226 | panic( |
| 229 | 227 | @returnAddress(), |
| 230 | | "division of {} by -1 cannot be represented in type {s}", |
| 228 | "division of {f} by -1 cannot be represented in type {s}", |
| 231 | 229 | .{ lhs, data.td.getName() }, |
| 232 | 230 | ); |
| 233 | 231 | } else panic(@returnAddress(), "division by zero", .{}); |
| ... | ... | @@ -269,8 +267,8 @@ fn alignmentAssumptionHandler( |
| 269 | 267 | if (maybe_offset) |offset| { |
| 270 | 268 | panic( |
| 271 | 269 | @returnAddress(), |
| 272 | | "assumption of {} byte alignment (with offset of {} byte) for pointer of type {s} failed\n" ++ |
| 273 | | "offset address is {} aligned, misalignment offset is {} bytes", |
| 270 | "assumption of {f} byte alignment (with offset of {d} byte) for pointer of type {s} failed\n" ++ |
| 271 | "offset address is {d} aligned, misalignment offset is {d} bytes", |
| 274 | 272 | .{ |
| 275 | 273 | alignment, |
| 276 | 274 | @intFromPtr(offset), |
| ... | ... | @@ -282,8 +280,8 @@ fn alignmentAssumptionHandler( |
| 282 | 280 | } else { |
| 283 | 281 | panic( |
| 284 | 282 | @returnAddress(), |
| 285 | | "assumption of {} byte alignment for pointer of type {s} failed\n" ++ |
| 286 | | "address is {} aligned, misalignment offset is {} bytes", |
| 283 | "assumption of {f} byte alignment for pointer of type {s} failed\n" ++ |
| 284 | "address is {d} aligned, misalignment offset is {d} bytes", |
| 287 | 285 | .{ |
| 288 | 286 | alignment, |
| 289 | 287 | data.td.getName(), |
| ... | ... | @@ -320,21 +318,21 @@ fn shiftOob( |
| 320 | 318 | rhs.getPositiveInteger() >= data.lhs_type.getIntegerSize()) |
| 321 | 319 | { |
| 322 | 320 | if (rhs.isNegative()) { |
| 323 | | panic(@returnAddress(), "shift exponent {} is negative", .{rhs}); |
| 321 | panic(@returnAddress(), "shift exponent {f} is negative", .{rhs}); |
| 324 | 322 | } else { |
| 325 | 323 | panic( |
| 326 | 324 | @returnAddress(), |
| 327 | | "shift exponent {} is too large for {}-bit type {s}", |
| 325 | "shift exponent {f} is too large for {d}-bit type {s}", |
| 328 | 326 | .{ rhs, data.lhs_type.getIntegerSize(), data.lhs_type.getName() }, |
| 329 | 327 | ); |
| 330 | 328 | } |
| 331 | 329 | } else { |
| 332 | 330 | if (lhs.isNegative()) { |
| 333 | | panic(@returnAddress(), "left shift of negative value {}", .{lhs}); |
| 331 | panic(@returnAddress(), "left shift of negative value {f}", .{lhs}); |
| 334 | 332 | } else { |
| 335 | 333 | panic( |
| 336 | 334 | @returnAddress(), |
| 337 | | "left shift of {} by {} places cannot be represented in type {s}", |
| 335 | "left shift of {f} by {f} places cannot be represented in type {s}", |
| 338 | 336 | .{ lhs, rhs, data.lhs_type.getName() }, |
| 339 | 337 | ); |
| 340 | 338 | } |
| ... | ... | @@ -361,7 +359,7 @@ fn outOfBounds( |
| 361 | 359 | const index: Value = .{ .handle = index_handle, .td = data.index_type }; |
| 362 | 360 | panic( |
| 363 | 361 | @returnAddress(), |
| 364 | | "index {} out of bounds for type {s}", |
| 362 | "index {f} out of bounds for type {s}", |
| 365 | 363 | .{ index, data.array_type.getName() }, |
| 366 | 364 | ); |
| 367 | 365 | } |
| ... | ... | @@ -387,7 +385,7 @@ fn pointerOverflow( |
| 387 | 385 | if (result == 0) { |
| 388 | 386 | panic(@returnAddress(), "applying zero offset to null pointer", .{}); |
| 389 | 387 | } else { |
| 390 | | panic(@returnAddress(), "applying non-zero offset {} to null pointer", .{result}); |
| 388 | panic(@returnAddress(), "applying non-zero offset {d} to null pointer", .{result}); |
| 391 | 389 | } |
| 392 | 390 | } else { |
| 393 | 391 | if (result == 0) { |
| ... | ... | @@ -483,7 +481,7 @@ fn typeMismatch( |
| 483 | 481 | } else if (!std.mem.isAligned(handle, alignment)) { |
| 484 | 482 | panic( |
| 485 | 483 | @returnAddress(), |
| 486 | | "{s} misaligned address 0x{x} for type {s}, which requires {} byte alignment", |
| 484 | "{s} misaligned address 0x{x} for type {s}, which requires {d} byte alignment", |
| 487 | 485 | .{ data.kind.getName(), handle, data.td.getName(), alignment }, |
| 488 | 486 | ); |
| 489 | 487 | } else { |
| ... | ... | @@ -531,7 +529,7 @@ fn nonNullArgAbort(data: *const NonNullArgData) callconv(.c) noreturn { |
| 531 | 529 | fn nonNullArg(data: *const NonNullArgData) callconv(.c) noreturn { |
| 532 | 530 | panic( |
| 533 | 531 | @returnAddress(), |
| 534 | | "null pointer passed as argument {}, which is declared to never be null", |
| 532 | "null pointer passed as argument {d}, which is declared to never be null", |
| 535 | 533 | .{data.arg_index}, |
| 536 | 534 | ); |
| 537 | 535 | } |
| ... | ... | @@ -555,7 +553,7 @@ fn loadInvalidValue( |
| 555 | 553 | const value: Value = .{ .handle = value_handle, .td = data.td }; |
| 556 | 554 | panic( |
| 557 | 555 | @returnAddress(), |
| 558 | | "load of value {}, which is not valid for type {s}", |
| 556 | "load of value {f}, which is not valid for type {s}", |
| 559 | 557 | .{ value, data.td.getName() }, |
| 560 | 558 | ); |
| 561 | 559 | } |
| ... | ... | @@ -598,7 +596,7 @@ fn vlaBoundNotPositive( |
| 598 | 596 | const bound: Value = .{ .handle = bound_handle, .td = data.td }; |
| 599 | 597 | panic( |
| 600 | 598 | @returnAddress(), |
| 601 | | "variable length array bound evaluates to non-positive value {}", |
| 599 | "variable length array bound evaluates to non-positive value {f}", |
| 602 | 600 | .{bound}, |
| 603 | 601 | ); |
| 604 | 602 | } |
| ... | ... | @@ -631,13 +629,13 @@ fn floatCastOverflow( |
| 631 | 629 | if (@as(u16, ptr[0]) + @as(u16, ptr[1]) < 2 or ptr[0] == 0xFF or ptr[1] == 0xFF) { |
| 632 | 630 | const data: *const FloatCastOverflowData = @ptrCast(data_handle); |
| 633 | 631 | const from_value: Value = .{ .handle = from_handle, .td = data.from }; |
| 634 | | panic(@returnAddress(), "{} is outside the range of representable values of type {s}", .{ |
| 632 | panic(@returnAddress(), "{f} is outside the range of representable values of type {s}", .{ |
| 635 | 633 | from_value, data.to.getName(), |
| 636 | 634 | }); |
| 637 | 635 | } else { |
| 638 | 636 | const data: *const FloatCastOverflowDataV2 = @ptrCast(data_handle); |
| 639 | 637 | const from_value: Value = .{ .handle = from_handle, .td = data.from }; |
| 640 | | panic(@returnAddress(), "{} is outside the range of representable values of type {s}", .{ |
| 638 | panic(@returnAddress(), "{f} is outside the range of representable values of type {s}", .{ |
| 641 | 639 | from_value, data.to.getName(), |
| 642 | 640 | }); |
| 643 | 641 | } |