File tree Expand file tree Collapse file tree 2 files changed +35
-13
lines changed Expand file tree Collapse file tree 2 files changed +35
-13
lines changed Original file line number Diff line number Diff line change @@ -3160,20 +3160,25 @@ extension FixedWidthInteger {
3160
3160
self = Self ( _truncatingBits: source. _lowWord)
3161
3161
}
3162
3162
else {
3163
- let neg = source < ( 0 as T )
3164
- var result : Self = neg ? ~ 0 : 0
3165
- var shift : Self = 0
3166
- let width = Self ( _truncatingBits: Self . bitWidth. _lowWord)
3167
- for word in source. words {
3168
- guard shift < width else { break }
3169
- // Masking shift is OK here because we have already ensured
3170
- // that shift < Self.bitWidth. Not masking results in
3171
- // infinite recursion.
3172
- result ^= Self ( _truncatingBits: neg ? ~ word : word) &<< shift
3173
- shift += Self ( _truncatingBits: Int . bitWidth. _lowWord)
3174
- }
3175
- self = result
3163
+ self = Self . _truncatingInit ( source)
3164
+ }
3165
+ }
3166
+
3167
+ @_alwaysEmitIntoClient
3168
+ internal static func _truncatingInit< T: BinaryInteger > ( _ source: T ) -> Self {
3169
+ let neg = source < ( 0 as T )
3170
+ var result : Self = neg ? ~ 0 : 0
3171
+ var shift : Self = 0
3172
+ let width = Self ( _truncatingBits: Self . bitWidth. _lowWord)
3173
+ for word in source. words {
3174
+ guard shift < width else { break }
3175
+ // Masking shift is OK here because we have already ensured
3176
+ // that shift < Self.bitWidth. Not masking results in
3177
+ // infinite recursion.
3178
+ result ^= Self ( _truncatingBits: neg ? ~ word : word) &<< shift
3179
+ shift += Self ( _truncatingBits: Int . bitWidth. _lowWord)
3176
3180
}
3181
+ return result
3177
3182
}
3178
3183
3179
3184
@_transparent
Original file line number Diff line number Diff line change
1
+ // RUN: %target-swift-frontend -O -parse-as-library -emit-sil -enable-ossa-modules %s | %FileCheck %s
2
+ // REQUIRES: PTRSIZE=32,swift_stdlib_asserts
3
+
4
+ import Swift
5
+
6
+ // CHECK-LABEL: sil [noinline] @$s14jumpthreadtest3fooys6UInt64Vs5UInt8VF :
7
+ // CHECK: bb0
8
+ // CHECK: [[FUNC:%.*]] = function_ref @$ss17FixedWidthIntegerPsE15_truncatingInityxqd__SzRd__lFZs6UInt64V_s5UInt8VTgq5Tf4nd_n :
9
+ // CHECK: apply [[FUNC]]
10
+ // CHECK-NOT: bb1
11
+ // CHECK-LABEL: } // end sil function '$s14jumpthreadtest3fooys6UInt64Vs5UInt8VF'
12
+ @inlinable
13
+ @inline ( never)
14
+ public func foo( _ p: UInt8 ) -> UInt64 {
15
+ let q = UInt64 ( truncatingIfNeeded: p)
16
+ return q
17
+ }
You can’t perform that action at this time.
0 commit comments