File tree Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -2786,9 +2786,18 @@ public struct ${Self}
2786
2786
2787
2787
@_transparent
2788
2788
public static func %= ( _ lhs: inout ${ Self} , _ rhs: ${ Self} ) {
2789
+ // No LLVM primitives for checking overflow of division
2790
+ // operations, so we check manually.
2789
2791
if _slowPath ( rhs == ( 0 as ${ Self} ) ) {
2790
2792
_preconditionFailure ( " Remainder of division by zero " )
2791
2793
}
2794
+ % if signed:
2795
+ if _slowPath (
2796
+ ${ 'lhs == % s . min && rhs == ( - 1 as % s) ' % ( Self, Self) }
2797
+ ) {
2798
+ _preconditionFailure ( " Overflow in remainder of division " )
2799
+ }
2800
+ % end
2792
2801
2793
2802
let ( newStorage, _) = (
2794
2803
Builtin . ${ u} rem_Int${ bits} ( lhs. _value, rhs. _value) ,
Original file line number Diff line number Diff line change 14
14
// RUN: %target-build-swift -swift-version 4 -o %t/a.out %s
15
15
// RUN: %target-run %t/a.out
16
16
// REQUIRES: executable_test
17
+ // REQUIRES: CPU=x86_64
17
18
18
19
import StdlibUnittest
19
20
import Darwin
You can’t perform that action at this time.
0 commit comments