Skip to content

Commit 77944e6

Browse files
committed
[RemoteInspection] Change "return false" to "return {}".
There are a number of instances in `ReflectionContext.h` where we are doing `return false` with an `std::optional<...>` where it seems we really mean to return an empty optional instead. (The way to do this is either `return {}` or `return std::nullopt`.) rdar://123504095
1 parent c7a0840 commit 77944e6

File tree

1 file changed

+29
-39
lines changed

1 file changed

+29
-39
lines changed

include/swift/RemoteInspection/ReflectionContext.h

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class ReflectionContext
242242
auto Buf =
243243
this->getReader().readBytes(ImageStart, sizeof(typename T::Header));
244244
if (!Buf)
245-
return false;
245+
return {};
246246
auto Header = reinterpret_cast<typename T::Header *>(Buf.get());
247247
assert(Header->magic == T::MagicNumber && "invalid MachO file");
248248

@@ -262,7 +262,7 @@ class ReflectionContext
262262
RemoteAddress(CmdStartAddress.getAddressData() + Offset),
263263
SegmentCmdHdrSize);
264264
if (!CmdBuf)
265-
return false;
265+
return {};
266266
auto CmdHdr = reinterpret_cast<typename T::SegmentCmd *>(CmdBuf.get());
267267
if (strncmp(CmdHdr->segname, "__TEXT", sizeof(CmdHdr->segname)) == 0) {
268268
TextCommand = CmdHdr;
@@ -274,7 +274,7 @@ class ReflectionContext
274274

275275
// No __TEXT segment, bail out.
276276
if (!TextCommand)
277-
return false;
277+
return {};
278278

279279
// Find the load command offset.
280280
auto loadCmdOffset = ImageStart.getAddressData() + Offset + sizeof(typename T::Header);
@@ -284,7 +284,7 @@ class ReflectionContext
284284
auto LoadCmdBuf = this->getReader().readBytes(
285285
RemoteAddress(LoadCmdAddress), sizeof(typename T::SegmentCmd));
286286
if (!LoadCmdBuf)
287-
return false;
287+
return {};
288288
auto LoadCmd = reinterpret_cast<typename T::SegmentCmd *>(LoadCmdBuf.get());
289289

290290
// The sections start immediately after the load command.
@@ -294,7 +294,7 @@ class ReflectionContext
294294
auto Sections = this->getReader().readBytes(
295295
RemoteAddress(SectAddress), NumSect * sizeof(typename T::Section));
296296
if (!Sections)
297-
return false;
297+
return {};
298298

299299
auto Slide = ImageStart.getAddressData() - TextCommand->vmaddr;
300300
auto SectionsBuf = reinterpret_cast<const char *>(Sections.get());
@@ -346,7 +346,7 @@ class ReflectionContext
346346
ReflStrMdSec.first == nullptr &&
347347
ConformMdSec.first == nullptr &&
348348
MPEnumMdSec.first == nullptr)
349-
return false;
349+
return {};
350350

351351
ReflectionInfo info = {{FieldMdSec.first, FieldMdSec.second},
352352
{AssocTySec.first, AssocTySec.second},
@@ -371,7 +371,7 @@ class ReflectionContext
371371
RemoteAddress(CmdStartAddress.getAddressData() + Offset),
372372
SegmentCmdHdrSize);
373373
if (!CmdBuf)
374-
return false;
374+
return {};
375375
auto CmdHdr = reinterpret_cast<typename T::SegmentCmd *>(CmdBuf.get());
376376
// Look for any segment name starting with __DATA or __AUTH.
377377
if (strncmp(CmdHdr->segname, "__DATA", 6) == 0 ||
@@ -398,7 +398,7 @@ class ReflectionContext
398398
auto DOSHdrBuf = this->getReader().readBytes(
399399
ImageStart, sizeof(llvm::object::dos_header));
400400
if (!DOSHdrBuf)
401-
return false;
401+
return {};
402402
auto DOSHdr =
403403
reinterpret_cast<const llvm::object::dos_header *>(DOSHdrBuf.get());
404404
auto COFFFileHdrAddr = ImageStart.getAddressData() +
@@ -408,7 +408,7 @@ class ReflectionContext
408408
auto COFFFileHdrBuf = this->getReader().readBytes(
409409
RemoteAddress(COFFFileHdrAddr), sizeof(llvm::object::coff_file_header));
410410
if (!COFFFileHdrBuf)
411-
return false;
411+
return {};
412412
auto COFFFileHdr = reinterpret_cast<const llvm::object::coff_file_header *>(
413413
COFFFileHdrBuf.get());
414414

@@ -419,7 +419,7 @@ class ReflectionContext
419419
RemoteAddress(SectionTableAddr),
420420
sizeof(llvm::object::coff_section) * COFFFileHdr->NumberOfSections);
421421
if (!SectionTableBuf)
422-
return false;
422+
return {};
423423

424424
auto findCOFFSectionByName =
425425
[&](llvm::StringRef Name) -> std::pair<RemoteRef<void>, uint64_t> {
@@ -481,7 +481,7 @@ class ReflectionContext
481481
ReflStrMdSec.first == nullptr &&
482482
ConformMdSec.first == nullptr &&
483483
MPEnumMdSec.first == nullptr)
484-
return false;
484+
return {};
485485

