From 86b8a0890c6179afd6300c47851c7ac0f8101ccf Mon Sep 17 00:00:00 2001 From: Mathias Quintero Date: Mon, 8 Feb 2021 00:40:42 +0100 Subject: [PATCH] Fixing negative remainder offset --- Sources/Syntax/Implementations/Structure/TupleParser.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/Syntax/Implementations/Structure/TupleParser.swift b/Sources/Syntax/Implementations/Structure/TupleParser.swift index a43b4ae..b3a4251 100644 --- a/Sources/Syntax/Implementations/Structure/TupleParser.swift +++ b/Sources/Syntax/Implementations/Structure/TupleParser.swift @@ -72,7 +72,11 @@ private protocol ValuePopper { } extension ValuePopper { static func pop(from scanner: Scanner, into pointer: UnsafeMutableRawPointer, followedBy next: T) throws where T.Element == Any.Type { - let byteOffsetNeeded = (MemoryLayout.alignment - Int(UInt(bitPattern: pointer))) % MemoryLayout.alignment + var byteOffsetNeeded = (MemoryLayout.alignment - Int(UInt(bitPattern: pointer))) % MemoryLayout.alignment + if byteOffsetNeeded < 0 { + byteOffsetNeeded += MemoryLayout.alignment + } + let pointer = pointer.advanced(by: byteOffsetNeeded) if let nextType = next.first {