From 00384fda3cdf9c26a513fb769618010973d106aa 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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@340678 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCParser/AsmParser.cpp | 2 +- test/Assembler/empty-string.s | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 test/Assembler/empty-string.s diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index 501a1cccf60..0a4706ed104 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/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/test/Assembler/empty-string.s b/test/Assembler/empty-string.s new file mode 100644 index 00000000000..2d3d0ed15ad --- /dev/null +++ b/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