@@ -104,25 +104,7 @@ struct PointerOffsetTests {
104
104
#expect( pointer [ offset: firstOffset] == 3 )
105
105
#expect( pointer [ offset: secondOffset] . isApproximatelyEqual ( to: 4.0 ) )
106
106
}
107
- #if !canImport(Darwin) && !DEBUG
108
- // FIXME: The issue only occur on Linux + Release configuration (Swift 5.10)
109
-
110
- // Uncomment the following withKnownIssue code will make the result back to normal thus causing 5 new issues
111
- // withKnownIssue {
112
- // withUnsafePointer(to: tuple) { pointer in
113
- // #expect(pointer[offset: firstOffset] == 3)
114
- // #expect(pointer[offset: secondOffset].isApproximatelyEqual(to: 4.0))
115
- // }
116
- // #expect(tuple.first == 3)
117
- // #expect(tuple.second.isApproximatelyEqual(to: 4.0))
118
- // }
119
- withUnsafePointer ( to: tuple) { pointer in
120
- #expect( pointer [ offset: firstOffset] == 1 )
121
- #expect( pointer [ offset: secondOffset] . isApproximatelyEqual ( to: 2.0 ) )
122
- }
123
- #expect( tuple. first == 1 )
124
- #expect( tuple. second. isApproximatelyEqual ( to: 2.0 ) )
125
- #else
107
+ #if !(!canImport(Darwin) && !DEBUG)
126
108
withUnsafePointer ( to: tuple) { pointer in
127
109
#expect( pointer [ offset: firstOffset] == 3 )
128
110
#expect( pointer [ offset: secondOffset] . isApproximatelyEqual ( to: 4.0 ) )
@@ -163,29 +145,7 @@ struct PointerOffsetTests {
163
145
#expect( ( pointer + secondOffset) . pointee == 4 )
164
146
#expect( ( pointer + thirdOffset) . pointee == 5 )
165
147
}
166
- #if !canImport(Darwin) && !DEBUG
167
- // FIXME: The issue only occur on Linux + Release configuration (Swift 5.10)
168
-
169
- // Uncomment the following withKnownIssue code will make the result back to normal thus causing 7 new issues
170
- // withKnownIssue {
171
- // withUnsafePointer(to: triple) { pointer in
172
- // #expect((pointer + firstOffset).pointee == 3)
173
- // #expect((pointer + secondOffset).pointee == 4)
174
- // #expect((pointer + thirdOffset).pointee == 5)
175
- // }
176
- // #expect(triple.first == 3)
177
- // #expect(triple.second == 4)
178
- // #expect(triple.third == 5)
179
- // }
180
- withUnsafePointer ( to: triple) { pointer in
181
- #expect( ( pointer + firstOffset) . pointee == 0 )
182
- #expect( ( pointer + secondOffset) . pointee == 1 )
183
- #expect( ( pointer + thirdOffset) . pointee == 2 )
184
- }
185
- #expect( triple. first == 0 )
186
- #expect( triple. second == 1 )
187
- #expect( triple. third == 2 )
188
- #else
148
+ #if !(!canImport(Darwin) && !DEBUG)
189
149
withUnsafePointer ( to: triple) { pointer in
190
150
#expect( ( pointer + firstOffset) . pointee == 3 )
191
151
#expect( ( pointer + secondOffset) . pointee == 4 )
@@ -197,4 +157,28 @@ struct PointerOffsetTests {
197
157
#endif
198
158
}
199
159
}
160
+
161
+ #if !canImport(Darwin) && !DEBUG
162
+ @Test ( " Undefined Behavior Issue for PointerOffset " , . bug( " #73 " , relationship: . uncoveredBug) )
163
+ func unsafePointerAndUnsafeMutablePointerExtensionUB( ) {
164
+ var tuple = Tuple ( first: 1 , second: 2 )
165
+ typealias Base = Tuple < Int , Int >
166
+ let firstOffset = PointerOffset < Base , Int > ( byteOffset: 0 )
167
+ withUnsafeMutablePointer ( to: & tuple) { pointer in
168
+ #expect( pointer [ offset: firstOffset] == 1 )
169
+ pointer [ offset: firstOffset] = 3
170
+ }
171
+ let unexpectedValue = tuple. first
172
+ // The value will be unexpected due to UB
173
+ #expect( unexpectedValue == 1 )
174
+ // The value will be expected after and within a withKnownIssue block
175
+ withKnownIssue {
176
+ let expectedValue = tuple. first
177
+ #expect( expectedValue == 3 )
178
+ Issue . record ( " To make withKnownIssue pass " )
179
+ }
180
+ let expectedValue = tuple. first
181
+ #expect( expectedValue == 3 )
182
+ }
183
+ #endif
200
184
}
0 commit comments