[llvm] Remote redundant null check (PR #100928)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 28 05:13:04 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mc

Author: None (abhishek-kaushik22)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/100928.diff


1 Files Affected:

- (modified) llvm/lib/MC/MCContext.cpp (+2-1) 


``````````diff
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() !=

``````````

</details>


https://github.com/llvm/llvm-project/pull/100928


More information about the llvm-commits mailing list