From 5d0c2ffadf84839b951f12a23a163acbd8162d05 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 2 Jul 2015 20:55:21 +0000 Subject: Return ErrorOr from SymbolRef::getName. This function can really fail since the string table offset can be out of bounds. Using ErrorOr makes sure the error is checked. Hopefully a lot of the boilerplate code in tools/* can go away once we have a diagnostic manager in Object. llvm-svn: 241297 --- llvm/lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'llvm/lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp') diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp index 34b6424bebe..c9479b62f7b 100644 --- a/llvm/lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp @@ -30,7 +30,10 @@ public: uint64_t RelType = Rel.getType(); symbol_iterator SymI = Rel.getSymbol(); - StringRef SymName; SymI->getName(SymName); + ErrorOr SymNameOrErr = SymI->getName(); + if (std::error_code EC = SymNameOrErr.getError()) + report_fatal_error(EC.message()); + StringRef SymName = *SymNameOrErr; uint64_t SymAddr; SymI->getAddress(SymAddr); any_relocation_info RE = Obj->getRelocation(Rel.getRawDataRefImpl()); @@ -89,10 +92,11 @@ public: symbol_iterator RSymI = Rel.getSymbol(); uint64_t RSymAddr; RSymI->getAddress(RSymAddr); - StringRef RSymName; - RSymI->getName(RSymName); + ErrorOr RSymName = RSymI->getName(); + if (std::error_code EC = RSymName.getError()) + report_fatal_error(EC.message()); - MCSymbol *RSym = Ctx.getOrCreateSymbol(RSymName); + MCSymbol *RSym = Ctx.getOrCreateSymbol(*RSymName); if (!RSym->isVariable()) RSym->setVariableValue(MCConstantExpr::create(RSymAddr, Ctx)); -- cgit v1.2.3