Skip to content

Commit 92c20a6

Browse files
committed
[embedded] Avoid unsafeBitCast, use Builtin.castFromNativeObject instead, add armv7 test
1 parent 7ae20b7 commit 92c20a6

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

stdlib/public/core/StringObject.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ extension _StringObject {
983983
#if !$Embedded
984984
return _unsafeUncheckedDowncast(storage, to: __StringStorage.self)
985985
#else
986-
return unsafeBitCast(_nativeObject(toNative: storage), to: __StringStorage.self)
986+
return Builtin.castFromNativeObject(storage)
987987
#endif
988988
#else
989989
#error("Unknown platform")
@@ -1022,7 +1022,7 @@ extension _StringObject {
10221022
#if !$Embedded
10231023
return _unsafeUncheckedDowncast(storage, to: __SharedStringStorage.self)
10241024
#else
1025-
return unsafeBitCast(_nativeObject(toNative: storage), to: __SharedStringStorage.self)
1025+
return Builtin.castFromNativeObject(storage)
10261026
#endif
10271027
#else
10281028
#error("Unknown platform")
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %target-swift-frontend -target armv7-apple-none-macho -module-name main -parse-as-library -Xcc -D__MACH__ -emit-ir %s -enable-experimental-feature Embedded
2+
// RUN: %target-swift-frontend -target armv7-apple-none-macho -module-name main -parse-as-library -Xcc -D__MACH__ -emit-ir %s -enable-experimental-feature Embedded -O
3+
// RUN: %target-swift-frontend -target armv7-apple-none-macho -module-name main -parse-as-library -Xcc -D__MACH__ -emit-ir %s -enable-experimental-feature Embedded -Osize
4+
5+
// REQUIRES: swift_in_compiler
6+
// REQUIRES: OS=macosx || OS=linux-gnu
7+
// REQUIRES: CODEGENERATOR=ARM
8+
9+
@main
10+
struct Main {
11+
static func main() {
12+
let n = 42
13+
let m = -42
14+
let s = "str"
15+
let str = "Hello \(s) \(n) \(s) \(m)"
16+
print(str)
17+
18+
print("hex: \(hex: 42)")
19+
print("ptr: \(UnsafeRawPointer(bitPattern: UInt(0xffff0000))!)")
20+
}
21+
}
22+
23+
extension DefaultStringInterpolation {
24+
mutating func appendInterpolation(hex value: Int) {
25+
appendInterpolation("0x" + String(value, radix: 16))
26+
}
27+
28+
mutating func appendInterpolation(_ value: UnsafeRawPointer) {
29+
appendInterpolation("0x" + String(UInt(bitPattern: value), radix: 16))
30+
}
31+
}

0 commit comments

Comments
 (0)