[llvm] 7a80c86 - [MC] Remove redundant null check, NFCI (#100928)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 30 22:29:45 PDT 2024


Author: abhishek-kaushik22
Date: 2024-07-31T13:29:42+08:00
New Revision: 7a80c86726f7c37128bfee3618707c1607f5014d

URL: https://github.com/llvm/llvm-project/commit/7a80c86726f7c37128bfee3618707c1607f5014d
DIFF: https://github.com/llvm/llvm-project/commit/7a80c86726f7c37128bfee3618707c1607f5014d.diff

LOG: [MC] Remove redundant null check, NFCI (#100928)

`getOrCreateSymbol` should never return a `nullptr`, add an assert and
remove the redundant null check in the if condition.

Added: 
    

Modified: 
    llvm/lib/MC/MCContext.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index 228c4fb03a276..ac3946b6ef46f 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -697,10 +697,11 @@ MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,
   MCSymbol *COMDATSymbol = nullptr;
   if (!COMDATSymName.empty()) {
     COMDATSymbol = getOrCreateSymbol(COMDATSymName);
+    assert(COMDATSymbol && "COMDATSymbol is null");
     COMDATSymName = COMDATSymbol->getName();
     // A non-associative COMDAT is considered to define the COMDAT symbol. Check
     // the redefinition error.
-    if (Selection != COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE && COMDATSymbol &&
+    if (Selection != COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE &&
         COMDATSymbol->isDefined() &&
         (!COMDATSymbol->isInSection() ||
          cast<MCSectionCOFF>(COMDATSymbol->getSection()).getCOMDATSymbol() !=


        


More information about the llvm-commits mailing list