| ... | @@ -1073,6 +1073,35 @@ test "@mulWithOverflow bitsize > 32" { | ... | @@ -1073,6 +1073,35 @@ test "@mulWithOverflow bitsize > 32" { |
| 1073 | try testMulWithOverflow(i63, minInt(i63), minInt(i63), 0, 1); | 1073 | try testMulWithOverflow(i63, minInt(i63), minInt(i63), 0, 1); |
| 1074 | } | 1074 | } |
| 1075 | | 1075 | |
| | 1076 | fn captureMultiply(comptime T: type) type { |
| | 1077 | return struct { |
| | 1078 | opA: T, |
| | 1079 | |
| | 1080 | fn returnA(self: @This()) anyerror!T { |
| | 1081 | return self.opA; |
| | 1082 | } |
| | 1083 | |
| | 1084 | fn testMutiplyWithOverflow(self: @This(), comptime b: T, expected: T) !void { |
| | 1085 | const a = try self.returnA(); |
| | 1086 | |
| | 1087 | const c = a * b; |
| | 1088 | try expectEqual(expected, c); |
| | 1089 | } |
| | 1090 | }; |
| | 1091 | } |
| | 1092 | |
| | 1093 | test "Multiply unwrap error * immediate" { |
| | 1094 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| | 1095 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| | 1096 | if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; |
| | 1097 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; |
| | 1098 | |
| | 1099 | try (captureMultiply(i8){ .opA = 3 }).testMutiplyWithOverflow(-1, -3); |
| | 1100 | try (captureMultiply(i16){ .opA = 3 }).testMutiplyWithOverflow(-1, -3); |
| | 1101 | try (captureMultiply(i32){ .opA = 3 }).testMutiplyWithOverflow(-1, -3); |
| | 1102 | try (captureMultiply(i64){ .opA = 3 }).testMutiplyWithOverflow(-1, -3); |
| | 1103 | } |
| | 1104 | |
| 1076 | test "@mulWithOverflow bitsize 128 bits" { | 1105 | test "@mulWithOverflow bitsize 128 bits" { |
| 1077 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | 1106 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| 1078 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | 1107 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; |