2016-02-19 00:43:24 +08:00
|
|
|
//===- 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/CodeGen/BackendUtil.h"
|
2016-07-19 03:02:11 +08:00
|
|
|
#include "clang/CodeGen/CodeGenAction.h"
|
|
|
|
#include "clang/Frontend/CompilerInstance.h"
|
|
|
|
#include "clang/Lex/PreprocessorOptions.h"
|
2016-02-19 00:43:24 +08:00
|
|
|
#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)
|
2016-02-19 04:27:16 +08:00
|
|
|
: CodeGenAction(Backend_EmitMCNull, _VMContext) {}
|
2016-02-19 00:43:24 +08:00
|
|
|
|
|
|
|
// 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) {
|
2017-01-07 03:49:01 +08:00
|
|
|
auto Invocation = std::make_shared<CompilerInvocation>();
|
2016-02-19 00:43:24 +08:00
|
|
|
Invocation->getPreprocessorOpts().addRemappedFile(
|
|
|
|
"test.cc",
|
|
|
|
MemoryBuffer::getMemBuffer("").release());
|
|
|
|
Invocation->getFrontendOpts().Inputs.push_back(
|
2017-04-27 02:57:40 +08:00
|
|
|
FrontendInputFile("test.cc", InputKind::CXX));
|
2016-02-19 00:43:24 +08:00
|
|
|
Invocation->getFrontendOpts().ProgramAction = EmitLLVM;
|
|
|
|
Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu";
|
|
|
|
CompilerInstance Compiler;
|
2017-01-07 03:49:01 +08:00
|
|
|
Compiler.setInvocation(std::move(Invocation));
|
2016-02-19 00:43:24 +08:00
|
|
|
Compiler.createDiagnostics();
|
|
|
|
EXPECT_TRUE(Compiler.hasDiagnostics());
|
|
|
|
|
|
|
|
std::unique_ptr<FrontendAction> Act(new NullCodeGenAction);
|
|
|
|
bool Success = Compiler.ExecuteAction(*Act);
|
|
|
|
EXPECT_TRUE(Success);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|