[lld] [ELF] Improve comment of InputSection::file and update getFile. NFC (PR #79550)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 25 20:25:22 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lld

Author: Fangrui Song (MaskRay)

<details>
<summary>Changes</summary>

Clarify a comment after #<!-- -->78944.

All uses of `getFile()` assert `file` is non-null. It is not used with a
synthetic section. Replace `cast_or_null` with `cast`.


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


1 Files Affected:

- (modified) lld/ELF/InputSection.h (+5-4) 


``````````diff
diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h
index dda4242d8be1c1f..bb9dff38ae02995 100644
--- a/lld/ELF/InputSection.h
+++ b/lld/ELF/InputSection.h
@@ -118,9 +118,9 @@ class InputSectionBase : public SectionBase {
 
   static bool classof(const SectionBase *s) { return s->kind() != Output; }
 
-  // The file which contains this section. Its dynamic type is always
-  // ObjFile<ELFT>, but in order to avoid ELFT, we use InputFile as
-  // its static type.
+  // The file which contains this section. Its dynamic type is usually
+  // ObjFile<ELFT>, but may be an InputFile of InternalKind (for a synthetic
+  // section).
   InputFile *file;
 
   // Input sections are part of an output section. Special sections
@@ -132,8 +132,9 @@ class InputSectionBase : public SectionBase {
   // Section index of the relocation section if exists.
   uint32_t relSecIdx = 0;
 
+  // Getter when the dynamic type is ObjFile<ELFT>.
   template <class ELFT> ObjFile<ELFT> *getFile() const {
-    return cast_or_null<ObjFile<ELFT>>(file);
+    return cast<ObjFile<ELFT>>(file);
   }
 
   // Used by --optimize-bb-jumps and RISC-V linker relaxation temporarily to

``````````

</details>


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


More information about the llvm-commits mailing list