Skip to content

Commit 4720fcf

Browse files
authored
Add uncoveredBug test case for #73 (#75)
1 parent 48ad532 commit 4720fcf

File tree

1 file changed

+26
-42
lines changed

1 file changed

+26
-42
lines changed

Tests/OpenGraphCompatibilityTests/Attribute/Attribute/PointerOffsetTests.swift

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,7 @@ struct PointerOffsetTests {
104104
#expect(pointer[offset: firstOffset] == 3)
105105
#expect(pointer[offset: secondOffset].isApproximatelyEqual(to: 4.0))
106106
}
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)
126108
withUnsafePointer(to: tuple) { pointer in
127109
#expect(pointer[offset: firstOffset] == 3)
128110
#expect(pointer[offset: secondOffset].isApproximatelyEqual(to: 4.0))
@@ -163,29 +145,7 @@ struct PointerOffsetTests {
163145
#expect((pointer + secondOffset).pointee == 4)
164146
#expect((pointer + thirdOffset).pointee == 5)
165147
}
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)
189149
withUnsafePointer(to: triple) { pointer in
190150
#expect((pointer + firstOffset).pointee == 3)
191151
#expect((pointer + secondOffset).pointee == 4)
@@ -197,4 +157,28 @@ struct PointerOffsetTests {
197157
#endif
198158
}
199159
}
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
200184
}

0 commit comments

Comments
 (0)