Skip to content

Commit 92769d8

Browse files
kazutakahiratackoparkar
authored andcommitted
[MC] Remove SMRange(std::nullopt_t) (llvm#165832)
This patch removes SMRange(std::nullopt_t) to reduce the number of uses of std::nullopt outside the context of std::optional. Since there are only a handful of uses, this patch removes the constructor without going through deprecation. The use of std::nullopt here has its root in llvm::None, which was used as a convenient way to indicate "nothing" before we migrated llvm::Optional to std::optional.
1 parent 07160fa commit 92769d8

File tree

8 files changed

+21
-30
lines changed

8 files changed

+21
-30
lines changed

llvm/include/llvm/MC/MCParser/MCAsmParser.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,28 +209,25 @@ class LLVM_ABI MCAsmParser {
209209
MCInstPrinter *IP, MCAsmParserSemaCallback &SI) = 0;
210210

211211
/// Emit a note at the location \p L, with the message \p Msg.
212-
virtual void Note(SMLoc L, const Twine &Msg,
213-
SMRange Range = std::nullopt) = 0;
212+
virtual void Note(SMLoc L, const Twine &Msg, SMRange Range = {}) = 0;
214213

215214
/// Emit a warning at the location \p L, with the message \p Msg.
216215
///
217216
/// \return The return value is true, if warnings are fatal.
218-
virtual bool Warning(SMLoc L, const Twine &Msg,
219-
SMRange Range = std::nullopt) = 0;
217+
virtual bool Warning(SMLoc L, const Twine &Msg, SMRange Range = {}) = 0;
220218

221219
/// Return an error at the location \p L, with the message \p Msg. This
222220
/// may be modified before being emitted.
223221
///
224222
/// \return The return value is always true, as an idiomatic convenience to
225223
/// clients.
226-
bool Error(SMLoc L, const Twine &Msg, SMRange Range = std::nullopt);
224+
bool Error(SMLoc L, const Twine &Msg, SMRange Range = {});
227225

228226
/// Emit an error at the location \p L, with the message \p Msg.
229227
///
230228
/// \return The return value is always true, as an idiomatic convenience to
231229
/// clients.
232-
virtual bool printError(SMLoc L, const Twine &Msg,
233-
SMRange Range = std::nullopt) = 0;
230+
virtual bool printError(SMLoc L, const Twine &Msg, SMRange Range = {}) = 0;
234231

235232
bool hasPendingError() { return !PendingErrors.empty(); }
236233

@@ -255,7 +252,7 @@ class LLVM_ABI MCAsmParser {
255252
const AsmToken &getTok() const;
256253

257254
/// Report an error at the current lexer location.
258-
bool TokError(const Twine &Msg, SMRange Range = std::nullopt);
255+
bool TokError(const Twine &Msg, SMRange Range = {});
259256

260257
bool parseTokenLoc(SMLoc &Loc);
261258
bool parseToken(AsmToken::TokenKind T, const Twine &Msg = "unexpected token");

llvm/include/llvm/Support/SMLoc.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#define LLVM_SUPPORT_SMLOC_H
1616

1717
#include <cassert>
18-
#include <optional>
1918

2019
namespace llvm {
2120

@@ -50,7 +49,6 @@ class SMRange {
5049
SMLoc Start, End;
5150

5251
SMRange() = default;
53-
SMRange(std::nullopt_t) {}
5452
SMRange(SMLoc St, SMLoc En) : Start(St), End(En) {
5553
assert(Start.isValid() == End.isValid() &&
5654
"Start and End should either both be valid or both be invalid!");

llvm/lib/FileCheck/FileCheckImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ class ErrorDiagnostic : public ErrorInfo<ErrorDiagnostic> {
528528
SMRange getRange() const { return Range; }
529529

530530
static Error get(const SourceMgr &SM, SMLoc Loc, const Twine &ErrMsg,
531-
SMRange Range = std::nullopt) {
531+
SMRange Range = {}) {
532532
return make_error<ErrorDiagnostic>(
533533
SM.GetMessage(Loc, SourceMgr::DK_Error, ErrMsg), Range);
534534
}

llvm/lib/MC/MCParser/AsmParser.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,9 @@ class AsmParser : public MCAsmParser {
228228
AssemblerDialect = i;
229229
}
230230

231-
void Note(SMLoc L, const Twine &Msg, SMRange Range = std::nullopt) override;
232-
bool Warning(SMLoc L, const Twine &Msg,
233-
SMRange Range = std::nullopt) override;
234-
bool printError(SMLoc L, const Twine &Msg,
235-
SMRange Range = std::nullopt) override;
231+
void Note(SMLoc L, const Twine &Msg, SMRange Range = {}) override;
232+
bool Warning(SMLoc L, const Twine &Msg, SMRange Range = {}) override;
233+
bool printError(SMLoc L, const Twine &Msg, SMRange Range = {}) override;
236234

237235
const AsmToken &Lex() override;
238236

@@ -312,7 +310,7 @@ class AsmParser : public MCAsmParser {
312310

313311
void printMacroInstantiations();
314312
void printMessage(SMLoc Loc, SourceMgr::DiagKind Kind, const Twine &Msg,
315-
SMRange Range = std::nullopt) const {
313+
SMRange Range = {}) const {
316314
ArrayRef<SMRange> Ranges(Range);
317315
SrcMgr.PrintMessage(Loc, Kind, Msg, Ranges);
318316
}

llvm/lib/MC/MCParser/MasmParser.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -483,11 +483,9 @@ class MasmParser : public MCAsmParser {
483483
AssemblerDialect = i;
484484
}
485485

486-
void Note(SMLoc L, const Twine &Msg, SMRange Range = std::nullopt) override;
487-
bool Warning(SMLoc L, const Twine &Msg,
488-
SMRange Range = std::nullopt) override;
489-
bool printError(SMLoc L, const Twine &Msg,
490-
SMRange Range = std::nullopt) override;
486+
void Note(SMLoc L, const Twine &Msg, SMRange Range = {}) override;
487+
bool Warning(SMLoc L, const Twine &Msg, SMRange Range = {}) override;
488+
bool printError(SMLoc L, const Twine &Msg, SMRange Range = {}) override;
491489

492490
enum ExpandKind { ExpandMacros, DoNotExpandMacros };
493491
const AsmToken &Lex(ExpandKind ExpandNextToken);
@@ -592,7 +590,7 @@ class MasmParser : public MCAsmParser {
592590
bool expandStatement(SMLoc Loc);
593591

594592
void printMessage(SMLoc Loc, SourceMgr::DiagKind Kind, const Twine &Msg,
595-
SMRange Range = std::nullopt) const {
593+
SMRange Range = {}) const {
596594
ArrayRef<SMRange> Ranges(Range);
597595
SrcMgr.PrintMessage(Loc, Kind, Msg, Ranges);
598596
}

llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,15 +426,15 @@ class ARMAsmParser : public MCTargetAsmParser {
426426
VPTState.CurPosition = ~0U;
427427
}
428428

429-
void Note(SMLoc L, const Twine &Msg, SMRange Range = std::nullopt) {
429+
void Note(SMLoc L, const Twine &Msg, SMRange Range = {}) {
430430
return getParser().Note(L, Msg, Range);
431431
}
432432

433-
bool Warning(SMLoc L, const Twine &Msg, SMRange Range = std::nullopt) {
433+
bool Warning(SMLoc L, const Twine &Msg, SMRange Range = {}) {
434434
return getParser().Warning(L, Msg, Range);
435435
}
436436

437-
bool Error(SMLoc L, const Twine &Msg, SMRange Range = std::nullopt) {
437+
bool Error(SMLoc L, const Twine &Msg, SMRange Range = {}) {
438438
return getParser().Error(L, Msg, Range);
439439
}
440440

llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ class X86AsmParser : public MCTargetAsmParser {
11211121
void setTypeInfo(AsmTypeInfo Type) { CurType = Type; }
11221122
};
11231123

1124-
bool Error(SMLoc L, const Twine &Msg, SMRange Range = std::nullopt,
1124+
bool Error(SMLoc L, const Twine &Msg, SMRange Range = {},
11251125
bool MatchingInlineAsm = false) {
11261126
MCAsmParser &Parser = getParser();
11271127
if (MatchingInlineAsm) {
@@ -4322,7 +4322,7 @@ bool X86AsmParser::matchAndEmitATTInstruction(
43224322
SMLoc IDLoc, unsigned &Opcode, MCInst &Inst, OperandVector &Operands,
43234323
MCStreamer &Out, uint64_t &ErrorInfo, bool MatchingInlineAsm) {
43244324
X86Operand &Op = static_cast<X86Operand &>(*Operands[0]);
4325-
SMRange EmptyRange = std::nullopt;
4325+
SMRange EmptyRange;
43264326
// In 16-bit mode, if data32 is specified, temporarily switch to 32-bit mode
43274327
// when matching the instruction.
43284328
if (ForcedDataPrefix == X86::Is32Bit)
@@ -4548,7 +4548,7 @@ bool X86AsmParser::matchAndEmitIntelInstruction(
45484548
SMLoc IDLoc, unsigned &Opcode, MCInst &Inst, OperandVector &Operands,
45494549
MCStreamer &Out, uint64_t &ErrorInfo, bool MatchingInlineAsm) {
45504550
X86Operand &Op = static_cast<X86Operand &>(*Operands[0]);
4551-
SMRange EmptyRange = std::nullopt;
4551+
SMRange EmptyRange;
45524552
// Find one unsized memory operand, if present.
45534553
X86Operand *UnsizedMemOp = nullptr;
45544554
for (const auto &Op : Operands) {

llvm/utils/TableGen/AsmMatcherEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4164,7 +4164,7 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
41644164
OS << " MII.getDeprecatedInfo(Inst, getSTI(), Info)) {\n";
41654165
OS << " SMLoc Loc = ((" << Target.getName()
41664166
<< "Operand &)*Operands[0]).getStartLoc();\n";
4167-
OS << " getParser().Warning(Loc, Info, std::nullopt);\n";
4167+
OS << " getParser().Warning(Loc, Info, {});\n";
41684168
OS << " }\n";
41694169
}
41704170

0 commit comments

Comments
 (0)