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}
27862786
27872787 @_transparent
27882788 public static func %= ( _ lhs: inout ${ Self} , _ rhs: ${ Self} ) {
2789+ // No LLVM primitives for checking overflow of division
2790+ // operations, so we check manually.
27892791 if _slowPath ( rhs == ( 0 as ${ Self} ) ) {
27902792 _preconditionFailure ( " Remainder of division by zero " )
27912793 }
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
27922801
27932802 let ( newStorage, _) = (
27942803 Builtin . ${ u} rem_Int${ bits} ( lhs. _value, rhs. _value) ,
Original file line number Diff line number Diff line change 1414// RUN: %target-build-swift -swift-version 4 -o %t/a.out %s
1515// RUN: %target-run %t/a.out
1616// REQUIRES: executable_test
17+ // REQUIRES: CPU=x86_64
1718
1819import StdlibUnittest
1920import Darwin
You can’t perform that action at this time.
0 commit comments