[llvm] [BOLT][NFC] Refactor relocation loop (PR #88424)

Nathan Sidwell via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 11 11:43:18 PDT 2024


https://github.com/urnathan created https://github.com/llvm/llvm-project/pull/88424

Rather than combine 2 rather distinct and negated conditions into a single if, use the std `if () continue;` idiom before falling into the processing.

>From 09874e2308c14d979e1bab1e7410f38785a67e65 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell <nathan at acm.org>
Date: Thu, 11 Apr 2024 14:27:28 -0400
Subject: [PATCH] [BOLT][NFC] Refactor relocation loop

---
 bolt/lib/Rewrite/RewriteInstance.cpp | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 0c8ee0d417233b..6d7b18cc78ef39 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -2305,9 +2305,13 @@ void RewriteInstance::processRelocations() {
     return;
 
   for (const SectionRef &Section : InputFile->sections()) {
-    if (cantFail(Section.getRelocatedSection()) != InputFile->section_end() &&
-        !BinarySection(*BC, Section).isAllocatable())
-      readRelocations(Section);
+    section_iterator SecIter = cantFail(Section.getRelocatedSection());
+    if (SecIter == InputFile->section_end())
+      continue;
+    if (BinarySection(*BC, Section).isAllocatable())
+      continue;
+
+    readRelocations(Section);
   }
 
   if (NumFailedRelocations)



More information about the llvm-commits mailing list