blob: 3ff6c4eb40bda3f272f61973c1eb97238189d0a5 [file] [log] [blame]
Serge Pavlov7a545532016-02-18 16:43:24 +00001//===- unittests/Frontend/CodeGenActionTest.cpp --- FrontendAction tests --===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Unit tests for CodeGenAction.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Frontend/CompilerInstance.h"
15#include "clang/CodeGen/CodeGenAction.h"
16#include "clang/CodeGen/BackendUtil.h"
17#include "gtest/gtest.h"
18
19using namespace llvm;
20using namespace clang;
21using namespace clang::frontend;
22
23namespace {
24
25
26class NullCodeGenAction : public CodeGenAction {
27public:
28 NullCodeGenAction(llvm::LLVMContext *_VMContext = nullptr)
29 : CodeGenAction(Backend_EmitLL, _VMContext) {}
30
31 // The action does not call methods of ATContext.
32 void ExecuteAction() override {
33 CompilerInstance &CI = getCompilerInstance();
34 if (!CI.hasPreprocessor())
35 return;
36 if (!CI.hasSema())
37 CI.createSema(getTranslationUnitKind(), nullptr);
38 }
39};
40
41
42TEST(CodeGenTest, TestNullCodeGen) {
43 CompilerInvocation *Invocation = new CompilerInvocation;
44 Invocation->getPreprocessorOpts().addRemappedFile(
45 "test.cc",
46 MemoryBuffer::getMemBuffer("").release());
47 Invocation->getFrontendOpts().Inputs.push_back(
48 FrontendInputFile("test.cc", IK_CXX));
49 Invocation->getFrontendOpts().ProgramAction = EmitLLVM;
50 Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu";
51 CompilerInstance Compiler;
52 Compiler.setInvocation(Invocation);
53 Compiler.createDiagnostics();
54 EXPECT_TRUE(Compiler.hasDiagnostics());
55
56 std::unique_ptr<FrontendAction> Act(new NullCodeGenAction);
57 bool Success = Compiler.ExecuteAction(*Act);
58 EXPECT_TRUE(Success);
59}
60
61}