[llvm] fcffb2c - [MC] Replace one nullable getCurrentSectionOnly with CurFrag

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 27 22:27:19 PDT 2024


Author: Fangrui Song
Date: 2024-06-27T22:27:14-07:00
New Revision: fcffb2c0240bb3a08b3e14486ea6abd23fa2c44f

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

LOG: [MC] Replace one nullable getCurrentSectionOnly with CurFrag

We will implement getCurrentSectionOnly with `CurFrag->getParent()`,
which is non-null. Eliminate a nullable use.

Added: 
    

Modified: 
    llvm/lib/MC/MCELFStreamer.cpp
    llvm/lib/MC/MCObjectStreamer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp
index bf3edcce2e05c..b88a5723de691 100644
--- a/llvm/lib/MC/MCELFStreamer.cpp
+++ b/llvm/lib/MC/MCELFStreamer.cpp
@@ -628,8 +628,8 @@ void MCELFStreamer::finishImpl() {
   }
 
   // Ensure the last section gets aligned if necessary.
-  MCSection *CurSection = getCurrentSectionOnly();
-  setSectionAlignmentForBundling(getAssembler(), CurSection);
+  if (MCFragment *F = getCurrentFragment())
+    setSectionAlignmentForBundling(getAssembler(), F->getParent());
 
   finalizeCGProfile();
   emitFrames(nullptr);

diff  --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
index 6dddaa427a97d..cd5e049958d23 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -143,7 +143,8 @@ void MCObjectStreamer::emitFrames(MCAsmBackend *MAB) {
 }
 
 MCFragment *MCObjectStreamer::getCurrentFragment() const {
-  assert(CurFrag->getParent() == getCurrentSection().first);
+  assert(!getCurrentSection().first ||
+         CurFrag->getParent() == getCurrentSection().first);
   return CurFrag;
 }
 


        


More information about the llvm-commits mailing list