Skip to content

Commit 6a58b89

Browse files
committed
[lldb] Use binary literals for String discriminator checks (NFC) (#5602)
Replace hex literals with binary literals to improve bit masking readability. Follow up to #5559. (cherry picked from commit c842163)
1 parent 5c1735f commit 6a58b89

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lldb/source/Plugins/Language/Swift/SwiftFormatters.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ static bool makeStringGutsSummary(
302302

303303
uint8_t discriminator = raw1 >> 56;
304304

305-
if ((discriminator & 0xB0) == 0xA0) { // 1x10xxxx: Small string
306-
uint64_t count = (raw1 >> 56) & 0x0F;
305+
if ((discriminator & 0b1011'0000) == 0b1010'0000) { // 1x10xxxx: Small string
306+
uint64_t count = (raw1 >> 56) & 0b1111;
307307
uint64_t maxCount = (ptrSize == 8 ? 15 : 10);
308308
if (count > maxCount)
309309
return false;
@@ -328,7 +328,7 @@ static bool makeStringGutsSummary(
328328
lldb::addr_t objectAddress = (raw1 & 0x0FFFFFFFFFFFFFFF);
329329
if ((flags & 0x1000) != 0) { // Tail-allocated / biased address
330330
// Tail-allocation is only for natively stored or literals.
331-
if ((discriminator & 0x70) != 0)
331+
if ((discriminator & 0b0111'0000) != 0)
332332
return false;
333333
uint64_t bias = (ptrSize == 8 ? 32 : 20);
334334
auto address = objectAddress + bias;
@@ -337,7 +337,7 @@ static bool makeStringGutsSummary(
337337
address, count, valobj, stream, summary_options, read_options);
338338
}
339339

340-
if ((discriminator & 0xF0) == 0x00) { // Shared string
340+
if ((discriminator & 0b1111'0000) == 0) { // Shared string
341341
// FIXME: Verify that there is a __SharedStringStorage instance at `address`.
342342
// Shared strings must not be tail-allocated or natively stored.
343343
if ((flags & 0x3000) != 0)
@@ -354,10 +354,10 @@ static bool makeStringGutsSummary(
354354
}
355355

356356
// Native/shared strings should already have been handled.
357-
if ((discriminator & 0x70) == 0)
357+
if ((discriminator & 0b0111'0000) == 0)
358358
return false;
359359

360-
if ((discriminator & 0xE0) == 0x40) { // 010xxxxx: Bridged
360+
if ((discriminator & 0b1110'0000) == 0b0100'0000) { // 010xxxxx: Bridged
361361
TypeSystemClangSP clang_ts_sp =
362362
ScratchTypeSystemClang::GetForTarget(process->GetTarget());
363363
if (!clang_ts_sp)
@@ -376,7 +376,7 @@ static bool makeStringGutsSummary(
376376
return NSStringSummaryProvider(*nsstring.get(), stream, summary_options);
377377
}
378378

379-
if ((discriminator & 0xF8) == 0x18) { // 0001xxxx: Foreign
379+
if ((discriminator & 0b1111'1000) == 0b0001'1000) { // 0001xxxx: Foreign
380380
// Not currently generated: Foreign non-bridged strings are not currently
381381
// used in Swift.
382382
return false;

0 commit comments

Comments
 (0)