Index: lib/AsmParser/LLLexer.cpp =================================================================== --- lib/AsmParser/LLLexer.cpp +++ lib/AsmParser/LLLexer.cpp @@ -170,19 +170,9 @@ } int LLLexer::getNextChar() { - char CurChar = *CurPtr++; - switch (CurChar) { - default: return (unsigned char)CurChar; - case 0: - // A nul character in the stream is either the end of the current buffer or - // a random nul in the file. Disambiguate that here. - if (CurPtr-1 != CurBuf.end()) - return 0; // Just whitespace. - - // Otherwise, return end of file. - --CurPtr; // Another call to lex will return EOF again. + if (CurPtr >= CurBuf.end()) return EOF; - } + return (unsigned char)*CurPtr++; } Index: unittests/AsmParser/AsmParserTest.cpp =================================================================== --- /dev/null +++ unittests/AsmParser/AsmParserTest.cpp @@ -0,0 +1,32 @@ +//===- llvm/unittest/AsmParser/AsmParserTest.cpp - asm parser unittests ---===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/StringRef.h" +#include "llvm/AsmParser/Parser.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" +#include "llvm/Support/SourceMgr.h" +#include "gtest/gtest.h" + +using namespace llvm; + +namespace { + +TEST(AsmParserTest, NonNullTerminatedInput) { + LLVMContext &Ctx = getGlobalContext(); + StringRef Source = "; Empty module \n\1\2"; + SMDiagnostic Error; + auto Mod = + parseAssemblyString(Source.substr(0, Source.size() - 2), Error, Ctx); + + EXPECT_TRUE(Mod != nullptr); + EXPECT_TRUE(Error.getMessage().empty()); +} + +} // end anonymous namespace Index: unittests/AsmParser/CMakeLists.txt =================================================================== --- /dev/null +++ unittests/AsmParser/CMakeLists.txt @@ -0,0 +1,9 @@ +set(LLVM_LINK_COMPONENTS + AsmParser + Core + Support + ) + +add_llvm_unittest(AsmParserTests + AsmParserTest.cpp + ) Index: unittests/AsmParser/Makefile =================================================================== --- /dev/null +++ unittests/AsmParser/Makefile @@ -0,0 +1,15 @@ +##===- unittests/Assembler/Makefile ------------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL = ../.. +TESTNAME = AsmParser +LINK_COMPONENTS := AsmParser Core Support + +include $(LEVEL)/Makefile.config +include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest Index: unittests/CMakeLists.txt =================================================================== --- unittests/CMakeLists.txt +++ unittests/CMakeLists.txt @@ -13,6 +13,7 @@ add_subdirectory(ADT) add_subdirectory(Analysis) +add_subdirectory(AsmParser) add_subdirectory(Bitcode) add_subdirectory(CodeGen) add_subdirectory(DebugInfo) Index: unittests/Makefile =================================================================== --- unittests/Makefile +++ unittests/Makefile @@ -9,8 +9,9 @@ LEVEL = .. -PARALLEL_DIRS = ADT Analysis Bitcode CodeGen DebugInfo ExecutionEngine IR \ - LineEditor Linker MC Option ProfileData Support Transforms +PARALLEL_DIRS = ADT Analysis AsmParser Bitcode CodeGen DebugInfo \ + ExecutionEngine IR LineEditor Linker MC Option ProfileData \ + Support Transforms include $(LEVEL)/Makefile.config include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest