@@ -39,12 +39,9 @@ public struct StaticString
39
39
CustomDebugStringConvertible ,
40
40
CustomReflectable {
41
41
42
- // FIXME(ABI): RawPointer is non-nullable, but we can store a null Unicode
43
- // scalar in it. Change it to an integer.
44
- //
45
- /// Either a pointer to the start of UTF-8 data, or an integer representation
46
- /// of a single Unicode scalar.
47
- internal var _startPtrOrData : Builtin . RawPointer
42
+ /// Either a pointer to the start of UTF-8 data, represented as an integer,
43
+ /// or an integer representation of a single Unicode scalar.
44
+ internal var _startPtrOrData : Builtin . Word
48
45
49
46
/// If `_startPtrOrData` is a pointer, contains the length of the UTF-8 data
50
47
/// in bytes.
@@ -68,7 +65,7 @@ public struct StaticString
68
65
_precondition (
69
66
hasPointerRepresentation,
70
67
" StaticString should have pointer representation " )
71
- return UnsafePointer ( _startPtrOrData)
68
+ return UnsafePointer ( bitPattern : UInt ( _startPtrOrData) ) !
72
69
}
73
70
74
71
/// The stored Unicode scalar value.
@@ -79,9 +76,7 @@ public struct StaticString
79
76
_precondition (
80
77
!hasPointerRepresentation,
81
78
" StaticString should have Unicode scalar representation " )
82
- return UnicodeScalar (
83
- UInt32 ( UInt ( bitPattern: UnsafePointer < Builtin . RawPointer > ( _startPtrOrData) ) )
84
- )
79
+ return UnicodeScalar ( UInt32 ( UInt ( _startPtrOrData) ) )
85
80
}
86
81
87
82
/// If `self` stores a pointer to ASCII or UTF-8 code units, the
@@ -148,7 +143,10 @@ public struct StaticString
148
143
utf8CodeUnitCount: Builtin . Word ,
149
144
isASCII: Builtin . Int1
150
145
) {
151
- self . _startPtrOrData = _start
146
+ // We don't go through UnsafePointer here to make things simpler for alias
147
+ // analysis. A higher-level algorithm may be trying to make sure an
148
+ // unrelated buffer is not accessed or freed.
149
+ self . _startPtrOrData = Builtin . ptrtoint_Word ( _start)
152
150
self . _utf8CodeUnitCount = utf8CodeUnitCount
153
151
self . _flags = Bool ( isASCII) ? ( 0x2 as UInt8 ) . _value : ( 0x0 as UInt8 ) . _value
154
152
}
@@ -158,11 +156,7 @@ public struct StaticString
158
156
internal init (
159
157
unicodeScalar: Builtin . Int32
160
158
) {
161
- self . _startPtrOrData =
162
- unsafeBitCast (
163
- UInt ( UInt32 ( unicodeScalar) ) ,
164
- to: OpaquePointer . self
165
- ) . _rawValue
159
+ self . _startPtrOrData = UInt ( UInt32 ( unicodeScalar) ) . _builtinWordValue
166
160
self . _utf8CodeUnitCount = 0 . _builtinWordValue
167
161
self . _flags = UnicodeScalar ( _builtinUnicodeScalarLiteral: unicodeScalar) . isASCII
168
162
? ( 0x3 as UInt8 ) . _value
0 commit comments