[llvm] [CodeGen] Fix lpad padding at section start after empty block (PR #112595)

Fabian Parzefall via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 31 10:18:31 PDT 2024


================
@@ -265,8 +265,22 @@ void llvm::sortBasicBlocksAndUpdateBranches(
 // zero implies "no landing pad." This function inserts a NOP just before the EH
 // pad label to ensure a nonzero offset.
 void llvm::avoidZeroOffsetLandingPad(MachineFunction &MF) {
+  std::optional<MBBSectionID> CurrentSection;
+  bool SectionEmpty = true;
+  auto IsFirstNonEmptyBBInSection = [&](const MachineBasicBlock &MBB) {
----------------
pzfl wrote:

Good catch! I was under the impression that basic blocks are assumed to be sorted. Both callsites `avoidZeroOffsetLandingPad` are preceded by a call to `sortBasicBlocksAndUpdateBranches`. However, I see now that `finishAdjustingBasicBlocksAndLandingPads` sorts only by section type, but not by section number. I am not sure how section numbers are used.

Another thing I noticed is that `sortBasicBlocksAndUpdateBranches` calls `assignBeginEndSections`. If this issue already exists where sections are interleaved with each other after sorting, this would incorrectly mark some blocks as section begin as well. But that also means `avoidZeroOffsetLandingPad` should probably keep using `MBB.isBeginSection()`, to not duplicate that behavior if it changes in future.

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


More information about the llvm-commits mailing list