[lld] r312391 - COFF: simplify thunk handling (NFC)

Saleem Abdulrasool via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 1 16:35:43 PDT 2017


Author: compnerd
Date: Fri Sep  1 16:35:43 2017
New Revision: 312391

URL: http://llvm.org/viewvc/llvm-project?rev=312391&view=rev
Log:
COFF: simplify thunk handling (NFC)

Apply the simplification suggestions that Peter Collingbourne made
during the review at D37368.  The returned thunk is cast to the
appropriate type in the SymbolTable, and the constant symbol's body is
not needed directly, so avoid the assignment.  NFC

Modified:
    lld/trunk/COFF/InputFiles.cpp
    lld/trunk/COFF/InputFiles.h
    lld/trunk/COFF/SymbolTable.cpp
    lld/trunk/COFF/SymbolTable.h

Modified: lld/trunk/COFF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=312391&r1=312390&r2=312391&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.cpp (original)
+++ lld/trunk/COFF/InputFiles.cpp Fri Sep  1 16:35:43 2017
@@ -355,19 +355,16 @@ void ImportFile::parse() {
   this->Hdr = Hdr;
   ExternalName = ExtName;
 
-  if (Symbol *S = Symtab->addImportData(ImpName, this))
-    ImpSym = cast<DefinedImportData>(S->body());
+  ImpSym = Symtab->addImportData(ImpName, this);
 
   if (Hdr->getType() == llvm::COFF::IMPORT_CONST)
-    if (Symbol *S = Symtab->addImportData(Name, this))
-      ConstSym = cast<DefinedImportData>(S->body());
+    static_cast<void>(Symtab->addImportData(Name, this));
 
   // If type is function, we need to create a thunk which jump to an
   // address pointed by the __imp_ symbol. (This allows you to call
   // DLL functions just like regular non-DLL functions.)
   if (Hdr->getType() == llvm::COFF::IMPORT_CODE)
-    if (Symbol *S = Symtab->addImportThunk(Name, ImpSym, Hdr->Machine))
-      ThunkSym = cast<DefinedImportThunk>(S->body());
+    ThunkSym = Symtab->addImportThunk(Name, ImpSym, Hdr->Machine);
 }
 
 void BitcodeFile::parse() {

Modified: lld/trunk/COFF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.h?rev=312391&r1=312390&r2=312391&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.h (original)
+++ lld/trunk/COFF/InputFiles.h Fri Sep  1 16:35:43 2017
@@ -186,7 +186,6 @@ public:
   static std::vector<ImportFile *> Instances;
 
   DefinedImportData *ImpSym = nullptr;
-  DefinedImportData *ConstSym = nullptr;
   DefinedImportThunk *ThunkSym = nullptr;
   std::string DLLName;
 

Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=312391&r1=312390&r2=312391&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Fri Sep  1 16:35:43 2017
@@ -269,29 +269,30 @@ Symbol *SymbolTable::addCommon(InputFile
   return S;
 }
 
-Symbol *SymbolTable::addImportData(StringRef N, ImportFile *F) {
+DefinedImportData *SymbolTable::addImportData(StringRef N, ImportFile *F) {
   Symbol *S;
   bool WasInserted;
   std::tie(S, WasInserted) = insert(N);
   S->IsUsedInRegularObj = true;
   if (WasInserted || isa<Undefined>(S->body()) || isa<Lazy>(S->body())) {
     replaceBody<DefinedImportData>(S, N, F);
-    return S;
+    return cast<DefinedImportData>(S->body());
   }
 
   reportDuplicate(S, F);
   return nullptr;
 }
 
-Symbol *SymbolTable::addImportThunk(StringRef Name, DefinedImportData *ID,
-                                    uint16_t Machine) {
+DefinedImportThunk *SymbolTable::addImportThunk(StringRef Name,
+                                               DefinedImportData *ID,
+                                               uint16_t Machine) {
   Symbol *S;
   bool WasInserted;
   std::tie(S, WasInserted) = insert(Name);
   S->IsUsedInRegularObj = true;
   if (WasInserted || isa<Undefined>(S->body()) || isa<Lazy>(S->body())) {
     replaceBody<DefinedImportThunk>(S, Name, ID, Machine);
-    return S;
+    return cast<DefinedImportThunk>(S->body());
   }
 
   reportDuplicate(S, ID->File);

Modified: lld/trunk/COFF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.h?rev=312391&r1=312390&r2=312391&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.h (original)
+++ lld/trunk/COFF/SymbolTable.h Fri Sep  1 16:35:43 2017
@@ -90,9 +90,9 @@ public:
   Symbol *addCommon(InputFile *F, StringRef N, uint64_t Size,
                     const llvm::object::coff_symbol_generic *S = nullptr,
                     CommonChunk *C = nullptr);
-  Symbol *addImportData(StringRef N, ImportFile *F);
-  Symbol *addImportThunk(StringRef Name, DefinedImportData *S,
-                         uint16_t Machine);
+  DefinedImportData *addImportData(StringRef N, ImportFile *F);
+  DefinedImportThunk *addImportThunk(StringRef Name, DefinedImportData *S,
+                                     uint16_t Machine);
 
   void reportDuplicate(Symbol *Existing, InputFile *NewFile);
 




More information about the llvm-commits mailing list