Skip to content

Commit e17bc02

Browse files
committed
[MC] flushPendingLabels: set Atom for new fragment after D71368
Fixes: c26c5e4 (essentially a no-op) The newly created MCDataFragment should inherit Atom (see MCMachOStreamer::finishImpl). To the best of my knowledge, this change cannot be tested at present, but this is important to ensure MCExpr.cpp:AttemptToFoldSymbolOffsetDifference gives the same result in case we evaluate the expression again with a MCAsmLayout. In the following case, ``` .section __DATA,xray_instr_map lxray_sleds_start1: .space 16 Lxray_sleds_end1: .section __DATA,xray_fn_idx .quad (Lxray_sleds_end1-lxray_sleds_start1)>>4 // can be folded without a MCAsmLayout ``` When we have a MCAsmLayout, without this change, evaluating (Lxray_sleds_end1-lxray_sleds_start1)>>4 again will fail due to `FA->getAtom() == nullptr && FB.getAtom() != nullptr` in MachObjectWriter::isSymbolRefDifferenceFullyResolvedImpl, called by AttemptToFoldSymbolOffsetDifference.
1 parent 507efbc commit e17bc02

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

llvm/lib/MC/MCSection.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,13 @@ void MCSection::flushPendingLabels() {
113113
PendingLabel& Label = PendingLabels[0];
114114
iterator CurInsertionPoint =
115115
this->getSubsectionInsertionPoint(Label.Subsection);
116+
const MCSymbol *Atom = nullptr;
117+
if (CurInsertionPoint != begin())
118+
Atom = std::prev(CurInsertionPoint)->getAtom();
116119
MCFragment *F = new MCDataFragment();
117120
getFragmentList().insert(CurInsertionPoint, F);
118121
F->setParent(this);
119-
if (CurInsertionPoint != begin())
120-
F->setAtom(std::prev(CurInsertionPoint)->getAtom());
122+
F->setAtom(Atom);
121123
flushPendingLabels(F, 0, Label.Subsection);
122124
}
123125
}

0 commit comments

Comments
 (0)