Skip to content

Consistently add #error when compiling on unsupported architectures. #2450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Foundation/CGFloat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public struct CGFloat {
/// The native type used to store the CGFloat, which is Float on
/// 32-bit architectures and Double on 64-bit architectures.
public typealias NativeType = Double
#else
#error("This architecture isn't known. Add it to the 32-bit or 64-bit line.")
#endif

@_transparent public init() {
Expand Down Expand Up @@ -187,6 +189,8 @@ extension CGFloat : BinaryFloatingPoint {
native = NativeType(bitPattern: UInt32(bitPattern))
#elseif arch(x86_64) || arch(arm64) || arch(s390x) || arch(powerpc64) || arch(powerpc64le)
native = NativeType(bitPattern: UInt64(bitPattern))
#else
#error("This architecture isn't known. Add it to the 32-bit or 64-bit line.")
#endif
}

Expand Down
6 changes: 6 additions & 0 deletions Foundation/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,8 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
@usableFromInline typealias Buffer = (UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8) //len //enum
@usableFromInline var bytes: Buffer
#else
#error("This architecture isn't known. Add it to the 32-bit or 64-bit line.")
#endif
@usableFromInline var length: UInt8

Expand All @@ -686,6 +688,8 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
bytes = (UInt8(0), UInt8(0), UInt8(0), UInt8(0), UInt8(0), UInt8(0), UInt8(0), UInt8(0), UInt8(0), UInt8(0), UInt8(0), UInt8(0), UInt8(0), UInt8(0))
#elseif arch(i386) || arch(arm)
bytes = (UInt8(0), UInt8(0), UInt8(0), UInt8(0), UInt8(0), UInt8(0))
#else
#error("This architecture isn't known. Add it to the 32-bit or 64-bit line.")
#endif
length = UInt8(count)
}
Expand Down Expand Up @@ -867,6 +871,8 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
@usableFromInline internal typealias HalfInt = Int32
#elseif arch(i386) || arch(arm)
@usableFromInline internal typealias HalfInt = Int16
#else
#error("This architecture isn't known. Add it to the 32-bit or 64-bit line.")
#endif

// A buffer of bytes too large to fit in an InlineData, but still small enough to fit a storage pointer + range in two words.
Expand Down
4 changes: 4 additions & 0 deletions Foundation/NSNumber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,8 @@ open class NSNumber : NSValue {
self.init(bytes: &value, numberType: kCFNumberSInt64Type)
#elseif arch(i386) || arch(arm)
self.init(bytes: &value, numberType: kCFNumberSInt32Type)
#else
#error("This architecture isn't known. Add it to the 32-bit or 64-bit line.")
#endif
}

Expand All @@ -733,6 +735,8 @@ open class NSNumber : NSValue {
#elseif arch(i386) || arch(arm)
var value = Int64(value)
self.init(bytes: &value, numberType: kCFNumberSInt64Type)
#else
#error("This architecture isn't known. Add it to the 32-bit or 64-bit line.")
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion Foundation/NSRange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ extension NSRange: NSSpecialValueCoding {
#elseif arch(x86_64) || arch(arm64) || arch(s390x) || arch(powerpc64) || arch(powerpc64le)
return "{_NSRange=QQ}"
#else
NSUnimplemented()
#error("This architecture isn't known. Add it to the 32-bit or 64-bit line.")
#endif
}

Expand Down
2 changes: 2 additions & 0 deletions TestFoundation/TestNSNumber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,8 @@ class TestNSNumber : XCTestCase {
XCTAssertEqual("i" /* 0x71 */, objCType(NSNumber(value: Int.max)))
XCTAssertEqual("q" /* 0x71 */, objCType(NSNumber(value: UInt(Int.max))))
XCTAssertEqual("q" /* 0x51 */, objCType(NSNumber(value: UInt(Int.max) + 1)))
#else
#error("This architecture isn't known. Add it to the 32-bit or 64-bit line.")
#endif

XCTAssertEqual("f" /* 0x66 */, objCType(NSNumber(value: Float.greatestFiniteMagnitude)))
Expand Down