From 353f67a741daa97e94bd402f6394c6d89fd8a987 Mon Sep 17 00:00:00 2001 From: Ana Pazos Date: Sat, 25 Aug 2018 01:34:32 +0000 Subject: [PATCH] [MC, RISCV] Fixed StringRef Assertion `Index < Length && "Invalid index!"' Summary: Handle the case IDVal is an empty string. This bug was uncovered by a LLVM MC Assembler Protocol Buffer Fuzzer for the RISC-V assembly language. Reviewers: rnk Reviewed By: rnk Subscribers: rnk, niravd, pcc, peter.smith, asb, grosbach, llvm-commits, bcain, kito-cheng, shiva0217, rogfer01, PkmX Differential Revision: https://reviews.llvm.org/D50808 llvm-svn: 340678 --- llvm/lib/MC/MCParser/AsmParser.cpp | 2 +- llvm/test/Assembler/empty-string.s | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 llvm/test/Assembler/empty-string.s diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp index 501a1cc..0a4706e 100644 --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -1842,7 +1842,7 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info, // Otherwise, we have a normal instruction or directive. // Directives start with "." - if (IDVal[0] == '.' && IDVal != ".") { + if (IDVal.startswith(".") && IDVal != ".") { // There are several entities interested in parsing directives: // // 1. The target-specific assembly parser. Some directives are target diff --git a/llvm/test/Assembler/empty-string.s b/llvm/test/Assembler/empty-string.s new file mode 100644 index 0000000..2d3d0ed --- /dev/null +++ b/llvm/test/Assembler/empty-string.s @@ -0,0 +1,3 @@ +// REQUIRES: riscv-registered-target +// RUN: not llvm-mc -triple riscv32-unknown-linux-gnu < %s 2>&1 | FileCheck %s +"" # CHECK: error: unrecognized instruction mnemonic -- 2.7.4