summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/AsmParser/Parser.cpp2
-rw-r--r--llvm/unittests/AsmParser/AsmParserTest.cpp47
-rw-r--r--llvm/unittests/AsmParser/CMakeLists.txt9
-rw-r--r--llvm/unittests/AsmParser/Makefile15
-rw-r--r--llvm/unittests/CMakeLists.txt1
-rw-r--r--llvm/unittests/Makefile5
6 files changed, 76 insertions, 3 deletions
diff --git a/llvm/lib/AsmParser/Parser.cpp b/llvm/lib/AsmParser/Parser.cpp
index 2e76c0ecc45..c55a6a1e243 100644
--- a/llvm/lib/AsmParser/Parser.cpp
+++ b/llvm/lib/AsmParser/Parser.cpp
@@ -24,7 +24,7 @@ using namespace llvm;
bool llvm::parseAssemblyInto(MemoryBufferRef F, Module &M, SMDiagnostic &Err) {
SourceMgr SM;
- std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(F, false);
+ std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(F);
SM.AddNewSourceBuffer(std::move(Buf), SMLoc());
return LLParser(F.getBuffer(), SM, Err, &M).Run();
diff --git a/llvm/unittests/AsmParser/AsmParserTest.cpp b/llvm/unittests/AsmParser/AsmParserTest.cpp
new file mode 100644
index 00000000000..8847b187167
--- /dev/null
+++ b/llvm/unittests/AsmParser/AsmParserTest.cpp
@@ -0,0 +1,47 @@
+//===- 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, NullTerminatedInput) {
+ LLVMContext &Ctx = getGlobalContext();
+ StringRef Source = "; Empty module \n";
+ SMDiagnostic Error;
+ auto Mod = parseAssemblyString(Source, Error, Ctx);
+
+ EXPECT_TRUE(Mod != nullptr);
+ EXPECT_TRUE(Error.getMessage().empty());
+}
+
+#ifdef GTEST_HAS_DEATH_TEST
+#ifndef NDEBUG
+
+TEST(AsmParserTest, NonNullTerminatedInput) {
+ LLVMContext &Ctx = getGlobalContext();
+ StringRef Source = "; Empty module \n\1\2";
+ SMDiagnostic Error;
+ std::unique_ptr<Module> Mod;
+ EXPECT_DEATH(Mod = parseAssemblyString(Source.substr(0, Source.size() - 2),
+ Error, Ctx),
+ "Buffer is not null terminated!");
+}
+
+#endif
+#endif
+
+} // end anonymous namespace
diff --git a/llvm/unittests/AsmParser/CMakeLists.txt b/llvm/unittests/AsmParser/CMakeLists.txt
new file mode 100644
index 00000000000..1920bfaa3aa
--- /dev/null
+++ b/llvm/unittests/AsmParser/CMakeLists.txt
@@ -0,0 +1,9 @@
+set(LLVM_LINK_COMPONENTS
+ AsmParser
+ Core
+ Support
+ )
+
+add_llvm_unittest(AsmParserTests
+ AsmParserTest.cpp
+ )
diff --git a/llvm/unittests/AsmParser/Makefile b/llvm/unittests/AsmParser/Makefile
new file mode 100644
index 00000000000..41eadd43043
--- /dev/null
+++ b/llvm/unittests/AsmParser/Makefile
@@ -0,0 +1,15 @@
+##===- unittests/AsmParser/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
diff --git a/llvm/unittests/CMakeLists.txt b/llvm/unittests/CMakeLists.txt
index a1272edcc97..e5befcec6e0 100644
--- a/llvm/unittests/CMakeLists.txt
+++ b/llvm/unittests/CMakeLists.txt
@@ -13,6 +13,7 @@ endfunction()
add_subdirectory(ADT)
add_subdirectory(Analysis)
+add_subdirectory(AsmParser)
add_subdirectory(Bitcode)
add_subdirectory(CodeGen)
add_subdirectory(DebugInfo)
diff --git a/llvm/unittests/Makefile b/llvm/unittests/Makefile
index fefef0748b9..bf2ed22efea 100644
--- a/llvm/unittests/Makefile
+++ b/llvm/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
OpenPOWER on IntegriCloud