[lld] r241000 - [cleanup] Clean up the flow of creating a symbol body for regular symbols.

Chandler Carruth chandlerc at gmail.com
Mon Jun 29 14:32:37 PDT 2015


Author: chandlerc
Date: Mon Jun 29 16:32:37 2015
New Revision: 241000

URL: http://llvm.org/viewvc/llvm-project?rev=241000&view=rev
Log:
[cleanup] Clean up the flow of creating a symbol body for regular symbols.

This uses a single cast and test to get the section for the symbol, and
uses the cast_or_null<> pattern throughout to handle the known type but
unknown non-null-ness.

No functionality changed.

Differential Revision: http://reviews.llvm.org/D10791

Modified:
    lld/trunk/COFF/InputFiles.cpp

Modified: lld/trunk/COFF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=241000&r1=240999&r2=241000&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.cpp (original)
+++ lld/trunk/COFF/InputFiles.cpp Mon Jun 29 16:32:37 2015
@@ -206,26 +206,26 @@ SymbolBody *ObjectFile::createSymbolBody
     auto *Aux = (const coff_aux_weak_external *)AuxP;
     return new (Alloc) Undefined(Name, &SparseSymbolBodies[Aux->TagIndex]);
   }
+
+  // Nothing else to do without a section chunk.
+  auto *SC = cast_or_null<SectionChunk>(SparseChunks[Sym.getSectionNumber()]);
+  if (!SC)
+    return nullptr;
+
   // Handle associative sections
   if (IsFirst && AuxP) {
-    if (Chunk *C = SparseChunks[Sym.getSectionNumber()]) {
-      auto *Aux = reinterpret_cast<const coff_aux_section_definition *>(AuxP);
-      if (Aux->Selection == IMAGE_COMDAT_SELECT_ASSOCIATIVE) {
-        auto *Parent =
-          (SectionChunk *)(SparseChunks[Aux->getNumber(Sym.isBigObj())]);
-        if (Parent)
-          Parent->addAssociative((SectionChunk *)C);
-      }
-    }
-  }
-  Chunk *C = SparseChunks[Sym.getSectionNumber()];
-  if (auto *SC = cast_or_null<SectionChunk>(C)) {
-    auto *B = new (Alloc) DefinedRegular(this, Sym, SC);
-    if (SC->isCOMDAT() && Sym.getValue() == 0 && !AuxP)
-      SC->setSymbol(B);
-    return B;
+    auto *Aux = reinterpret_cast<const coff_aux_section_definition *>(AuxP);
+    if (Aux->Selection == IMAGE_COMDAT_SELECT_ASSOCIATIVE)
+      if (auto *ParentSC = cast_or_null<SectionChunk>(
+              SparseChunks[Aux->getNumber(Sym.isBigObj())]))
+        ParentSC->addAssociative(SC);
   }
-  return nullptr;
+
+  auto *B = new (Alloc) DefinedRegular(this, Sym, SC);
+  if (SC->isCOMDAT() && Sym.getValue() == 0 && !AuxP)
+    SC->setSymbol(B);
+
+  return B;
 }
 
 std::error_code ImportFile::parse() {





More information about the llvm-commits mailing list