Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,50 @@ struct PointerOffsetTests {
typealias Base = Tuple<Int, Double>
let firstOffset = PointerOffset<Base, Int>(byteOffset: 0)
let secondOffset = PointerOffset<Base, Double>(byteOffset: 8)
withUnsafePointer(to: tuple) { pointer in
#expect(pointer[offset: firstOffset] == 1)
#expect(pointer[offset: secondOffset].isApproximatelyEqual(to: 2.0))
}
withUnsafeMutablePointer(to: &tuple) { pointer in
#expect(pointer[offset: firstOffset] == 1)
#expect(pointer[offset: secondOffset] == 2.0)
#expect(pointer[offset: secondOffset].isApproximatelyEqual(to: 2.0))

pointer[offset: firstOffset] = 3
pointer[offset: secondOffset] = 4.0

#expect(pointer[offset: firstOffset] == 3)
#expect(pointer[offset: secondOffset].isApproximatelyEqual(to: 4.0))
}
withUnsafePointer(to: &tuple) { pointer in
#expect(pointer[offset: firstOffset] == 3)
#expect(pointer[offset: secondOffset].isApproximatelyEqual(to: 4.0))
}
#if !canImport(Darwin) && !DEBUG
// FIXME: The issue only occur on Linux + Release configuration (Swift 5.10)

// Uncomment the following withKnownIssue code will make the result back to normal thus causing 5 new issues
// withKnownIssue {
// withUnsafePointer(to: tuple) { pointer in
// #expect(pointer[offset: firstOffset] == 3)
// #expect(pointer[offset: secondOffset].isApproximatelyEqual(to: 4.0))
// }
// #expect(tuple.first == 3)
// #expect(tuple.second.isApproximatelyEqual(to: 4.0))
// }
withUnsafePointer(to: tuple) { pointer in
#expect(pointer[offset: firstOffset] == 1)
#expect(pointer[offset: secondOffset].isApproximatelyEqual(to: 2.0))
}
#expect(tuple.first == 1)
#expect(tuple.second.isApproximatelyEqual(to: 2.0))
#else
withUnsafePointer(to: tuple) { pointer in
#expect(pointer[offset: firstOffset] == 3)
#expect(pointer[offset: secondOffset].isApproximatelyEqual(to: 4.0))
}
#expect(tuple.first == 3)
#expect(tuple.second.isApproximatelyEqual(to: 4.0))
#endif
}

do {
Expand All @@ -106,6 +139,12 @@ struct PointerOffsetTests {
let firstOffset = PointerOffset<Base, Int>.offset { .of(&$0.first) }
let secondOffset = PointerOffset<Base, Int>.offset { .of(&$0.second) }
let thirdOffset = PointerOffset<Base, Int>.offset { .of(&$0.third) }

withUnsafePointer(to: triple) { pointer in
#expect((pointer + firstOffset).pointee == 0)
#expect((pointer + secondOffset).pointee == 1)
#expect((pointer + thirdOffset).pointee == 2)
}
withUnsafeMutablePointer(to: &triple) { pointer in
#expect((pointer + firstOffset).pointee == 0)
#expect((pointer + secondOffset).pointee == 1)
Expand All @@ -114,12 +153,48 @@ struct PointerOffsetTests {
(pointer + firstOffset).pointee = 3
(pointer + secondOffset).pointee = 4
(pointer + thirdOffset).pointee = 5

#expect((pointer + firstOffset).pointee == 3)
#expect((pointer + secondOffset).pointee == 4)
#expect((pointer + thirdOffset).pointee == 5)
}
withUnsafePointer(to: &triple) { pointer in
#expect((pointer + firstOffset).pointee == 3)
#expect((pointer + secondOffset).pointee == 4)
#expect((pointer + thirdOffset).pointee == 5)
}
#if !canImport(Darwin) && !DEBUG
// FIXME: The issue only occur on Linux + Release configuration (Swift 5.10)

// Uncomment the following withKnownIssue code will make the result back to normal thus causing 7 new issues
// withKnownIssue {
// withUnsafePointer(to: triple) { pointer in
// #expect((pointer + firstOffset).pointee == 3)
// #expect((pointer + secondOffset).pointee == 4)
// #expect((pointer + thirdOffset).pointee == 5)
// }
// #expect(triple.first == 3)
// #expect(triple.second == 4)
// #expect(triple.third == 5)
// }
withUnsafePointer(to: triple) { pointer in
#expect((pointer + firstOffset).pointee == 0)
#expect((pointer + secondOffset).pointee == 1)
#expect((pointer + thirdOffset).pointee == 2)
}
#expect(triple.first == 0)
#expect(triple.second == 1)
#expect(triple.third == 2)
#else
withUnsafePointer(to: triple) { pointer in
#expect((pointer + firstOffset).pointee == 3)
#expect((pointer + secondOffset).pointee == 4)
#expect((pointer + thirdOffset).pointee == 5)
}
#expect(triple.first == 3)
#expect(triple.second == 4)
#expect(triple.third == 5)
#endif
}
}
}