| author | |
| committer | |
| log | e88566253d65a83e3564f95504fe034b4287c340 |
| tree | ec55973b4700ead9f55cd253b9e4ed7151167b6a |
| parent | f611a72e2eb7bba2ef5fc5f578ced3c711ff7374 |
10 files changed, 55 insertions(+), 6 deletions(-)
lib/std/debug.zig+4| ... | ... | @@ -151,6 +151,10 @@ pub fn FullPanic(comptime panicFn: fn ([]const u8, ?usize) noreturn) type { |
| 151 | 151 | @branchHint(.cold); |
| 152 | 152 | call("invalid error code", @returnAddress()); |
| 153 | 153 | } |
| 154 | pub fn unexpectedErrorCode(err: anyerror) noreturn { | |
| 155 | @branchHint(.cold); | |
| 156 | std.debug.panicExtra(@returnAddress(), "unexpected error code, found error.{s}", .{@errorName(err)}); | |
| 157 | } | |
| 154 | 158 | pub fn integerOutOfBounds() noreturn { |
| 155 | 159 | @branchHint(.cold); |
| 156 | 160 | call("integer does not fit in destination type", @returnAddress()); |
lib/std/debug/no_panic.zig+5| ... | ... | @@ -65,6 +65,11 @@ pub fn invalidErrorCode() noreturn { |
| 65 | 65 | @trap(); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | pub fn unexpectedErrorCode(_: anyerror) noreturn { | |
| 69 | @branchHint(.cold); | |
| 70 | @trap(); | |
| 71 | } | |
| 72 | ||
| 68 | 73 | pub fn integerOutOfBounds() noreturn { |
| 69 | 74 | @branchHint(.cold); |
| 70 | 75 | @trap(); |
lib/std/debug/simple_panic.zig+31| ... | ... | @@ -20,110 +20,141 @@ pub fn call(msg: []const u8, ra: ?usize) noreturn { |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | pub fn sentinelMismatch(expected: anytype, found: @TypeOf(expected)) noreturn { |
| 23 | @branchHint(.cold); | |
| 23 | 24 | _ = found; |
| 24 | 25 | call("sentinel mismatch", null); |
| 25 | 26 | } |
| 26 | 27 | |
| 27 | 28 | pub fn unwrapError(err: anyerror) noreturn { |
| 29 | @branchHint(.cold); | |
| 28 | 30 | _ = &err; |
| 29 | 31 | call("attempt to unwrap error", null); |
| 30 | 32 | } |
| 31 | 33 | |
| 32 | 34 | pub fn outOfBounds(index: usize, len: usize) noreturn { |
| 35 | @branchHint(.cold); | |
| 33 | 36 | _ = index; |
| 34 | 37 | _ = len; |
| 35 | 38 | call("index out of bounds", null); |
| 36 | 39 | } |
| 37 | 40 | |
| 38 | 41 | pub fn startGreaterThanEnd(start: usize, end: usize) noreturn { |
| 42 | @branchHint(.cold); | |
| 39 | 43 | _ = start; |
| 40 | 44 | _ = end; |
| 41 | 45 | call("start index is larger than end index", null); |
| 42 | 46 | } |
| 43 | 47 | |
| 44 | 48 | pub fn inactiveUnionField(active: anytype, accessed: @TypeOf(active)) noreturn { |
| 49 | @branchHint(.cold); | |
| 45 | 50 | _ = accessed; |
| 46 | 51 | call("access of inactive union field", null); |
| 47 | 52 | } |
| 48 | 53 | |
| 49 | 54 | pub fn sliceCastLenRemainder(src_len: usize) noreturn { |
| 55 | @branchHint(.cold); | |
| 50 | 56 | _ = src_len; |
| 51 | 57 | call("slice length does not divide exactly into destination elements", null); |
| 52 | 58 | } |
| 53 | 59 | |
| 54 | 60 | pub fn reachedUnreachable() noreturn { |
| 61 | @branchHint(.cold); | |
| 55 | 62 | call("reached unreachable code", null); |
| 56 | 63 | } |
| 57 | 64 | |
| 58 | 65 | pub fn unwrapNull() noreturn { |
| 66 | @branchHint(.cold); | |
| 59 | 67 | call("attempt to use null value", null); |
| 60 | 68 | } |
| 61 | 69 | |
| 62 | 70 | pub fn castToNull() noreturn { |
| 71 | @branchHint(.cold); | |
| 63 | 72 | call("cast causes pointer to be null", null); |
| 64 | 73 | } |
| 65 | 74 | |
| 66 | 75 | pub fn incorrectAlignment() noreturn { |
| 76 | @branchHint(.cold); | |
| 67 | 77 | call("incorrect alignment", null); |
| 68 | 78 | } |
| 69 | 79 | |
| 70 | 80 | pub fn invalidErrorCode() noreturn { |
| 81 | @branchHint(.cold); | |
| 71 | 82 | call("invalid error code", null); |
| 72 | 83 | } |
| 73 | 84 | |
| 85 | pub fn unexpectedErrorCode(err: anyerror) noreturn { | |
| 86 | @branchHint(.cold); | |
| 87 | _ = err; | |
| 88 | call("unexpected error code", null); | |
| 89 | } | |
| 90 | ||
| 74 | 91 | pub fn integerOutOfBounds() noreturn { |
| 92 | @branchHint(.cold); | |
| 75 | 93 | call("integer does not fit in destination type", null); |
| 76 | 94 | } |
| 77 | 95 | |
| 78 | 96 | pub fn integerOverflow() noreturn { |
| 97 | @branchHint(.cold); | |
| 79 | 98 | call("integer overflow", null); |
| 80 | 99 | } |
| 81 | 100 | |
| 82 | 101 | pub fn shlOverflow() noreturn { |
| 102 | @branchHint(.cold); | |
| 83 | 103 | call("left shift overflowed bits", null); |
| 84 | 104 | } |
| 85 | 105 | |
| 86 | 106 | pub fn shrOverflow() noreturn { |
| 107 | @branchHint(.cold); | |
| 87 | 108 | call("right shift overflowed bits", null); |
| 88 | 109 | } |
| 89 | 110 | |
| 90 | 111 | pub fn divideByZero() noreturn { |
| 112 | @branchHint(.cold); | |
| 91 | 113 | call("division by zero", null); |
| 92 | 114 | } |
| 93 | 115 | |
| 94 | 116 | pub fn exactDivisionRemainder() noreturn { |
| 117 | @branchHint(.cold); | |
| 95 | 118 | call("exact division produced remainder", null); |
| 96 | 119 | } |
| 97 | 120 | |
| 98 | 121 | pub fn integerPartOutOfBounds() noreturn { |
| 122 | @branchHint(.cold); | |
| 99 | 123 | call("integer part of floating point value out of bounds", null); |
| 100 | 124 | } |
| 101 | 125 | |
| 102 | 126 | pub fn corruptSwitch() noreturn { |
| 127 | @branchHint(.cold); | |
| 103 | 128 | call("switch on corrupt value", null); |
| 104 | 129 | } |
| 105 | 130 | |
| 106 | 131 | pub fn shiftRhsTooBig() noreturn { |
| 132 | @branchHint(.cold); | |
| 107 | 133 | call("shift amount is greater than the type size", null); |
| 108 | 134 | } |
| 109 | 135 | |
| 110 | 136 | pub fn invalidEnumValue() noreturn { |
| 137 | @branchHint(.cold); | |
| 111 | 138 | call("invalid enum value", null); |
| 112 | 139 | } |
| 113 | 140 | |
| 114 | 141 | pub fn forLenMismatch() noreturn { |
| 142 | @branchHint(.cold); | |
| 115 | 143 | call("for loop over objects with non-equal lengths", null); |
| 116 | 144 | } |
| 117 | 145 | |
| 118 | 146 | pub fn copyLenMismatch() noreturn { |
| 147 | @branchHint(.cold); | |
| 119 | 148 | call("source and destination have non-equal lengths", null); |
| 120 | 149 | } |
| 121 | 150 | |
| 122 | 151 | pub fn memcpyAlias() noreturn { |
| 152 | @branchHint(.cold); | |
| 123 | 153 | call("@memcpy arguments alias", null); |
| 124 | 154 | } |
| 125 | 155 | |
| 126 | 156 | pub fn noreturnReturned() noreturn { |
| 157 | @branchHint(.cold); | |
| 127 | 158 | call("'noreturn' function returned", null); |
| 128 | 159 | } |
| 129 | 160 |
src/Sema.zig+6-4| ... | ... | @@ -21675,16 +21675,16 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData |
| 21675 | 21675 | const is_zero = try block.addBinOp(.cmp_eq, err_int_inst, zero_err); |
| 21676 | 21676 | if (result == .disjoint) { |
| 21677 | 21677 | // Error must be zero. |
| 21678 | try sema.addSafetyCheck(block, src, is_zero, .invalid_error_code); | |
| 21678 | try sema.addSafetyCheckCall(block, src, is_zero, .@"panic.unexpectedErrorCode", &.{err_code_inst}); | |
| 21679 | 21679 | } else { |
| 21680 | 21680 | // Error must be in destination set or zero. |
| 21681 | 21681 | const has_value = try block.addTyOp(.error_set_has_value, dest_err_ty, err_int_inst); |
| 21682 | 21682 | const ok = try block.addBinOp(.bit_or, has_value, is_zero); |
| 21683 | try sema.addSafetyCheck(block, src, ok, .invalid_error_code); | |
| 21683 | try sema.addSafetyCheckCall(block, src, ok, .@"panic.unexpectedErrorCode", &.{err_code_inst}); | |
| 21684 | 21684 | } |
| 21685 | 21685 | } else { |
| 21686 | 21686 | const ok = try block.addTyOp(.error_set_has_value, dest_err_ty, err_int_inst); |
| 21687 | try sema.addSafetyCheck(block, src, ok, .invalid_error_code); | |
| 21687 | try sema.addSafetyCheckCall(block, src, ok, .@"panic.unexpectedErrorCode", &.{err_code_inst}); | |
| 21688 | 21688 | } |
| 21689 | 21689 | } |
| 21690 | 21690 | |
| ... | ... | @@ -35031,7 +35031,9 @@ fn getExpectedBuiltinFnType(sema: *Sema, decl: Zcu.StdLangDecl) CompileError!Typ |
| 35031 | 35031 | }), |
| 35032 | 35032 | |
| 35033 | 35033 | // `fn (anyerror) noreturn` |
| 35034 | .@"panic.unwrapError" => try pt.funcType(.{ | |
| 35034 | .@"panic.unwrapError", | |
| 35035 | .@"panic.unexpectedErrorCode", | |
| 35036 | => try pt.funcType(.{ | |
| 35035 | 35037 | .param_types = &.{.anyerror_type}, |
| 35036 | 35038 | .return_type = .noreturn_type, |
| 35037 | 35039 | }), |
src/Zcu.zig+2| ... | ... | @@ -503,6 +503,7 @@ pub const StdLangDecl = enum { |
| 503 | 503 | @"panic.castToNull", |
| 504 | 504 | @"panic.incorrectAlignment", |
| 505 | 505 | @"panic.invalidErrorCode", |
| 506 | @"panic.unexpectedErrorCode", | |
| 506 | 507 | @"panic.integerOutOfBounds", |
| 507 | 508 | @"panic.integerOverflow", |
| 508 | 509 | @"panic.shlOverflow", |
| ... | ... | @@ -593,6 +594,7 @@ pub const StdLangDecl = enum { |
| 593 | 594 | .@"panic.castToNull", |
| 594 | 595 | .@"panic.incorrectAlignment", |
| 595 | 596 | .@"panic.invalidErrorCode", |
| 597 | .@"panic.unexpectedErrorCode", | |
| 596 | 598 | .@"panic.integerOutOfBounds", |
| 597 | 599 | .@"panic.integerOverflow", |
| 598 | 600 | .@"panic.shlOverflow", |
test/cases/compile_errors/bad_panic_call_signature.zig+1| ... | ... | @@ -15,6 +15,7 @@ pub const panic = struct { |
| 15 | 15 | pub const castToNull = simple_panic.castToNull; |
| 16 | 16 | pub const incorrectAlignment = simple_panic.incorrectAlignment; |
| 17 | 17 | pub const invalidErrorCode = simple_panic.invalidErrorCode; |
| 18 | pub const unexpectedErrorCode = simple_panic.unexpectedErrorCode; | |
| 18 | 19 | pub const integerOutOfBounds = simple_panic.integerOutOfBounds; |
| 19 | 20 | pub const integerOverflow = simple_panic.integerOverflow; |
| 20 | 21 | pub const shlOverflow = simple_panic.shlOverflow; |
test/cases/compile_errors/bad_panic_generic_signature.zig+1| ... | ... | @@ -11,6 +11,7 @@ pub const panic = struct { |
| 11 | 11 | pub const castToNull = simple_panic.castToNull; |
| 12 | 12 | pub const incorrectAlignment = simple_panic.incorrectAlignment; |
| 13 | 13 | pub const invalidErrorCode = simple_panic.invalidErrorCode; |
| 14 | pub const unexpectedErrorCode = simple_panic.unexpectedErrorCode; | |
| 14 | 15 | pub const integerOutOfBounds = simple_panic.integerOutOfBounds; |
| 15 | 16 | pub const integerOverflow = simple_panic.integerOverflow; |
| 16 | 17 | pub const shlOverflow = simple_panic.shlOverflow; |
test/cases/safety/@errorCast error not present in destination.zig	+1-1| ... | ... | @@ -2,7 +2,7 @@ const std = @import("std"); |
| 2 | 2 | |
| 3 | 3 | pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { |
| 4 | 4 | _ = stack_trace; |
| 5 | if (std.mem.eql(u8, message, "invalid error code")) { | |
| 5 | if (std.mem.eql(u8, message, "unexpected error code, found error.B")) { | |
| 6 | 6 | std.process.exit(0); |
| 7 | 7 | } |
| 8 | 8 | std.process.exit(1); |
test/cases/safety/@errorCast error union casted to disjoint set.zig	+1-1| ... | ... | @@ -2,7 +2,7 @@ const std = @import("std"); |
| 2 | 2 | |
| 3 | 3 | pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { |
| 4 | 4 | _ = stack_trace; |
| 5 | if (std.mem.eql(u8, message, "invalid error code")) { | |
| 5 | if (std.mem.eql(u8, message, "unexpected error code, found error.Bar")) { | |
| 6 | 6 | std.process.exit(0); |
| 7 | 7 | } |
| 8 | 8 | std.process.exit(1); |
test/incremental/change_panic_handler_explicit+3| ... | ... | @@ -23,6 +23,7 @@ pub const panic = struct { |
| 23 | 23 | pub const castToNull = no_panic.castToNull; |
| 24 | 24 | pub const incorrectAlignment = no_panic.incorrectAlignment; |
| 25 | 25 | pub const invalidErrorCode = no_panic.invalidErrorCode; |
| 26 | pub const unexpectedErrorCode = no_panic.unexpectedErrorCode; | |
| 26 | 27 | pub const integerOutOfBounds = no_panic.integerOutOfBounds; |
| 27 | 28 | pub const shlOverflow = no_panic.shlOverflow; |
| 28 | 29 | pub const shrOverflow = no_panic.shrOverflow; |
| ... | ... | @@ -72,6 +73,7 @@ pub const panic = struct { |
| 72 | 73 | pub const castToNull = no_panic.castToNull; |
| 73 | 74 | pub const incorrectAlignment = no_panic.incorrectAlignment; |
| 74 | 75 | pub const invalidErrorCode = no_panic.invalidErrorCode; |
| 76 | pub const unexpectedErrorCode = no_panic.unexpectedErrorCode; | |
| 75 | 77 | pub const integerOutOfBounds = no_panic.integerOutOfBounds; |
| 76 | 78 | pub const shlOverflow = no_panic.shlOverflow; |
| 77 | 79 | pub const shrOverflow = no_panic.shrOverflow; |
| ... | ... | @@ -121,6 +123,7 @@ pub const panic = struct { |
| 121 | 123 | pub const castToNull = no_panic.castToNull; |
| 122 | 124 | pub const incorrectAlignment = no_panic.incorrectAlignment; |
| 123 | 125 | pub const invalidErrorCode = no_panic.invalidErrorCode; |
| 126 | pub const unexpectedErrorCode = no_panic.unexpectedErrorCode; | |
| 124 | 127 | pub const integerOutOfBounds = no_panic.integerOutOfBounds; |
| 125 | 128 | pub const shlOverflow = no_panic.shlOverflow; |
| 126 | 129 | pub const shrOverflow = no_panic.shrOverflow; |