From f43cc9f8b5d8ebe7d02dba63ceaddf28118860eb Mon Sep 17 00:00:00 2001 From: Nirav Dave Date: Mon, 10 Oct 2016 15:24:54 +0000 Subject: [PATCH] Add return type for checkForValidSection parsing function. NFC Intended. llvm-svn: 283761 --- llvm/include/llvm/MC/MCParser/MCAsmParser.h | 3 +- llvm/lib/MC/MCParser/AsmParser.cpp | 76 +++++++++++++---------------- 2 files changed, 37 insertions(+), 42 deletions(-) diff --git a/llvm/include/llvm/MC/MCParser/MCAsmParser.h b/llvm/include/llvm/MC/MCParser/MCAsmParser.h index 1106185..7b76b46 100644 --- a/llvm/include/llvm/MC/MCParser/MCAsmParser.h +++ b/llvm/include/llvm/MC/MCParser/MCAsmParser.h @@ -235,7 +235,8 @@ public: /// \brief Ensure that we have a valid section set in the streamer. Otherwise, /// report an error and switch to .text. - virtual void checkForValidSection() = 0; + /// \return - False on success. + virtual bool checkForValidSection() = 0; /// \brief Parse an arbitrary expression of a specified parenthesis depth, /// assuming that the initial '(' characters have already been consumed. diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp index 794c295..f4de634 100644 --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -281,7 +281,7 @@ public: bool parseIdentifier(StringRef &Res) override; void eatToEndOfStatement() override; - void checkForValidSection() override; + bool checkForValidSection() override; /// } @@ -828,12 +828,13 @@ bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) { return HadError || getContext().hadError(); } -void AsmParser::checkForValidSection() { +bool AsmParser::checkForValidSection() { if (!ParsingInlineAsm && !getStreamer().getCurrentSection().first) { - printError(getTok().getLoc(), - "expected section directive before assembly directive"); Out.InitSections(false); + return Error(getTok().getLoc(), + "expected section directive before assembly directive"); } + return false; } /// \brief Throw away the rest of the line for testing purposes. @@ -1589,7 +1590,8 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info, case AsmToken::Colon: { if (!getTargetParser().isLabel(ID)) break; - checkForValidSection(); + if (checkForValidSection()) + return true; // identifier ':' -> Label. Lex(); @@ -1977,7 +1979,8 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info, if (ParsingInlineAsm && (IDVal == "even")) Info.AsmRewrites->emplace_back(AOK_EVEN, IDLoc, 4); - checkForValidSection(); + if (checkForValidSection()) + return true; // Canonicalize the opcode to lower case. std::string OpcodeStr = IDVal.lower(); @@ -2707,7 +2710,8 @@ bool AsmParser::parseEscapedString(std::string &Data) { /// ::= ( .ascii | .asciz | .string ) [ "string" ( , "string" )* ] bool AsmParser::parseDirectiveAscii(StringRef IDVal, bool ZeroTerminated) { if (getLexer().isNot(AsmToken::EndOfStatement)) { - checkForValidSection(); + if (checkForValidSection()) + return true; while (true) { std::string Data; @@ -2781,7 +2785,8 @@ bool AsmParser::parseDirectiveReloc(SMLoc DirectiveLoc) { /// ::= (.byte | .short | ... ) [ expression (, expression)* ] bool AsmParser::parseDirectiveValue(unsigned Size) { if (getLexer().isNot(AsmToken::EndOfStatement)) { - checkForValidSection(); + if (checkForValidSection()) + return true; while (true) { const MCExpr *Value; @@ -2816,7 +2821,8 @@ bool AsmParser::parseDirectiveValue(unsigned Size) { /// ::= .octa [ hexconstant (, hexconstant)* ] bool AsmParser::parseDirectiveOctaValue() { if (getLexer().isNot(AsmToken::EndOfStatement)) { - checkForValidSection(); + if (checkForValidSection()) + return true; while (true) { if (getTok().is(AsmToken::Error)) @@ -2904,7 +2910,8 @@ bool AsmParser::parseRealValue(const fltSemantics &Semantics, APInt &Res) { /// ::= (.single | .double) [ expression (, expression)* ] bool AsmParser::parseDirectiveRealValue(const fltSemantics &Semantics) { if (getLexer().isNot(AsmToken::EndOfStatement)) { - checkForValidSection(); + if (checkForValidSection()) + return true; while (true) { APInt AsInt; @@ -2929,11 +2936,9 @@ bool AsmParser::parseDirectiveRealValue(const fltSemantics &Semantics) { /// parseDirectiveZero /// ::= .zero expression bool AsmParser::parseDirectiveZero() { - checkForValidSection(); - SMLoc NumBytesLoc = Lexer.getLoc(); const MCExpr *NumBytes; - if (parseExpression(NumBytes)) + if (checkForValidSection() || parseExpression(NumBytes)) return true; int64_t Val = 0; @@ -2954,11 +2959,9 @@ bool AsmParser::parseDirectiveZero() { /// parseDirectiveFill /// ::= .fill expression [ , expression [ , expression ] ] bool AsmParser::parseDirectiveFill() { - checkForValidSection(); - SMLoc NumValuesLoc = Lexer.getLoc(); const MCExpr *NumValues; - if (parseExpression(NumValues)) + if (checkForValidSection() || parseExpression(NumValues)) return true; int64_t FillSize = 1; @@ -3001,10 +3004,8 @@ bool AsmParser::parseDirectiveFill() { /// parseDirectiveOrg /// ::= .org expression [ , expression ] bool AsmParser::parseDirectiveOrg() { - checkForValidSection(); - const MCExpr *Offset; - if (parseExpression(Offset)) + if (checkForValidSection() || parseExpression(Offset)) return true; // Parse optional fill expression. @@ -3026,11 +3027,9 @@ bool AsmParser::parseDirectiveOrg() { /// parseDirectiveAlign /// ::= {.align, ...} expression [ , expression [ , expression ]] bool AsmParser::parseDirectiveAlign(bool IsPow2, unsigned ValueSize) { - checkForValidSection(); - SMLoc AlignmentLoc = getLexer().getLoc(); int64_t Alignment; - if (parseAbsoluteExpression(Alignment)) + if (checkForValidSection() || parseAbsoluteExpression(Alignment)) return true; SMLoc MaxBytesLoc; @@ -4183,13 +4182,11 @@ bool AsmParser::parseDirectivePurgeMacro(SMLoc DirectiveLoc) { /// parseDirectiveBundleAlignMode /// ::= {.bundle_align_mode} expression bool AsmParser::parseDirectiveBundleAlignMode() { - checkForValidSection(); - // Expect a single argument: an expression that evaluates to a constant // in the inclusive range 0-30. SMLoc ExprLoc = getLexer().getLoc(); int64_t AlignSizePow2; - if (parseAbsoluteExpression(AlignSizePow2) || + if (checkForValidSection() || parseAbsoluteExpression(AlignSizePow2) || parseToken(AsmToken::EndOfStatement, "unexpected token after expression " "in '.bundle_align_mode' " "directive") || @@ -4206,7 +4203,8 @@ bool AsmParser::parseDirectiveBundleAlignMode() { /// parseDirectiveBundleLock /// ::= {.bundle_lock} [align_to_end] bool AsmParser::parseDirectiveBundleLock() { - checkForValidSection(); + if (checkForValidSection()) + return true; bool AlignToEnd = false; if (getLexer().isNot(AsmToken::EndOfStatement)) { @@ -4232,9 +4230,8 @@ bool AsmParser::parseDirectiveBundleLock() { /// parseDirectiveBundleLock /// ::= {.bundle_lock} bool AsmParser::parseDirectiveBundleUnlock() { - checkForValidSection(); - - if (parseToken(AsmToken::EndOfStatement, + if (checkForValidSection() || + parseToken(AsmToken::EndOfStatement, "unexpected token in '.bundle_unlock' directive")) return true; @@ -4245,11 +4242,10 @@ bool AsmParser::parseDirectiveBundleUnlock() { /// parseDirectiveSpace /// ::= (.skip | .space) expression [ , expression ] bool AsmParser::parseDirectiveSpace(StringRef IDVal) { - checkForValidSection(); SMLoc NumBytesLoc = Lexer.getLoc(); const MCExpr *NumBytes; - if (parseExpression(NumBytes)) + if (checkForValidSection() || parseExpression(NumBytes)) return true; int64_t FillExpr = 0; @@ -4274,11 +4270,9 @@ bool AsmParser::parseDirectiveSpace(StringRef IDVal) { /// parseDirectiveDCB /// ::= .dcb.{b, l, w} expression, expression bool AsmParser::parseDirectiveDCB(StringRef IDVal, unsigned Size) { - checkForValidSection(); - SMLoc NumValuesLoc = Lexer.getLoc(); int64_t NumValues; - if (parseAbsoluteExpression(NumValues)) + if (checkForValidSection() || parseAbsoluteExpression(NumValues)) return true; if (NumValues < 0) { @@ -4318,11 +4312,9 @@ bool AsmParser::parseDirectiveDCB(StringRef IDVal, unsigned Size) { /// parseDirectiveRealDCB /// ::= .dcb.{d, s} expression, expression bool AsmParser::parseDirectiveRealDCB(StringRef IDVal, const fltSemantics &Semantics) { - checkForValidSection(); - SMLoc NumValuesLoc = Lexer.getLoc(); int64_t NumValues; - if (parseAbsoluteExpression(NumValues)) + if (checkForValidSection() || parseAbsoluteExpression(NumValues)) return true; if (NumValues < 0) { @@ -4352,11 +4344,10 @@ bool AsmParser::parseDirectiveRealDCB(StringRef IDVal, const fltSemantics &Seman /// parseDirectiveDS /// ::= .ds.{b, d, l, p, s, w, x} expression bool AsmParser::parseDirectiveDS(StringRef IDVal, unsigned Size) { - checkForValidSection(); SMLoc NumValuesLoc = Lexer.getLoc(); int64_t NumValues; - if (parseAbsoluteExpression(NumValues)) + if (checkForValidSection() || parseAbsoluteExpression(NumValues)) return true; if (NumValues < 0) { @@ -4377,7 +4368,9 @@ bool AsmParser::parseDirectiveDS(StringRef IDVal, unsigned Size) { /// parseDirectiveLEB128 /// ::= (.sleb128 | .uleb128) [ expression (, expression)* ] bool AsmParser::parseDirectiveLEB128(bool Signed) { - checkForValidSection(); + if (checkForValidSection()) + return true; + const MCExpr *Value; while (true) { @@ -4435,7 +4428,8 @@ bool AsmParser::parseDirectiveSymbolAttribute(MCSymbolAttr Attr) { /// parseDirectiveComm /// ::= ( .comm | .lcomm ) identifier , size_expression [ , align_expression ] bool AsmParser::parseDirectiveComm(bool IsLocal) { - checkForValidSection(); + if (checkForValidSection()) + return true; SMLoc IDLoc = getLexer().getLoc(); StringRef Name; -- 2.7.4