486486
ReflectionInfo Info = {{FieldMdSec.first, FieldMdSec.second},
487487
{AssocTySec.first, AssocTySec.second},
@@ -502,7 +502,7 @@ class ReflectionContext
502502
auto Buf = this->getReader().readBytes(ImageStart,
503503
sizeof(llvm::object::dos_header));
504504
if (!Buf)
505-
return false;
505+
return {};
506506

507507
auto DOSHdr = reinterpret_cast<const llvm::object::dos_header *>(Buf.get());
508508

@@ -512,10 +512,10 @@ class ReflectionContext
512512
Buf = this->getReader().readBytes(RemoteAddress(PEHeaderAddress),
513513
sizeof(llvm::COFF::PEMagic));
514514
if (!Buf)
515-
return false;
515+
return {};
516516

517517
if (memcmp(Buf.get(), llvm::COFF::PEMagic, sizeof(llvm::COFF::PEMagic)))
518-
return false;
518+
return {};
519519

520520
return readPECOFFSections(ImageStart, PotentialModuleNames);
521521
}
@@ -550,7 +550,7 @@ class ReflectionContext
550550

551551
const void *Buf = readData(0, sizeof(typename T::Header));
552552
if (!Buf)
553-
return false;
553+
return {};
554554
auto Hdr = reinterpret_cast<const typename T::Header *>(Buf);
555555
assert(Hdr->getFileClass() == T::ELFClass && "invalid ELF file class");
556556

@@ -560,9 +560,9 @@ class ReflectionContext
560560
uint16_t SectionEntrySize = Hdr->e_shentsize;
561561

562562
if (sizeof(typename T::Section) > SectionEntrySize)
563-
return false;
563+
return {};
564564
if (SectionHdrNumEntries == 0)
565-
return false;
565+
return {};
566566

567567
// Collect all the section headers, we need them to look up the
568568
// reflection sections (by name) and the string table.
@@ -573,7 +573,7 @@ class ReflectionContext
573573
uint64_t Offset = SectionHdrAddress + (I * SectionEntrySize);
574574
auto SecBuf = readData(Offset, sizeof(typename T::Section));
575575
if (!SecBuf)
576-
return false;
576+
return {};
577577
const typename T::Section *SecHdr =
578578
reinterpret_cast<const typename T::Section *>(SecBuf);
579579

@@ -597,7 +597,7 @@ class ReflectionContext
597597

598598
auto StrTabBuf = readData(StrTabOffset, StrTabSize);
599599
if (!StrTabBuf)
600-
return false;
600+
return {};
601601
auto StrTab = reinterpret_cast<const char *>(StrTabBuf);
602602
bool Error = false;
603603

@@ -691,20 +691,15 @@ class ReflectionContext
691691
ObjectFileFormat.getSectionName(ReflectionSectionKind::mpenum), true);
692692

693693
if (Error)
694-
return false;
694+
return {};
695695

696-
std::optional<uint32_t> result = false;
696+
std::optional<uint32_t> result = {};
697697

698698
// We succeed if at least one of the sections is present in the
699699
// ELF executable.
700-
if (FieldMdSec.first != nullptr ||
701-
AssocTySec.first != nullptr ||
702-
BuiltinTySec.first != nullptr ||
703-
CaptureSec.first != nullptr ||
704-
TypeRefMdSec.first != nullptr ||
705-
ReflStrMdSec.first != nullptr ||
706-
ConformMdSec.first != nullptr ||
707-
MPEnumMdSec.first != nullptr) {
700+
if (FieldMdSec.first || AssocTySec.first || BuiltinTySec.first ||
701+
CaptureSec.first || TypeRefMdSec.first || ReflStrMdSec.first ||
702+
ConformMdSec.first || MPEnumMdSec.first) {
708703
ReflectionInfo info = {{FieldMdSec.first, FieldMdSec.second},
709704
{AssocTySec.first, AssocTySec.second},
710705
{BuiltinTySec.first, BuiltinTySec.second},
@@ -739,16 +734,11 @@ class ReflectionContext
739734
ObjectFileFormat.getSectionName(ReflectionSectionKind::mpenum), false);
740735

741736
if (Error)
742-
return false;
737+
return {};
743738

744-
if (FieldMdSec.first != nullptr ||
745-
AssocTySec.first != nullptr ||
746-
BuiltinTySec.first != nullptr ||
747-
CaptureSec.first != nullptr ||
748-
TypeRefMdSec.first != nullptr ||
749-
ReflStrMdSec.first != nullptr ||
750-
ConformMdSec.first != nullptr ||
751-
MPEnumMdSec.first != nullptr) {
739+
if (FieldMdSec.first || AssocTySec.first || BuiltinTySec.first ||
740+
CaptureSec.first || TypeRefMdSec.first || ReflStrMdSec.first ||
741+
ConformMdSec.first || MPEnumMdSec.first) {
752742
ReflectionInfo info = {{FieldMdSec.first, FieldMdSec.second},
753743
{AssocTySec.first, AssocTySec.second},
754744
{BuiltinTySec.first, BuiltinTySec.second},
@@ -819,7 +809,7 @@ class ReflectionContext
819809
// Read the first few bytes to look for a magic header.
820810
auto Magic = this->getReader().readBytes(ImageStart, sizeof(uint32_t));
821811
if (!Magic)
822-
return false;
812+
return {};
823813

824814
uint32_t MagicWord;
825815
memcpy(&MagicWord, Magic.get(), sizeof(MagicWord));

0 commit comments

Comments
 (0)