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

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 25 20:24:53 PST 2024


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

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`.


>From 0fa4d3204e064bf19a855b13def52f0bf2a16c67 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Thu, 25 Jan 2024 20:24:44 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 lld/ELF/InputSection.h | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h
index dda4242d8be1c1..bb9dff38ae0299 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



More information about the llvm-commits mailing list