llvm.org GIT mirror llvm / df0b8bc
Make the Error class constructor protected This is forcing to use Error::success(), which is in a wide majority of cases a lot more readable. Differential Revision: https://reviews.llvm.org/D26481 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286561 91177308-0d34-0410-b5e6-96231b3b80d8 Mehdi Amini 2 years ago
21 changed file(s) with 79 addition(s) and 77 deletion(s). Raw diff Collapse all Expand all
588588 /// Channel is the ChannelT instance to communicate on. It is assumed that
589589 /// the channel is ready to be read from and written to.
590590 static Expected Create(ChannelT &Channel) {
591 Error Err;
591 Error Err = Error::success();
592592 OrcRemoteTargetClient H(Channel, Err);
593593 if (Err)
594594 return std::move(Err);
807807 static Error doNothing() { return Error::success(); }
808808
809809 ChannelT &Channel;
810 Error ExistingError;
810 Error ExistingError = Error::success();
811811 std::string RemoteTargetTriple;
812812 uint32_t RemotePointerSize = 0;
813813 uint32_t RemotePageSize = 0;
148148 // error.
149149 template friend class Expected;
150150
151 public:
151 protected:
152152 /// Create a success value. Prefer using 'Error::success()' for readability
153 /// where possible.
154153 Error() : Payload(nullptr) {
155154 setPtr(nullptr);
156155 setChecked(false);
157156 }
158157
158 public:
159159 /// Create a success value. This is equivalent to calling the default
160160 /// constructor, but should be preferred for readability where possible.
161161 static Error success() { return Error(); }
436436 assert(ResI == Res.end());
437437
438438 ThinLTO.ModuleMap[MBRef.getBufferIdentifier()] = MBRef;
439 return Error();
439 return Error::success();
440440 }
441441
442442 unsigned LTO::getMaxTasks() const {
488488
489489 if (Conf.PreOptModuleHook &&
490490 !Conf.PreOptModuleHook(0, *RegularLTO.CombinedModule))
491 return Error();
491 return Error::success();
492492
493493 if (!Conf.CodeGenOnly) {
494494 for (const auto &R : GlobalResolutions) {
511511
512512 if (Conf.PostInternalizeModuleHook &&
513513 !Conf.PostInternalizeModuleHook(0, *RegularLTO.CombinedModule))
514 return Error();
514 return Error::success();
515515 }
516516 return backend(Conf, AddStream, RegularLTO.ParallelCodeGenParallelismLevel,
517517 std::move(RegularLTO.CombinedModule));
592592 if (AddStreamFn CacheAddStream = Cache(Task, Key))
593593 return RunThinBackend(CacheAddStream);
594594
595 return Error();
595 return Error::success();
596596 }
597597
598598 Error start(
627627 MBRef, std::ref(CombinedIndex), std::ref(ImportList),
628628 std::ref(ExportList), std::ref(ResolvedODR), std::ref(DefinedGlobals),
629629 std::ref(ModuleMap));
630 return Error();
630 return Error::success();
631631 }
632632
633633 Error wait() override {
635635 if (Err)
636636 return std::move(*Err);
637637 else
638 return Error();
638 return Error::success();
639639 }
640640 };
641641
721721 if (ShouldEmitImportsFiles)
722722 return errorCodeToError(
723723 EmitImportsFiles(ModulePath, NewModulePath + ".imports", ImportList));
724 return Error();
725 }
726
727 Error wait() override { return Error(); }
724 return Error::success();
725 }
726
727 Error wait() override { return Error::success(); }
728728 };
729729
730730 ThinBackend lto::createWriteIndexesThinBackend(std::string OldPrefix,
743743 Error LTO::runThinLTO(AddStreamFn AddStream, NativeObjectCache Cache,
744744 bool HasRegularLTO) {
745745 if (ThinLTO.ModuleMap.empty())
746 return Error();
746 return Error::success();
747747
748748 if (Conf.CombinedIndexHook && !Conf.CombinedIndexHook(ThinLTO.CombinedIndex))
749 return Error();
749 return Error::success();
750750
751751 // Collect for each module the list of function it defines (GUID ->
752752 // Summary).
104104 return true;
105105 };
106106
107 return Error();
107 return Error::success();
108108 }
109109
110110 namespace {
301301
302302 if (!C.CodeGenOnly)
303303 if (!opt(C, TM.get(), 0, *Mod, /*IsThinLto=*/false))
304 return Error();
304 return Error::success();
305305
306306 if (ParallelCodeGenParallelismLevel == 1) {
307307 codegen(C, TM.get(), AddStream, 0, *Mod);
309309 splitCodeGen(C, TM.get(), AddStream, ParallelCodeGenParallelismLevel,
310310 std::move(Mod));
311311 }
312 return Error();
312 return Error::success();
313313 }
314314
315315 Error lto::thinBackend(Config &Conf, unsigned Task, AddStreamFn AddStream,
328328
329329 if (Conf.CodeGenOnly) {
330330 codegen(Conf, TM.get(), AddStream, Task, Mod);
331 return Error();
331 return Error::success();
332332 }
333333
334334 if (Conf.PreOptModuleHook && !Conf.PreOptModuleHook(Task, Mod))
335 return Error();
335 return Error::success();
336336
337337 renameModuleForThinLTO(Mod, CombinedIndex);
338338
339339 thinLTOResolveWeakForLinkerModule(Mod, DefinedGlobals);
340340
341341 if (Conf.PostPromoteModuleHook && !Conf.PostPromoteModuleHook(Task, Mod))
342 return Error();
342 return Error::success();
343343
344344 if (!DefinedGlobals.empty())
345345 thinLTOInternalizeModule(Mod, DefinedGlobals);
346346
347347 if (Conf.PostInternalizeModuleHook &&
348348 !Conf.PostInternalizeModuleHook(Task, Mod))
349 return Error();
349 return Error::success();
350350
351351 auto ModuleLoader = [&](StringRef Identifier) {
352352 assert(Mod.getContext().isODRUniquingDebugTypes() &&
362362 return Err;
363363
364364 if (Conf.PostImportModuleHook && !Conf.PostImportModuleHook(Task, Mod))
365 return Error();
365 return Error::success();
366366
367367 if (!opt(Conf, TM.get(), Task, Mod, /*IsThinLto=*/true))
368 return Error();
368 return Error::success();
369369
370370 codegen(Conf, TM.get(), AddStream, Task, Mod);
371 return Error();
372 }
371 return Error::success();
372 }
457457 return malformedError(Msg + NameOrErr.get());
458458 }
459459
460 Error Err;
460 Error Err = Error::success();
461461 Child Ret(Parent, NextLoc, &Err);
462462 if (Err)
463463 return std::move(Err);
507507 }
508508
509509 Expected> Archive::create(MemoryBufferRef Source) {
510 Error Err;
510 Error Err = Error::success();
511511 std::unique_ptr Ret(new Archive(Source, Err));
512512 if (Err)
513513 return std::move(Err);
829829 }
830830
831831 const char *Loc = Parent->getData().begin() + Offset;
832 Error Err;
832 Error Err = Error::success();
833833 Child C(Parent, Loc, &Err);
834834 if (Err)
835835 return std::move(Err);
7878
7979 llvm::Error llvm::object::isNotObjectErrorInvalidFileType(llvm::Error Err) {
8080 if (auto Err2 =
81 handleErrors(std::move(Err),
82 [](std::unique_ptr M) {
83 // Try to handle 'M'. If successful, return a success value from
84 // the handler.
85 if (M->convertToErrorCode() == object_error::invalid_file_type)
86 return Error::success();
81 handleErrors(std::move(Err), [](std::unique_ptr M) -> Error {
82 // Try to handle 'M'. If successful, return a success value from
83 // the handler.
84 if (M->convertToErrorCode() == object_error::invalid_file_type)
85 return Error::success();
8786
88 // We failed to handle 'M' - return it from the handler.
89 // This value will be passed back from catchErrors and
90 // wind up in Err2, where it will be returned from this function.
91 return Error(std::move(M));
92 }))
87 // We failed to handle 'M' - return it from the handler.
88 // This value will be passed back from catchErrors and
89 // wind up in Err2, where it will be returned from this function.
90 return Error(std::move(M));
91 }))
9392 return Err2;
9493 return Err;
9594 }
10721072 MachOObjectFile::create(MemoryBufferRef Object, bool IsLittleEndian,
10731073 bool Is64Bits, uint32_t UniversalCputype,
10741074 uint32_t UniversalIndex) {
1075 Error Err;
1075 Error Err = Error::success();
10761076 std::unique_ptr Obj(
10771077 new MachOObjectFile(std::move(Object), IsLittleEndian,
10781078 Is64Bits, Err, UniversalCputype,
106106
107107 Expected>
108108 MachOUniversalBinary::create(MemoryBufferRef Source) {
109 Error Err;
109 Error Err = Error::success();
110110 std::unique_ptr Ret(
111111 new MachOUniversalBinary(Source, Err));
112112 if (Err)
647647 StringRef Coverage;
648648 uint8_t BytesInAddress;
649649 support::endianness Endian;
650 Error E;
650 Error E = Error::success();
651651 consumeError(std::move(E));
652652 if (ObjectBuffer->getBuffer().startswith(TestingFormatMagic))
653653 // This is a special format used for testing.
9999 Buffers.reserve(CurrentArchives.size());
100100
101101 for (const auto &CurrentArchive : CurrentArchives) {
102 Error Err;
102 Error Err = Error::success();
103103 for (auto Child : CurrentArchive->children(Err)) {
104104 if (auto NameOrErr = Child.getName()) {
105105 if (*NameOrErr == Filename) {
422422
423423 bool Filter = !Members.empty();
424424 {
425 Error Err;
425 Error Err = Error::success();
426426 for (auto &C : OldArchive->children(Err)) {
427427 Expected NameOrErr = C.getName();
428428 failIfError(NameOrErr.takeError());
550550 int InsertPos = -1;
551551 StringRef PosName = sys::path::filename(RelPos);
552552 if (OldArchive) {
553 Error Err;
553 Error Err = Error::success();
554554 for (auto &Child : OldArchive->children(Err)) {
555555 int Pos = Ret.size();
556556 Expected NameOrErr = Child.getName();
722722 fail("error opening '" + ArchiveName + "': " + EC.message() + "!");
723723
724724 if (!EC) {
725 Error Err;
725 Error Err = Error::success();
726726 object::Archive Archive(Buf.get()->getMemBufferRef(), Err);
727727 EC = errorToErrorCode(std::move(Err));
728728 failIfError(EC,
784784 Archives.push_back(std::move(*LibOrErr));
785785 object::Archive &Lib = *Archives.back();
786786 {
787 Error Err;
787 Error Err = Error::success();
788788 for (auto &Member : Lib.children(Err))
789789 addMember(NewMembers, Member);
790790 failIfError(std::move(Err));
489489 }
490490
491491 static void dumpArchive(const Archive *Arc) {
492 Error Err;
492 Error Err = Error::success();
493493 for (auto &ArcC : Arc->children(Err)) {
494494 Expected> ChildOrErr = ArcC.getAsBinary();
495495 if (!ChildOrErr) {
363363 std::deque> &UncompressedSections, StringRef &Name,
364364 StringRef &Contents) {
365365 if (!Name.startswith("zdebug_"))
366 return Error();
366 return Error::success();
367367 UncompressedSections.emplace_back();
368368 uint64_t OriginalSize;
369369 if (!zlib::isAvailable())
376376 .str());
377377 Name = Name.substr(1);
378378 Contents = UncompressedSections.back();
379 return Error();
379 return Error::success();
380380 }
381381
382382 static Error handleSection(
391391 StringRef &AbbrevSection, StringRef &CurCUIndexSection,
392392 StringRef &CurTUIndexSection) {
393393 if (Section.isBSS())
394 return Error();
394 return Error::success();
395395
396396 if (Section.isVirtual())
397 return Error();
397 return Error::success();
398398
399399 StringRef Name;
400400 if (std::error_code Err = Section.getName(Name))
411411
412412 auto SectionPair = KnownSections.find(Name);
413413 if (SectionPair == KnownSections.end())
414 return Error();
414 return Error::success();
415415
416416 if (DWARFSectionKind Kind = SectionPair->second.second) {
417417 auto Index = Kind - DW_SECT_INFO;
448448 Out.SwitchSection(OutSection);
449449 Out.EmitBytes(Contents);
450450 }
451 return Error();
451 return Error::success();
452452 }
453453
454454 static Error
599599 writeIndex(Out, MCOFI.getDwarfCUIndexSection(), ContributionOffsets,
600600 IndexEntries);
601601
602 return Error();
602 return Error::success();
603603 }
604604
605605 static int error(const Twine &Error, const Twine &Context) {
11121112 }
11131113
11141114 {
1115 Error Err;
1115 Error Err = Error::success();
11161116 for (auto &C : A->children(Err)) {
11171117 Expected> ChildOrErr = C.getAsBinary(&Context);
11181118 if (!ChildOrErr) {
11771177 } else if (Expected> AOrErr =
11781178 I->getAsArchive()) {
11791179 std::unique_ptr &A = *AOrErr;
1180 Error Err;
1180 Error Err = Error::success();
11811181 for (auto &C : A->children(Err)) {
11821182 Expected> ChildOrErr =
11831183 C.getAsBinary(&Context);
12481248 } else if (Expected> AOrErr =
12491249 I->getAsArchive()) {
12501250 std::unique_ptr &A = *AOrErr;
1251 Error Err;
1251 Error Err = Error::success();
12521252 for (auto &C : A->children(Err)) {
12531253 Expected> ChildOrErr =
12541254 C.getAsBinary(&Context);
13151315 } else if (Expected> AOrErr =
13161316 I->getAsArchive()) {
13171317 std::unique_ptr &A = *AOrErr;
1318 Error Err;
1318 Error Err = Error::success();
13191319 for (auto &C : A->children(Err)) {
13201320 Expected> ChildOrErr =
13211321 C.getAsBinary(&Context);
15451545 static void printArchiveHeaders(StringRef Filename, Archive *A, bool verbose,
15461546 bool print_offset,
15471547 StringRef ArchitectureName = StringRef()) {
1548 Error Err;
1548 Error Err = Error::success();
1549 ;
15491550 for (const auto &C : A->children(Err, false))
15501551 printArchiveChild(Filename, C, verbose, print_offset, ArchitectureName);
15511552
15821583 if (ArchiveHeaders)
15831584 printArchiveHeaders(Filename, A, !NonVerbose, ArchiveMemberOffsets);
15841585
1585 Error Err;
1586 Error Err = Error::success();
15861587 for (auto &C : A->children(Err)) {
15871588 Expected> ChildOrErr = C.getAsBinary();
15881589 if (!ChildOrErr) {
16401641 if (ArchiveHeaders)
16411642 printArchiveHeaders(Filename, A.get(), !NonVerbose,
16421643 ArchiveMemberOffsets, ArchitectureName);
1643 Error Err;
1644 Error Err = Error::success();
16441645 for (auto &C : A->children(Err)) {
16451646 Expected> ChildOrErr = C.getAsBinary();
16461647 if (!ChildOrErr) {
16961697 if (ArchiveHeaders)
16971698 printArchiveHeaders(Filename, A.get(), !NonVerbose,
16981699 ArchiveMemberOffsets);
1699 Error Err;
1700 Error Err = Error::success();
17001701 for (auto &C : A->children(Err)) {
17011702 Expected> ChildOrErr = C.getAsBinary();
17021703 if (!ChildOrErr) {
17481749 if (ArchiveHeaders)
17491750 printArchiveHeaders(Filename, A.get(), !NonVerbose,
17501751 ArchiveMemberOffsets, ArchitectureName);
1751 Error Err;
1752 Error Err = Error::success();
17521753 for (auto &C : A->children(Err)) {
17531754 Expected> ChildOrErr = C.getAsBinary();
17541755 if (!ChildOrErr) {
19681968
19691969 /// @brief Dump each object file in \a a;
19701970 static void DumpArchive(const Archive *a) {
1971 Error Err;
1971 Error Err = Error::success();
19721972 for (auto &C : a->children(Err)) {
19731973 Expected> ChildOrErr = C.getAsBinary();
19741974 if (!ChildOrErr) {
457457
458458 /// @brief Dumps each object file in \a Arc;
459459 static void dumpArchive(const Archive *Arc) {
460 Error Err;
460 Error Err = Error::success();
461461 for (auto &Child : Arc->children(Err)) {
462462 Expected> ChildOrErr = Child.getAsBinary();
463463 if (!ChildOrErr) {
541541
542542 if (Archive *a = dyn_cast(&Bin)) {
543543 // This is an archive. Iterate over each member and display its sizes.
544 Error Err;
544 Error Err = Error::success();
545545 for (auto &C : a->children(Err)) {
546546 Expected> ChildOrErr = C.getAsBinary();
547547 if (!ChildOrErr) {
610610 std::unique_ptr &UA = *AOrErr;
611611 // This is an archive. Iterate over each member and display its
612612 // sizes.
613 Error Err;
613 Error Err = Error::success();
614614 for (auto &C : UA->children(Err)) {
615615 Expected> ChildOrErr = C.getAsBinary();
616616 if (!ChildOrErr) {
699699 std::unique_ptr &UA = *AOrErr;
700700 // This is an archive. Iterate over each member and display its
701701 // sizes.
702 Error Err;
702 Error Err = Error::success();
703703 for (auto &C : UA->children(Err)) {
704704 Expected> ChildOrErr = C.getAsBinary();
705705 if (!ChildOrErr) {
774774 I->getAsArchive()) {
775775 std::unique_ptr &UA = *AOrErr;
776776 // This is an archive. Iterate over each member and display its sizes.
777 Error Err;
777 Error Err = Error::success();
778778 for (auto &C : UA->children(Err)) {
779779 Expected> ChildOrErr = C.getAsBinary();
780780 if (!ChildOrErr) {
222222 Out << YAMLSleds;
223223 }
224224
225 static CommandRegistration Unused(&Extract, [] {
226 Error Err;
225 static CommandRegistration Unused(&Extract, []() -> Error {
226 Error Err = Error::success();
227227 xray::InstrumentationMapExtractor Extractor(
228228 ExtractInput, InstrumentationMapExtractor::InputFormats::ELF, Err);
229229 if (Err)
820820 static void
821821 visitObjectFiles(const object::Archive &A,
822822 function_ref Fn) {
823 Error Err;
823 Error Err = Error::success();
824824 for (auto &C : A.children(Err)) {
825825 Expected> ChildOrErr = C.getAsBinary();
826826 failIfError(ChildOrErr);
8181
8282 char CustomSubError::ID = 0;
8383
84 static Error handleCustomError(const CustomError &CE) { return Error(); }
84 static Error handleCustomError(const CustomError &CE) {
85 return Error::success();
86 }
8587
8688 static void handleCustomErrorVoid(const CustomError &CE) {}
8789
8890 static Error handleCustomErrorUP(std::unique_ptr CE) {
89 return Error();
91 return Error::success();
9092 }
9193
9294 static void handleCustomErrorUPVoid(std::unique_ptr CE) {}