Skip to content

Commit db48f1a

Browse files
committed
[MC] Remove nullable getCurrentSectionOnly use from AsmParser
We will implement getCurrentSectionOnly with `CurFrag->getParent()`, which is non-null. Eliminate a nullable use.
1 parent 5221634 commit db48f1a

File tree

7 files changed

+24
-24
lines changed

7 files changed

+24
-24
lines changed

llvm/include/llvm/MC/MCObjectStreamer.h

-4
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ class MCAssembler;
2626
class MCCodeEmitter;
2727
class MCSubtargetInfo;
2828
class MCExpr;
29-
class MCFragment;
30-
class MCDataFragment;
3129
class MCAsmBackend;
3230
class raw_ostream;
3331
class raw_pwrite_stream;
@@ -85,8 +83,6 @@ class MCObjectStreamer : public MCStreamer {
8583
void emitFrames(MCAsmBackend *MAB);
8684
void emitCFISections(bool EH, bool Debug) override;
8785

88-
MCFragment *getCurrentFragment() const;
89-
9086
void insert(MCFragment *F) {
9187
auto *Sec = CurFrag->getParent();
9288
F->setParent(Sec);

llvm/include/llvm/MC/MCStreamer.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,15 @@ class MCStreamer {
255255
/// discussion for future inclusion.
256256
bool AllowAutoPadding = false;
257257

258-
/// This is called by popSection and switchSection, if the current
259-
/// section changes.
260-
virtual void changeSection(MCSection *, uint32_t);
261-
262258
protected:
263259
MCFragment *CurFrag = nullptr;
264260

265261
MCStreamer(MCContext &Ctx);
266262

263+
/// This is called by popSection and switchSection, if the current
264+
/// section changes.
265+
virtual void changeSection(MCSection *, uint32_t);
266+
267267
virtual void emitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
268268
virtual void emitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
269269

@@ -408,6 +408,8 @@ class MCStreamer {
408408
return MCSectionSubPair();
409409
}
410410

411+
MCFragment *getCurrentFragment() const;
412+
411413
/// Returns an index to represent the order a symbol was emitted in.
412414
/// (zero if we did not emit that symbol)
413415
unsigned getSymbolOrder(const MCSymbol *Sym) const {

llvm/lib/MC/MCAsmStreamer.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,7 @@ void MCAsmStreamer::emitExplicitComments() {
511511
}
512512

513513
void MCAsmStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
514-
assert(Section && "Cannot switch to a null section!");
515-
CurFrag = &Section->getDummyFragment();
514+
MCStreamer::changeSection(Section, Subsection);
516515
if (MCTargetStreamer *TS = getTargetStreamer()) {
517516
TS->changeSection(getCurrentSectionOnly(), Section, Subsection, OS);
518517
} else {

llvm/lib/MC/MCELFStreamer.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,14 @@ static void setSectionAlignmentForBundling(const MCAssembler &Assembler,
107107
}
108108

109109
void MCELFStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
110-
MCSection *CurSection = getCurrentSectionOnly();
111-
if (CurSection && isBundleLocked())
112-
report_fatal_error("Unterminated .bundle_lock when changing a section");
113-
114110
MCAssembler &Asm = getAssembler();
115-
// Ensure the previous section gets aligned if necessary.
116-
setSectionAlignmentForBundling(Asm, CurSection);
111+
if (auto *F = getCurrentFragment()) {
112+
if (isBundleLocked())
113+
report_fatal_error("Unterminated .bundle_lock when changing a section");
114+
115+
// Ensure the previous section gets aligned if necessary.
116+
setSectionAlignmentForBundling(Asm, F->getParent());
117+
}
117118
auto *SectionELF = static_cast<const MCSectionELF *>(Section);
118119
const MCSymbol *Grp = SectionELF->getGroup();
119120
if (Grp)

llvm/lib/MC/MCObjectStreamer.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,6 @@ void MCObjectStreamer::emitFrames(MCAsmBackend *MAB) {
142142
MCDwarfFrameEmitter::Emit(*this, MAB, false);
143143
}
144144

145-
MCFragment *MCObjectStreamer::getCurrentFragment() const {
146-
assert(!getCurrentSection().first ||
147-
CurFrag->getParent() == getCurrentSection().first);
148-
return CurFrag;
149-
}
150-
151145
static bool canReuseDataFragment(const MCDataFragment &F,
152146
const MCAssembler &Assembler,
153147
const MCSubtargetInfo *STI) {

llvm/lib/MC/MCParser/AsmParser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) {
10821082
}
10831083

10841084
bool AsmParser::checkForValidSection() {
1085-
if (!ParsingMSInlineAsm && !getStreamer().getCurrentSectionOnly()) {
1085+
if (!ParsingMSInlineAsm && !getStreamer().getCurrentFragment()) {
10861086
Out.initSections(false, getTargetParser().getSTI());
10871087
return Error(getTok().getLoc(),
10881088
"expected section directive before assembly directive");

llvm/lib/MC/MCStreamer.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ ArrayRef<MCDwarfFrameInfo> MCStreamer::getDwarfFrameInfos() const {
118118
return DwarfFrameInfos;
119119
}
120120

121+
MCFragment *MCStreamer::getCurrentFragment() const {
122+
assert(!getCurrentSection().first ||
123+
CurFrag->getParent() == getCurrentSection().first);
124+
return CurFrag;
125+
}
126+
121127
void MCStreamer::emitRawComment(const Twine &T, bool TabPrefix) {}
122128

123129
void MCStreamer::addExplicitComment(const Twine &T) {}
@@ -1218,7 +1224,9 @@ void MCStreamer::emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
12181224
Align ByteAlignment) {}
12191225
void MCStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
12201226
uint64_t Size, Align ByteAlignment) {}
1221-
void MCStreamer::changeSection(MCSection *, uint32_t) {}
1227+
void MCStreamer::changeSection(MCSection *Section, uint32_t) {
1228+
CurFrag = &Section->getDummyFragment();
1229+
}
12221230
void MCStreamer::emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {}
12231231
void MCStreamer::emitBytes(StringRef Data) {}
12241232
void MCStreamer::emitBinaryData(StringRef Data) { emitBytes(Data); }

0 commit comments

Comments
 (0)