[lld] a993d60 - [lld-macho][nfc] Add comment explaining why a cast<> is safe

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 21 04:23:19 PDT 2022


Author: Jez Ng
Date: 2022-03-21T07:23:09-04:00
New Revision: a993d607def2592a5f571b185f8cb0382937a0ed

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

LOG: [lld-macho][nfc] Add comment explaining why a cast<> is safe

Added: 
    

Modified: 
    lld/MachO/MarkLive.cpp

Removed: 
    


################################################################################
diff  --git a/lld/MachO/MarkLive.cpp b/lld/MachO/MarkLive.cpp
index 979803f1fe70b..e9b0fd4f7b1a2 100644
--- a/lld/MachO/MarkLive.cpp
+++ b/lld/MachO/MarkLive.cpp
@@ -160,11 +160,16 @@ void MarkLiveImpl<RecordWhyLive>::markTransitively() {
     // Mark things reachable from GC roots as live.
     while (!worklist.empty()) {
       WorklistEntry *entry = worklist.pop_back_val();
-      assert(cast<ConcatInputSection>(getInputSection(entry))->live &&
+      // Entries that get placed onto the worklist always contain
+      // ConcatInputSections. `WhyLiveEntry::prev` may point to entries that
+      // contain other types of InputSections (due to S_ATTR_LIVE_SUPPORT), but
+      // those entries should never be pushed onto the worklist.
+      auto *isec = cast<ConcatInputSection>(getInputSection(entry));
+      assert(isec->live &&
              "We mark as live when pushing onto the worklist!");
 
       // Mark all symbols listed in the relocation table for this section.
-      for (const Reloc &r : getInputSection(entry)->relocs) {
+      for (const Reloc &r : isec->relocs) {
         if (auto *s = r.referent.dyn_cast<Symbol *>())
           addSym(s, entry);
         else


        


More information about the llvm-commits mailing list