[lld] r319974 - Always evaluate the second argument for CHECK() lazily.
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 6 14:15:32 PST 2017
Thanks
Rui Ueyama via llvm-commits <llvm-commits at lists.llvm.org> writes:
> Author: ruiu
> Date: Wed Dec 6 14:08:17 2017
> New Revision: 319974
>
> URL: http://llvm.org/viewvc/llvm-project?rev=319974&view=rev
> Log:
> Always evaluate the second argument for CHECK() lazily.
>
> This patch is to rename check CHECK and make it a C macro, so that
> we can evaluate the second argument lazily.
>
> Differential Revision: https://reviews.llvm.org/D40915
>
> Modified:
> lld/trunk/COFF/Driver.cpp
> lld/trunk/COFF/DriverUtils.cpp
> lld/trunk/COFF/InputFiles.cpp
> lld/trunk/COFF/Writer.cpp
> lld/trunk/ELF/Driver.cpp
> lld/trunk/ELF/InputFiles.cpp
> lld/trunk/include/lld/Common/ErrorHandler.h
> lld/trunk/wasm/InputFiles.cpp
>
> Modified: lld/trunk/COFF/Driver.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=319974&r1=319973&r2=319974&view=diff
> ==============================================================================
> --- lld/trunk/COFF/Driver.cpp (original)
> +++ lld/trunk/COFF/Driver.cpp Wed Dec 6 14:08:17 2017
> @@ -131,7 +131,7 @@ void LinkerDriver::addBuffer(std::unique
> case file_magic::archive:
> if (WholeArchive) {
> std::unique_ptr<Archive> File =
> - check(Archive::create(MBRef),
> + CHECK(Archive::create(MBRef),
> MBRef.getBufferIdentifier() + ": failed to parse archive");
>
> for (MemoryBufferRef M : getArchiveMembers(File.get()))
> @@ -196,7 +196,7 @@ void LinkerDriver::enqueueArchiveMember(
> StringRef SymName,
> StringRef ParentName) {
> if (!C.getParent()->isThin()) {
> - MemoryBufferRef MB = check(
> + MemoryBufferRef MB = CHECK(
> C.getMemoryBufferRef(),
> "could not get the buffer for the member defining symbol " + SymName);
> enqueueTask([=]() { Driver->addArchiveBuffer(MB, SymName, ParentName); });
> @@ -204,7 +204,7 @@ void LinkerDriver::enqueueArchiveMember(
> }
>
> auto Future = std::make_shared<std::future<MBErrPair>>(createFutureForFile(
> - check(C.getFullName(),
> + CHECK(C.getFullName(),
> "could not get the filename for the member defining symbol " +
> SymName)));
> enqueueTask([=]() {
> @@ -531,8 +531,8 @@ static void createImportLibrary(bool AsL
> }
>
> static void parseModuleDefs(StringRef Path) {
> - std::unique_ptr<MemoryBuffer> MB = check(
> - MemoryBuffer::getFile(Path, -1, false, true), "could not open " + Path);
> + std::unique_ptr<MemoryBuffer> MB = CHECK(
> + MemoryBuffer::getFile(Path, -1, false, true), "could not open " + Path);
> COFFModuleDefinition M = check(parseCOFFModuleDefinition(
> MB->getMemBufferRef(), Config->Machine, Config->MinGW));
>
> @@ -577,7 +577,7 @@ static bool needsRebuilding(MemoryBuffer
> // The MSVC linker doesn't support thin archives, so if it's a thin
> // archive, we always need to rebuild it.
> std::unique_ptr<Archive> File =
> - check(Archive::create(MB), "Failed to read " + MB.getBufferIdentifier());
> + CHECK(Archive::create(MB), "Failed to read " + MB.getBufferIdentifier());
> if (File->isThin())
> return true;
>
> @@ -598,7 +598,7 @@ static bool needsRebuilding(MemoryBuffer
> // its path is returned.
> static Optional<std::string>
> filterBitcodeFiles(StringRef Path, std::vector<std::string> &TemporaryFiles) {
> - std::unique_ptr<MemoryBuffer> MB = check(
> + std::unique_ptr<MemoryBuffer> MB = CHECK(
> MemoryBuffer::getFile(Path, -1, false, true), "could not open " + Path);
> MemoryBufferRef MBRef = MB->getMemBufferRef();
> file_magic Magic = identify_magic(MBRef.getBuffer());
> @@ -611,7 +611,7 @@ filterBitcodeFiles(StringRef Path, std::
> return Path.str();
>
> std::unique_ptr<Archive> File =
> - check(Archive::create(MBRef),
> + CHECK(Archive::create(MBRef),
> MBRef.getBufferIdentifier() + ": failed to parse archive");
>
> std::vector<NewArchiveMember> New;
> @@ -957,7 +957,7 @@ void LinkerDriver::link(ArrayRef<const c
>
> // Handle /lldsavecachepolicy
> if (auto *Arg = Args.getLastArg(OPT_lldltocachepolicy))
> - Config->LTOCachePolicy = check(
> + Config->LTOCachePolicy = CHECK(
> parseCachePruningPolicy(Arg->getValue()),
> Twine("/lldltocachepolicy: invalid cache policy: ") + Arg->getValue());
>
>
> Modified: lld/trunk/COFF/DriverUtils.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DriverUtils.cpp?rev=319974&r1=319973&r2=319974&view=diff
> ==============================================================================
> --- lld/trunk/COFF/DriverUtils.cpp (original)
> +++ lld/trunk/COFF/DriverUtils.cpp Wed Dec 6 14:08:17 2017
> @@ -317,7 +317,7 @@ public:
> // is called (you cannot remove an opened file on Windows.)
> std::unique_ptr<MemoryBuffer> getMemoryBuffer() {
> // IsVolatileSize=true forces MemoryBuffer to not use mmap().
> - return check(MemoryBuffer::getFile(Path, /*FileSize=*/-1,
> + return CHECK(MemoryBuffer::getFile(Path, /*FileSize=*/-1,
> /*RequiresNullTerminator=*/false,
> /*IsVolatileSize=*/true),
> "could not open " + Path);
> @@ -402,7 +402,7 @@ static std::string createManifestXmlWith
> E.add("/out:" + StringRef(User.Path));
> E.run();
>
> - return check(MemoryBuffer::getFile(User.Path), "could not open " + User.Path)
> + return CHECK(MemoryBuffer::getFile(User.Path), "could not open " + User.Path)
> .get()
> ->getBuffer();
> }
>
> Modified: lld/trunk/COFF/InputFiles.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=319974&r1=319973&r2=319974&view=diff
> ==============================================================================
> --- lld/trunk/COFF/InputFiles.cpp (original)
> +++ lld/trunk/COFF/InputFiles.cpp Wed Dec 6 14:08:17 2017
> @@ -63,7 +63,7 @@ ArchiveFile::ArchiveFile(MemoryBufferRef
>
> void ArchiveFile::parse() {
> // Parse a MemoryBufferRef as an archive file.
> - File = check(Archive::create(MB), toString(this));
> + File = CHECK(Archive::create(MB), toString(this));
>
> // Read the symbol table to construct Lazy objects.
> for (const Archive::Symbol &Sym : File->symbols())
> @@ -73,7 +73,7 @@ void ArchiveFile::parse() {
> // Returns a buffer pointing to a member file containing a given symbol.
> void ArchiveFile::addMember(const Archive::Symbol *Sym) {
> const Archive::Child &C =
> - check(Sym->getMember(),
> + CHECK(Sym->getMember(),
> "could not get the member for symbol " + Sym->getName());
>
> // Return an empty buffer if we have already returned the same buffer.
> @@ -88,10 +88,10 @@ std::vector<MemoryBufferRef> getArchiveM
> Error Err = Error::success();
> for (const ErrorOr<Archive::Child> &COrErr : File->children(Err)) {
> Archive::Child C =
> - check(COrErr,
> + CHECK(COrErr,
> File->getFileName() + ": could not get the child of the archive");
> MemoryBufferRef MBRef =
> - check(C.getMemoryBufferRef(),
> + CHECK(C.getMemoryBufferRef(),
> File->getFileName() +
> ": could not get the buffer for a child of the archive");
> V.push_back(MBRef);
> @@ -104,7 +104,7 @@ std::vector<MemoryBufferRef> getArchiveM
>
> void ObjFile::parse() {
> // Parse a memory buffer as a COFF file.
> - std::unique_ptr<Binary> Bin = check(createBinary(MB), toString(this));
> + std::unique_ptr<Binary> Bin = CHECK(createBinary(MB), toString(this));
>
> if (auto *Obj = dyn_cast<COFFObjectFile>(Bin.get())) {
> Bin.release();
>
> Modified: lld/trunk/COFF/Writer.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=319974&r1=319973&r2=319974&view=diff
> ==============================================================================
> --- lld/trunk/COFF/Writer.cpp (original)
> +++ lld/trunk/COFF/Writer.cpp Wed Dec 6 14:08:17 2017
> @@ -784,7 +784,7 @@ template <typename PEHeaderTy> void Writ
> }
>
> void Writer::openFile(StringRef Path) {
> - Buffer = check(
> + Buffer = CHECK(
> FileOutputBuffer::create(Path, FileSize, FileOutputBuffer::F_executable),
> "failed to open " + Path);
> }
>
> Modified: lld/trunk/ELF/Driver.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=319974&r1=319973&r2=319974&view=diff
> ==============================================================================
> --- lld/trunk/ELF/Driver.cpp (original)
> +++ lld/trunk/ELF/Driver.cpp Wed Dec 6 14:08:17 2017
> @@ -136,7 +136,7 @@ static std::tuple<ELFKind, uint16_t, uin
> std::vector<std::pair<MemoryBufferRef, uint64_t>> static getArchiveMembers(
> MemoryBufferRef MB) {
> std::unique_ptr<Archive> File =
> - check(Archive::create(MB),
> + CHECK(Archive::create(MB),
> MB.getBufferIdentifier() + ": failed to parse archive");
>
> std::vector<std::pair<MemoryBufferRef, uint64_t>> V;
> @@ -144,10 +144,10 @@ std::vector<std::pair<MemoryBufferRef, u
> bool AddToTar = File->isThin() && Tar;
> for (const ErrorOr<Archive::Child> &COrErr : File->children(Err)) {
> Archive::Child C =
> - check(COrErr, MB.getBufferIdentifier() +
> + CHECK(COrErr, MB.getBufferIdentifier() +
> ": could not get the child of the archive");
> MemoryBufferRef MBRef =
> - check(C.getMemoryBufferRef(),
> + CHECK(C.getMemoryBufferRef(),
> MB.getBufferIdentifier() +
> ": could not get the buffer for a child of the archive");
> if (AddToTar)
> @@ -192,7 +192,7 @@ void LinkerDriver::addFile(StringRef Pat
> }
>
> std::unique_ptr<Archive> File =
> - check(Archive::create(MBRef), Path + ": failed to parse archive");
> + CHECK(Archive::create(MBRef), Path + ": failed to parse archive");
>
> // If an archive file has no symbol table, it is likely that a user
> // is attempting LTO and using a default ar command that doesn't
> @@ -651,7 +651,7 @@ void LinkerDriver::readConfigs(opt::Inpu
> Config->Target1Rel = Args.hasFlag(OPT_target1_rel, OPT_target1_abs, false);
> Config->Target2 = getTarget2(Args);
> Config->ThinLTOCacheDir = Args.getLastArgValue(OPT_thinlto_cache_dir);
> - Config->ThinLTOCachePolicy = check(
> + Config->ThinLTOCachePolicy = CHECK(
> parseCachePruningPolicy(Args.getLastArgValue(OPT_thinlto_cache_policy)),
> "--thinlto-cache-policy: invalid cache policy");
> Config->ThinLTOJobs = args::getInteger(Args, OPT_thinlto_jobs, -1u);
>
> Modified: lld/trunk/ELF/InputFiles.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=319974&r1=319973&r2=319974&view=diff
> ==============================================================================
> --- lld/trunk/ELF/InputFiles.cpp (original)
> +++ lld/trunk/ELF/InputFiles.cpp Wed Dec 6 14:08:17 2017
> @@ -209,19 +209,19 @@ typename ELFT::SymRange ELFFileBase<ELFT
>
> template <class ELFT>
> uint32_t ELFFileBase<ELFT>::getSectionIndex(const Elf_Sym &Sym) const {
> - return checkLazy(getObj().getSectionIndex(&Sym, ELFSyms, SymtabSHNDX),
> - [=]() { return toString(this); });
> + return CHECK(getObj().getSectionIndex(&Sym, ELFSyms, SymtabSHNDX),
> + toString(this));
> }
>
> template <class ELFT>
> void ELFFileBase<ELFT>::initSymtab(ArrayRef<Elf_Shdr> Sections,
> const Elf_Shdr *Symtab) {
> FirstNonLocal = Symtab->sh_info;
> - ELFSyms = check(getObj().symbols(Symtab), toString(this));
> + ELFSyms = CHECK(getObj().symbols(Symtab), toString(this));
> if (FirstNonLocal == 0 || FirstNonLocal > ELFSyms.size())
> fatal(toString(this) + ": invalid sh_info in symbol table");
>
> - StringTable = check(getObj().getStringTableForSymtab(*Symtab, Sections),
> + StringTable = CHECK(getObj().getStringTableForSymtab(*Symtab, Sections),
> toString(this));
> }
>
> @@ -253,15 +253,13 @@ StringRef ObjFile<ELFT>::getShtGroupSign
> // Group signatures are stored as symbol names in object files.
> // sh_info contains a symbol index, so we fetch a symbol and read its name.
> if (this->ELFSyms.empty())
> - this->initSymtab(Sections,
> - checkLazy(object::getSection<ELFT>(Sections, Sec.sh_link),
> - [=]() { return toString(this); }));
> -
> - const Elf_Sym *Sym =
> - checkLazy(object::getSymbol<ELFT>(this->ELFSyms, Sec.sh_info),
> - [=]() { return toString(this); });
> - StringRef Signature = checkLazy(Sym->getName(this->StringTable),
> - [=]() { return toString(this); });
> + this->initSymtab(
> + Sections,
> + CHECK(object::getSection<ELFT>(Sections, Sec.sh_link), toString(this)));
> +
> + const Elf_Sym *Sym = CHECK(
> + object::getSymbol<ELFT>(this->ELFSyms, Sec.sh_info), toString(this));
> + StringRef Signature = CHECK(Sym->getName(this->StringTable), toString(this));
>
> // As a special case, if a symbol is a section symbol and has no name,
> // we use a section name as a signature.
> @@ -279,9 +277,8 @@ template <class ELFT>
> ArrayRef<typename ObjFile<ELFT>::Elf_Word>
> ObjFile<ELFT>::getShtGroupEntries(const Elf_Shdr &Sec) {
> const ELFFile<ELFT> &Obj = this->getObj();
> - ArrayRef<Elf_Word> Entries =
> - checkLazy(Obj.template getSectionContentsAsArray<Elf_Word>(&Sec),
> - [=]() { return toString(this); });
> + ArrayRef<Elf_Word> Entries = CHECK(
> + Obj.template getSectionContentsAsArray<Elf_Word>(&Sec), toString(this));
> if (Entries.empty() || Entries[0] != GRP_COMDAT)
> fatal(toString(this) + ": unsupported SHT_GROUP format");
> return Entries.slice(1);
> @@ -327,11 +324,11 @@ void ObjFile<ELFT>::initializeSections(
> const ELFFile<ELFT> &Obj = this->getObj();
>
> ArrayRef<Elf_Shdr> ObjSections =
> - check(this->getObj().sections(), toString(this));
> + CHECK(this->getObj().sections(), toString(this));
> uint64_t Size = ObjSections.size();
> this->Sections.resize(Size);
> this->SectionStringTable =
> - check(Obj.getSectionStringTable(ObjSections), toString(this));
> + CHECK(Obj.getSectionStringTable(ObjSections), toString(this));
>
> for (size_t I = 0, E = ObjSections.size(); I < E; I++) {
> if (this->Sections[I] == &InputSection::Discarded)
> @@ -378,7 +375,7 @@ void ObjFile<ELFT>::initializeSections(
> break;
> case SHT_SYMTAB_SHNDX:
> this->SymtabSHNDX =
> - check(Obj.getSHNDXTable(Sec, ObjSections), toString(this));
> + CHECK(Obj.getSHNDXTable(Sec, ObjSections), toString(this));
> break;
> case SHT_STRTAB:
> case SHT_NULL:
> @@ -523,14 +520,13 @@ InputSectionBase *ObjFile<ELFT>::createI
>
> size_t NumRelocations;
> if (Sec.sh_type == SHT_RELA) {
> - ArrayRef<Elf_Rela> Rels = checkLazy(this->getObj().relas(&Sec),
> - [=]() { return toString(this); });
> + ArrayRef<Elf_Rela> Rels =
> + CHECK(this->getObj().relas(&Sec), toString(this));
> Target->FirstRelocation = Rels.begin();
> NumRelocations = Rels.size();
> Target->AreRelocsRela = true;
> } else {
> - ArrayRef<Elf_Rel> Rels = checkLazy(this->getObj().rels(&Sec),
> - [=]() { return toString(this); });
> + ArrayRef<Elf_Rel> Rels = CHECK(this->getObj().rels(&Sec), toString(this));
> Target->FirstRelocation = Rels.begin();
> NumRelocations = Rels.size();
> Target->AreRelocsRela = false;
> @@ -599,8 +595,8 @@ InputSectionBase *ObjFile<ELFT>::createI
>
> template <class ELFT>
> StringRef ObjFile<ELFT>::getSectionName(const Elf_Shdr &Sec) {
> - return checkLazy(this->getObj().getSectionName(&Sec, SectionStringTable),
> - [=]() { return toString(this); });
> + return CHECK(this->getObj().getSectionName(&Sec, SectionStringTable),
> + toString(this));
> }
>
> template <class ELFT> void ObjFile<ELFT>::initializeSymbols() {
> @@ -632,7 +628,7 @@ template <class ELFT> Symbol *ObjFile<EL
>
> if (Binding == STB_LOCAL) {
> if (Sym->getType() == STT_FILE)
> - SourceFile = check(Sym->getName(this->StringTable), toString(this));
> + SourceFile = CHECK(Sym->getName(this->StringTable), toString(this));
>
> if (this->StringTable.size() <= Sym->st_name)
> fatal(toString(this) + ": invalid symbol name offset");
> @@ -644,8 +640,7 @@ template <class ELFT> Symbol *ObjFile<EL
> return make<Defined>(this, Name, Binding, StOther, Type, Value, Size, Sec);
> }
>
> - StringRef Name = checkLazy(Sym->getName(this->StringTable),
> - [=]() { return toString(this); });
> + StringRef Name = CHECK(Sym->getName(this->StringTable), toString(this));
>
> switch (Sym->st_shndx) {
> case SHN_UNDEF:
> @@ -686,7 +681,7 @@ template <class ELFT> void ArchiveFile::
> std::pair<MemoryBufferRef, uint64_t>
> ArchiveFile::getMember(const Archive::Symbol *Sym) {
> Archive::Child C =
> - check(Sym->getMember(), toString(this) +
> + CHECK(Sym->getMember(), toString(this) +
> ": could not get the member for symbol " +
> Sym->getName());
>
> @@ -694,13 +689,13 @@ ArchiveFile::getMember(const Archive::Sy
> return {MemoryBufferRef(), 0};
>
> MemoryBufferRef Ret =
> - check(C.getMemoryBufferRef(),
> + CHECK(C.getMemoryBufferRef(),
> toString(this) +
> ": could not get the buffer for the member defining symbol " +
> Sym->getName());
>
> if (C.getParent()->isThin() && Tar)
> - Tar->append(relativeToRoot(check(C.getFullName(), toString(this))),
> + Tar->append(relativeToRoot(CHECK(C.getFullName(), toString(this))),
> Ret.getBuffer());
> if (C.getParent()->isThin())
> return {Ret, 0};
> @@ -717,7 +712,7 @@ SharedFile<ELFT>::SharedFile(MemoryBuffe
> template <class ELFT> void SharedFile<ELFT>::parseSoName() {
> const Elf_Shdr *DynamicSec = nullptr;
> const ELFFile<ELFT> Obj = this->getObj();
> - ArrayRef<Elf_Shdr> Sections = check(Obj.sections(), toString(this));
> + ArrayRef<Elf_Shdr> Sections = CHECK(Obj.sections(), toString(this));
>
> // Search for .dynsym, .dynamic, .symtab, .gnu.version and .gnu.version_d.
> for (const Elf_Shdr &Sec : Sections) {
> @@ -732,7 +727,7 @@ template <class ELFT> void SharedFile<EL
> break;
> case SHT_SYMTAB_SHNDX:
> this->SymtabSHNDX =
> - check(Obj.getSHNDXTable(Sec, Sections), toString(this));
> + CHECK(Obj.getSHNDXTable(Sec, Sections), toString(this));
> break;
> case SHT_GNU_versym:
> this->VersymSec = &Sec;
> @@ -750,7 +745,7 @@ template <class ELFT> void SharedFile<EL
> if (!DynamicSec)
> return;
> ArrayRef<Elf_Dyn> Arr =
> - check(Obj.template getSectionContentsAsArray<Elf_Dyn>(DynamicSec),
> + CHECK(Obj.template getSectionContentsAsArray<Elf_Dyn>(DynamicSec),
> toString(this));
> for (const Elf_Dyn &Dyn : Arr) {
> if (Dyn.d_tag == DT_SONAME) {
> @@ -811,7 +806,7 @@ template <class ELFT> void SharedFile<EL
> std::vector<const Elf_Verdef *> Verdefs = parseVerdefs(Versym);
>
> ArrayRef<Elf_Shdr> Sections =
> - check(this->getObj().sections(), toString(this));
> + CHECK(this->getObj().sections(), toString(this));
>
> // Add symbols to the symbol table.
> Elf_Sym_Range Syms = this->getGlobalELFSyms();
> @@ -824,7 +819,7 @@ template <class ELFT> void SharedFile<EL
> bool Hidden = VersymIndex & VERSYM_HIDDEN;
> VersymIndex = VersymIndex & ~VERSYM_HIDDEN;
>
> - StringRef Name = check(Sym.getName(this->StringTable), toString(this));
> + StringRef Name = CHECK(Sym.getName(this->StringTable), toString(this));
> if (Sym.isUndefined()) {
> Undefs.push_back(Name);
> continue;
> @@ -921,7 +916,7 @@ BitcodeFile::BitcodeFile(MemoryBufferRef
> MemoryBufferRef MBRef(MB.getBuffer(),
> Saver.save(ArchiveName + MB.getBufferIdentifier() +
> utostr(OffsetInArchive)));
> - Obj = check(lto::InputFile::create(MBRef), toString(this));
> + Obj = CHECK(lto::InputFile::create(MBRef), toString(this));
>
> Triple T(Obj->getTargetTriple());
> EKind = getBitcodeELFKind(T);
> @@ -1086,20 +1081,20 @@ template <class ELFT> std::vector<String
> typedef typename ELFT::SymRange Elf_Sym_Range;
>
> ELFFile<ELFT> Obj = check(ELFFile<ELFT>::create(this->MB.getBuffer()));
> - ArrayRef<Elf_Shdr> Sections = check(Obj.sections(), toString(this));
> + ArrayRef<Elf_Shdr> Sections = CHECK(Obj.sections(), toString(this));
> for (const Elf_Shdr &Sec : Sections) {
> if (Sec.sh_type != SHT_SYMTAB)
> continue;
>
> - Elf_Sym_Range Syms = check(Obj.symbols(&Sec), toString(this));
> + Elf_Sym_Range Syms = CHECK(Obj.symbols(&Sec), toString(this));
> uint32_t FirstNonLocal = Sec.sh_info;
> StringRef StringTable =
> - check(Obj.getStringTableForSymtab(Sec, Sections), toString(this));
> + CHECK(Obj.getStringTableForSymtab(Sec, Sections), toString(this));
> std::vector<StringRef> V;
>
> for (const Elf_Sym &Sym : Syms.slice(FirstNonLocal))
> if (Sym.st_shndx != SHN_UNDEF)
> - V.push_back(check(Sym.getName(StringTable), toString(this)));
> + V.push_back(CHECK(Sym.getName(StringTable), toString(this)));
> return V;
> }
> return {};
> @@ -1107,7 +1102,7 @@ template <class ELFT> std::vector<String
>
> std::vector<StringRef> LazyObjFile::getBitcodeSymbols() {
> std::unique_ptr<lto::InputFile> Obj =
> - check(lto::InputFile::create(this->MB), toString(this));
> + CHECK(lto::InputFile::create(this->MB), toString(this));
> std::vector<StringRef> V;
> for (const lto::InputFile::Symbol &Sym : Obj->symbols())
> if (!Sym.isUndefined())
>
> Modified: lld/trunk/include/lld/Common/ErrorHandler.h
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Common/ErrorHandler.h?rev=319974&r1=319973&r2=319974&view=diff
> ==============================================================================
> --- lld/trunk/include/lld/Common/ErrorHandler.h (original)
> +++ lld/trunk/include/lld/Common/ErrorHandler.h Wed Dec 6 14:08:17 2017
> @@ -74,7 +74,7 @@ inline uint64_t errorCount() { return er
>
> LLVM_ATTRIBUTE_NORETURN void exitLld(int Val);
>
> -// check() functions are convenient functions to strip errors
> +// check functions are convenient functions to strip errors
> // from error-or-value objects.
> template <class T> T check(ErrorOr<T> E) {
> if (auto EC = E.getError())
> @@ -88,25 +88,27 @@ template <class T> T check(Expected<T> E
> return std::move(*E);
> }
>
> -template <class T> T check(ErrorOr<T> E, const Twine &Prefix) {
> +template <class T>
> +T check2(ErrorOr<T> E, llvm::function_ref<std::string()> Prefix) {
> if (auto EC = E.getError())
> - fatal(Prefix + ": " + EC.message());
> - return std::move(*E);
> -}
> -
> -template <class T> T check(Expected<T> E, const Twine &Prefix) {
> - if (!E)
> - fatal(Prefix + ": " + toString(E.takeError()));
> + fatal(Prefix() + ": " + EC.message());
> return std::move(*E);
> }
>
> -// A lazy variant that only allocates error messages when there is an error.
> template <class T>
> -T checkLazy(Expected<T> E, llvm::function_ref<std::string()> getPrefix) {
> +T check2(Expected<T> E, llvm::function_ref<std::string()> Prefix) {
> if (!E)
> - fatal(getPrefix() + ": " + toString(E.takeError()));
> + fatal(Prefix() + ": " + toString(E.takeError()));
> return std::move(*E);
> }
> +
> +inline std::string checkToString(const Twine &S) { return S.str(); }
> +inline std::string checkToString(std::string S) { return S; }
> +inline std::string checkToString(const char *S) { return S; }
> +
> +// To evaluate the second argument lazily, we use C macro.
> +#define CHECK(E, S) check2(E, [&] { return checkToString(S); })
> +
> } // namespace lld
>
> #endif
>
> Modified: lld/trunk/wasm/InputFiles.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputFiles.cpp?rev=319974&r1=319973&r2=319974&view=diff
> ==============================================================================
> --- lld/trunk/wasm/InputFiles.cpp (original)
> +++ lld/trunk/wasm/InputFiles.cpp Wed Dec 6 14:08:17 2017
> @@ -104,7 +104,7 @@ uint32_t ObjFile::relocateGlobalIndex(ui
> void ObjFile::parse() {
> // Parse a memory buffer as a wasm file.
> DEBUG(dbgs() << "Parsing object: " << toString(this) << "\n");
> - std::unique_ptr<Binary> Bin = check(createBinary(MB), toString(this));
> + std::unique_ptr<Binary> Bin = CHECK(createBinary(MB), toString(this));
>
> auto *Obj = dyn_cast<WasmObjectFile>(Bin.get());
> if (!Obj)
> @@ -223,7 +223,7 @@ Symbol *ObjFile::createDefined(const Was
> void ArchiveFile::parse() {
> // Parse a MemoryBufferRef as an archive file.
> DEBUG(dbgs() << "Parsing library: " << toString(this) << "\n");
> - File = check(Archive::create(MB), toString(this));
> + File = CHECK(Archive::create(MB), toString(this));
>
> // Read the symbol table to construct Lazy symbols.
> int Count = 0;
> @@ -236,7 +236,7 @@ void ArchiveFile::parse() {
>
> void ArchiveFile::addMember(const Archive::Symbol *Sym) {
> const Archive::Child &C =
> - check(Sym->getMember(),
> + CHECK(Sym->getMember(),
> "could not get the member for symbol " + Sym->getName());
>
> // Don't try to load the same member twice (this can happen when members
> @@ -248,7 +248,7 @@ void ArchiveFile::addMember(const Archiv
> DEBUG(dbgs() << "from archive: " << toString(this) << "\n");
>
> MemoryBufferRef MB =
> - check(C.getMemoryBufferRef(),
> + CHECK(C.getMemoryBufferRef(),
> "could not get the buffer for the member defining symbol " +
> Sym->getName());
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list