[llvm] r236808 - [yaml2elf] Replace error message by assert call in writeSectionContent methods

Simon Atanasyan simon at atanasyan.com
Fri May 8 00:05:04 PDT 2015


Author: atanasyan
Date: Fri May  8 02:05:04 2015
New Revision: 236808

URL: http://llvm.org/viewvc/llvm-project?rev=236808&view=rev
Log:
[yaml2elf] Replace error message by assert call in writeSectionContent methods

Now caller of ELFState::writeSectionContent() methods is responsible to check
a section type and selects an appropriate writeSectionContent method.
So unexpected section type inside writeSectionContent method indicates
a wrong usage of the method and should be guarded by assert.

Modified:
    llvm/trunk/tools/yaml2obj/yaml2elf.cpp

Modified: llvm/trunk/tools/yaml2obj/yaml2elf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2elf.cpp?rev=236808&r1=236807&r2=236808&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2elf.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2elf.cpp Fri May  8 02:05:04 2015
@@ -350,11 +350,9 @@ bool
 ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
                                     const ELFYAML::RelocationSection &Section,
                                     ContiguousBlobAccumulator &CBA) {
-  if (Section.Type != llvm::ELF::SHT_REL &&
-      Section.Type != llvm::ELF::SHT_RELA) {
-    errs() << "error: Invalid relocation section type.\n";
-    return false;
-  }
+  assert((Section.Type == llvm::ELF::SHT_REL ||
+          Section.Type == llvm::ELF::SHT_RELA) &&
+         "Section type is not SHT_REL nor SHT_RELA");
 
   bool IsRela = Section.Type == llvm::ELF::SHT_RELA;
   SHeader.sh_entsize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
@@ -392,10 +390,8 @@ bool ELFState<ELFT>::writeSectionContent
                                          const ELFYAML::Group &Section,
                                          ContiguousBlobAccumulator &CBA) {
   typedef typename object::ELFFile<ELFT>::Elf_Word Elf_Word;
-  if (Section.Type != llvm::ELF::SHT_GROUP) {
-    errs() << "error: Invalid section type.\n";
-    return false;
-  }
+  assert(Section.Type == llvm::ELF::SHT_GROUP &&
+         "Section type is not SHT_GROUP");
 
   SHeader.sh_entsize = sizeof(Elf_Word);
   SHeader.sh_size = SHeader.sh_entsize * Section.Members.size();
@@ -423,10 +419,8 @@ template <class ELFT>
 bool ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
                                          const ELFYAML::MipsABIFlags &Section,
                                          ContiguousBlobAccumulator &CBA) {
-  if (Section.Type != llvm::ELF::SHT_MIPS_ABIFLAGS) {
-    errs() << "error: Invalid section type.\n";
-    return false;
-  }
+  assert(Section.Type == llvm::ELF::SHT_MIPS_ABIFLAGS &&
+         "Section type is not SHT_MIPS_ABIFLAGS");
 
   object::Elf_Mips_ABIFlags<ELFT> Flags;
   zero(Flags);





More information about the llvm-commits mailing list