File: IntegerCompatibility.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (66 lines) | stat: -rw-r--r-- 1,883 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// RUN: %target-build-swift %s -swift-version 4 -typecheck


func byteswap_n(_ a: UInt64) -> UInt64 {
  return ((a & 0x00000000000000FF) &<< 56) |
         ((a & 0x000000000000FF00) &<< 40) |
         ((a & 0x0000000000FF0000) &<< 24) |
         ((a & 0x00000000FF000000) &<<  8) |
         ((a & 0x000000FF00000000) &>>  8) |
         ((a & 0x0000FF0000000000) &>> 24) |
         ((a & 0x00FF000000000000) &>> 40) |
         ((a & 0xFF00000000000000) &>> 56)
}


// expression should not be too complex
func radar31845712(_ i: Int, _ buffer: [UInt8]) {
  _ =  UInt64(buffer[i])
    | (UInt64(buffer[i + 1]) &<< 8)
    | (UInt64(buffer[i + 2]) &<< 16)
    | (UInt64(buffer[i + 3]) &<< 24)
    | (UInt64(buffer[i + 4]) &<< 32)
    | (UInt64(buffer[i + 5]) &<< 40)
    | (UInt64(buffer[i + 6]) &<< 48)
    | (UInt64(buffer[i + 7]) &<< 56)
}

// expression should not be too complex
func radar32149641() {
  func from(bigEndian input: UInt32) -> UInt32 {
    var val: UInt32 = input
    return withUnsafePointer(to: &val) { (ptr: UnsafePointer<UInt32>) -> UInt32 in
      return ptr.withMemoryRebound(to: UInt8.self, capacity: 4) { data in
        return (UInt32(data[3]) &<< 0) |
               (UInt32(data[2]) &<< 8) |
               (UInt32(data[1]) &<< 16) |
               (UInt32(data[0]) &<< 24)
      }
    }
  }
}

func homogeneousLookingShiftAndAMask(_ i64: Int64) {
  _ = (i64 >> 8) & 0xFF
}

func negativeShift(_ u8: UInt8) {
  _ = (u8 << -1)
}

// https://github.com/apple/swift/issues/47752
// Ambiguous 'Int32.init(bitPattern:)'
do {
  _ = Int32(bitPattern: 0) // should compile without ambiguity
}

// https://github.com/apple/swift/issues/49183
func f_49183(x: UnsafeBufferPointer<UInt8>) -> Int {
  return x.lazy.filter { $0 > 127 || $0 == 0 }.count // should be unambiguous
}

// abs of an integer literal
func returnIntAbs() -> Int {
  let x = abs(-8)
  return x
}