Skip to content

Commit bf7f423

Browse files
committed
Fix ULEB encoding
1 parent 0185d06 commit bf7f423

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/Macros/Sources/SwiftMacros/DebugDescriptionMacro.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,17 @@ private func encodeString(_ string: String) -> [UInt8] {
265265
}
266266

267267
private func encodeULEB(_ value: UInt) -> [UInt8] {
268+
guard value > 0 else {
269+
return [0]
270+
}
271+
268272
var bytes: [UInt8] = []
269273
var buffer = value
270274
while buffer > 0 {
271275
var byte = UInt8(buffer & 0b01111111)
272276
buffer >>= 7
273277
if buffer > 0 {
274-
byte &= 0b1000000
278+
byte |= 0b10000000
275279
}
276280
bytes.append(byte)
277281
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// REQUIRES: swift_swift_parser
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -typecheck -enable-experimental-feature SymbolLinkageMarkers -plugin-path %swift-plugin-dir -dump-macro-expansions > %t/expansions-dump.txt 2>&1
5+
// RUN: %FileCheck %s < %t/expansions-dump.txt
6+
7+
@attached(peer, names: suffixed(_lldb_summary))
8+
public macro _DebugDescription() =
9+
#externalMacro(module: "SwiftMacros", type: "DebugDescriptionMacro")
10+
11+
@_DebugDescription
12+
struct MyStruct: CustomDebugStringConvertible {
13+
var debugDescription: String {
14+
"""
15+
A string longer than one hundred and twenty eight characters, for the purpose of
16+
testing Unsigned Little Endian encoding (ULEB). Values less than or equal to 127 are
17+
represented as a single byte, with a bit representation identical to an unsigned
18+
8-bit integer. See https://en.wikipedia.org/wiki/LEB128
19+
"""
20+
}
21+
}
22+
// CHECK: let MyStruct_lldb_summary = (
23+
// CHECK: /* version */ 1 as UInt8,
24+
// CHECK: /* record size */ 192 as UInt8, 2 as UInt8,
25+
// CHECK: 8-bit integer. See https://en.wikipedia.org/wiki/LEB128" */ 175 as UInt8, 2 as UInt8, 65 as UInt8,

0 commit comments

Comments
 (0)