[llvm] db48f1a - [MC] Remove nullable getCurrentSectionOnly use from AsmParser
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 27 22:37:42 PDT 2024
Author: Fangrui Song
Date: 2024-06-27T22:37:37-07:00
New Revision: db48f1a1764023f8efeb055e343b967d1eb37d19
URL: https://github.com/llvm/llvm-project/commit/db48f1a1764023f8efeb055e343b967d1eb37d19
DIFF: https://github.com/llvm/llvm-project/commit/db48f1a1764023f8efeb055e343b967d1eb37d19.diff
LOG: [MC] Remove nullable getCurrentSectionOnly use from AsmParser
We will implement getCurrentSectionOnly with `CurFrag->getParent()`,
which is non-null. Eliminate a nullable use.
Added:
Modified:
llvm/include/llvm/MC/MCObjectStreamer.h
llvm/include/llvm/MC/MCStreamer.h
llvm/lib/MC/MCAsmStreamer.cpp
llvm/lib/MC/MCELFStreamer.cpp
llvm/lib/MC/MCObjectStreamer.cpp
llvm/lib/MC/MCParser/AsmParser.cpp
llvm/lib/MC/MCStreamer.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCObjectStreamer.h b/llvm/include/llvm/MC/MCObjectStreamer.h
index df50ad0ae84f3..4241ec1e1881b 100644
--- a/llvm/include/llvm/MC/MCObjectStreamer.h
+++ b/llvm/include/llvm/MC/MCObjectStreamer.h
@@ -26,8 +26,6 @@ class MCAssembler;
class MCCodeEmitter;
class MCSubtargetInfo;
class MCExpr;
-class MCFragment;
-class MCDataFragment;
class MCAsmBackend;
class raw_ostream;
class raw_pwrite_stream;
@@ -85,8 +83,6 @@ class MCObjectStreamer : public MCStreamer {
void emitFrames(MCAsmBackend *MAB);
void emitCFISections(bool EH, bool Debug) override;
- MCFragment *getCurrentFragment() const;
-
void insert(MCFragment *F) {
auto *Sec = CurFrag->getParent();
F->setParent(Sec);
diff --git a/llvm/include/llvm/MC/MCStreamer.h b/llvm/include/llvm/MC/MCStreamer.h
index a42f0ec55ff7c..5c091dbdafe96 100644
--- a/llvm/include/llvm/MC/MCStreamer.h
+++ b/llvm/include/llvm/MC/MCStreamer.h
@@ -255,15 +255,15 @@ class MCStreamer {
/// discussion for future inclusion.
bool AllowAutoPadding = false;
- /// This is called by popSection and switchSection, if the current
- /// section changes.
- virtual void changeSection(MCSection *, uint32_t);
-
protected:
MCFragment *CurFrag = nullptr;
MCStreamer(MCContext &Ctx);
+ /// This is called by popSection and switchSection, if the current
+ /// section changes.
+ virtual void changeSection(MCSection *, uint32_t);
+
virtual void emitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
virtual void emitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
@@ -408,6 +408,8 @@ class MCStreamer {
return MCSectionSubPair();
}
+ MCFragment *getCurrentFragment() const;
+
/// Returns an index to represent the order a symbol was emitted in.
/// (zero if we did not emit that symbol)
unsigned getSymbolOrder(const MCSymbol *Sym) const {
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index 31994e5247b9d..038217e023d44 100644
--- a/llvm/lib/MC/MCAsmStreamer.cpp
+++ b/llvm/lib/MC/MCAsmStreamer.cpp
@@ -511,8 +511,7 @@ void MCAsmStreamer::emitExplicitComments() {
}
void MCAsmStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
- assert(Section && "Cannot switch to a null section!");
- CurFrag = &Section->getDummyFragment();
+ MCStreamer::changeSection(Section, Subsection);
if (MCTargetStreamer *TS = getTargetStreamer()) {
TS->changeSection(getCurrentSectionOnly(), Section, Subsection, OS);
} else {
diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp
index b88a5723de691..6d30f2efcc7de 100644
--- a/llvm/lib/MC/MCELFStreamer.cpp
+++ b/llvm/lib/MC/MCELFStreamer.cpp
@@ -107,13 +107,14 @@ static void setSectionAlignmentForBundling(const MCAssembler &Assembler,
}
void MCELFStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
- MCSection *CurSection = getCurrentSectionOnly();
- if (CurSection && isBundleLocked())
- report_fatal_error("Unterminated .bundle_lock when changing a section");
-
MCAssembler &Asm = getAssembler();
- // Ensure the previous section gets aligned if necessary.
- setSectionAlignmentForBundling(Asm, CurSection);
+ if (auto *F = getCurrentFragment()) {
+ if (isBundleLocked())
+ report_fatal_error("Unterminated .bundle_lock when changing a section");
+
+ // Ensure the previous section gets aligned if necessary.
+ setSectionAlignmentForBundling(Asm, F->getParent());
+ }
auto *SectionELF = static_cast<const MCSectionELF *>(Section);
const MCSymbol *Grp = SectionELF->getGroup();
if (Grp)
diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
index cd5e049958d23..afe5da6e5fbb9 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -142,12 +142,6 @@ void MCObjectStreamer::emitFrames(MCAsmBackend *MAB) {
MCDwarfFrameEmitter::Emit(*this, MAB, false);
}
-MCFragment *MCObjectStreamer::getCurrentFragment() const {
- assert(!getCurrentSection().first ||
- CurFrag->getParent() == getCurrentSection().first);
- return CurFrag;
-}
-
static bool canReuseDataFragment(const MCDataFragment &F,
const MCAssembler &Assembler,
const MCSubtargetInfo *STI) {
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index 6e7ec68c44975..72cf59f7f583b 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -1082,7 +1082,7 @@ bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) {
}
bool AsmParser::checkForValidSection() {
- if (!ParsingMSInlineAsm && !getStreamer().getCurrentSectionOnly()) {
+ if (!ParsingMSInlineAsm && !getStreamer().getCurrentFragment()) {
Out.initSections(false, getTargetParser().getSTI());
return Error(getTok().getLoc(),
"expected section directive before assembly directive");
diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp
index c0879fd3a698c..91adc42dc1ba1 100644
--- a/llvm/lib/MC/MCStreamer.cpp
+++ b/llvm/lib/MC/MCStreamer.cpp
@@ -118,6 +118,12 @@ ArrayRef<MCDwarfFrameInfo> MCStreamer::getDwarfFrameInfos() const {
return DwarfFrameInfos;
}
+MCFragment *MCStreamer::getCurrentFragment() const {
+ assert(!getCurrentSection().first ||
+ CurFrag->getParent() == getCurrentSection().first);
+ return CurFrag;
+}
+
void MCStreamer::emitRawComment(const Twine &T, bool TabPrefix) {}
void MCStreamer::addExplicitComment(const Twine &T) {}
@@ -1218,7 +1224,9 @@ void MCStreamer::emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Align ByteAlignment) {}
void MCStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
uint64_t Size, Align ByteAlignment) {}
-void MCStreamer::changeSection(MCSection *, uint32_t) {}
+void MCStreamer::changeSection(MCSection *Section, uint32_t) {
+ CurFrag = &Section->getDummyFragment();
+}
void MCStreamer::emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {}
void MCStreamer::emitBytes(StringRef Data) {}
void MCStreamer::emitBinaryData(StringRef Data) { emitBytes(Data); }
More information about the llvm-commits
mailing list