aboutsummaryrefslogtreecommitdiff
path: root/unittests/Frontend
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2016-07-23 20:44:14 +0000
committerDimitry Andric <dim@FreeBSD.org>2016-07-23 20:44:14 +0000
commit2b6b257f4e5503a7a2675bdb8735693db769f75c (patch)
treee85e046ae7003fe3bcc8b5454cd0fa3f7407b470 /unittests/Frontend
parentb4348ed0b7e90c0831b925fbee00b5f179a99796 (diff)
Notes
Diffstat (limited to 'unittests/Frontend')
-rw-r--r--unittests/Frontend/CMakeLists.txt2
-rw-r--r--unittests/Frontend/CodeGenActionTest.cpp61
-rw-r--r--unittests/Frontend/Makefile21
3 files changed, 63 insertions, 21 deletions
diff --git a/unittests/Frontend/CMakeLists.txt b/unittests/Frontend/CMakeLists.txt
index 5b5fdc9a54fe..674f77bd0135 100644
--- a/unittests/Frontend/CMakeLists.txt
+++ b/unittests/Frontend/CMakeLists.txt
@@ -4,6 +4,7 @@ set(LLVM_LINK_COMPONENTS
add_clang_unittest(FrontendTests
FrontendActionTest.cpp
+ CodeGenActionTest.cpp
)
target_link_libraries(FrontendTests
clangAST
@@ -11,4 +12,5 @@ target_link_libraries(FrontendTests
clangFrontend
clangLex
clangSema
+ clangCodeGen
)
diff --git a/unittests/Frontend/CodeGenActionTest.cpp b/unittests/Frontend/CodeGenActionTest.cpp
new file mode 100644
index 000000000000..71446fd4d79d
--- /dev/null
+++ b/unittests/Frontend/CodeGenActionTest.cpp
@@ -0,0 +1,61 @@
+//===- unittests/Frontend/CodeGenActionTest.cpp --- FrontendAction tests --===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Unit tests for CodeGenAction.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/CodeGen/CodeGenAction.h"
+#include "clang/CodeGen/BackendUtil.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace clang;
+using namespace clang::frontend;
+
+namespace {
+
+
+class NullCodeGenAction : public CodeGenAction {
+public:
+ NullCodeGenAction(llvm::LLVMContext *_VMContext = nullptr)
+ : CodeGenAction(Backend_EmitMCNull, _VMContext) {}
+
+ // The action does not call methods of ATContext.
+ void ExecuteAction() override {
+ CompilerInstance &CI = getCompilerInstance();
+ if (!CI.hasPreprocessor())
+ return;
+ if (!CI.hasSema())
+ CI.createSema(getTranslationUnitKind(), nullptr);
+ }
+};
+
+
+TEST(CodeGenTest, TestNullCodeGen) {
+ CompilerInvocation *Invocation = new CompilerInvocation;
+ Invocation->getPreprocessorOpts().addRemappedFile(
+ "test.cc",
+ MemoryBuffer::getMemBuffer("").release());
+ Invocation->getFrontendOpts().Inputs.push_back(
+ FrontendInputFile("test.cc", IK_CXX));
+ Invocation->getFrontendOpts().ProgramAction = EmitLLVM;
+ Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu";
+ CompilerInstance Compiler;
+ Compiler.setInvocation(Invocation);
+ Compiler.createDiagnostics();
+ EXPECT_TRUE(Compiler.hasDiagnostics());
+
+ std::unique_ptr<FrontendAction> Act(new NullCodeGenAction);
+ bool Success = Compiler.ExecuteAction(*Act);
+ EXPECT_TRUE(Success);
+}
+
+}
diff --git a/unittests/Frontend/Makefile b/unittests/Frontend/Makefile
deleted file mode 100644
index a63ae1824534..000000000000
--- a/unittests/Frontend/Makefile
+++ /dev/null
@@ -1,21 +0,0 @@
-##===- unittests/Frontend/Makefile -------------------------*- Makefile -*-===##
-#
-# The LLVM Compiler Infrastructure
-#
-# This file is distributed under the University of Illinois Open Source
-# License. See LICENSE.TXT for details.
-#
-##===----------------------------------------------------------------------===##
-
-CLANG_LEVEL = ../..
-TESTNAME = Frontend
-include $(CLANG_LEVEL)/../../Makefile.config
-LINK_COMPONENTS := $(TARGETS_TO_BUILD) asmparser bitreader support mc option
-USEDLIBS = clangFrontendTool.a clangFrontend.a clangDriver.a \
- clangSerialization.a clangCodeGen.a clangParse.a clangSema.a \
- clangStaticAnalyzerCheckers.a clangStaticAnalyzerCore.a \
- clangARCMigrate.a clangRewrite.a \
- clangRewriteFrontend.a clangEdit.a \
- clangAnalysis.a clangAST.a clangLex.a clangBasic.a
-
-include $(CLANG_LEVEL)/unittests/Makefile