From a767ae2c5ce7615c188baabd3b6a52bb880de234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Marques?= Date: Wed, 19 Jan 2022 21:55:35 +0000 Subject: [PATCH] [RISCV] Fix incomplete asm statement parsing For instructions without operands, the final `AsmToken::EndOfStatement` wasn't being consumed. In the context of inline assembly, the resulting empty statements would cause extraneous empty lines to be emitted. Fix the issue by consuming the `EndOfStatement` token. Differential Revision: https://reviews.llvm.org/D117565 --- llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp | 4 +++- llvm/test/CodeGen/RISCV/large-stack.ll | 4 ---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp index 7b65591d680f..1c8ed0d60d8e 100644 --- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp +++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp @@ -1912,8 +1912,10 @@ bool RISCVAsmParser::ParseInstruction(ParseInstructionInfo &Info, Operands.push_back(RISCVOperand::createToken(Name, NameLoc, isRV64())); // If there are no more operands, then finish - if (getLexer().is(AsmToken::EndOfStatement)) + if (getLexer().is(AsmToken::EndOfStatement)) { + getParser().Lex(); // Consume the EndOfStatement. return false; + } // Parse first operand if (parseOperand(Operands, Name)) diff --git a/llvm/test/CodeGen/RISCV/large-stack.ll b/llvm/test/CodeGen/RISCV/large-stack.ll index a78c9f4f4b40..ff265d9598c8 100644 --- a/llvm/test/CodeGen/RISCV/large-stack.ll +++ b/llvm/test/CodeGen/RISCV/large-stack.ll @@ -64,12 +64,10 @@ define void @test_emergency_spill_slot(i32 %a) { ; RV32I-FPELIM-NEXT: add a1, a2, a1 ; RV32I-FPELIM-NEXT: #APP ; RV32I-FPELIM-NEXT: nop -; RV32I-FPELIM-EMPTY: ; RV32I-FPELIM-NEXT: #NO_APP ; RV32I-FPELIM-NEXT: sw a0, 0(a1) ; RV32I-FPELIM-NEXT: #APP ; RV32I-FPELIM-NEXT: nop -; RV32I-FPELIM-EMPTY: ; RV32I-FPELIM-NEXT: #NO_APP ; RV32I-FPELIM-NEXT: lui a0, 97 ; RV32I-FPELIM-NEXT: addi a0, a0, 672 @@ -104,12 +102,10 @@ define void @test_emergency_spill_slot(i32 %a) { ; RV32I-WITHFP-NEXT: add a1, a2, a1 ; RV32I-WITHFP-NEXT: #APP ; RV32I-WITHFP-NEXT: nop -; RV32I-WITHFP-EMPTY: ; RV32I-WITHFP-NEXT: #NO_APP ; RV32I-WITHFP-NEXT: sw a0, 0(a1) ; RV32I-WITHFP-NEXT: #APP ; RV32I-WITHFP-NEXT: nop -; RV32I-WITHFP-EMPTY: ; RV32I-WITHFP-NEXT: #NO_APP ; RV32I-WITHFP-NEXT: lui a0, 97 ; RV32I-WITHFP-NEXT: addi a0, a0, 688