[SCCP] Avoid modifying AdditionalUsers while iterating over it
[llvm-project.git] / clang / unittests / Frontend / CodeGenActionTest.cpp
blob455ec705f884d5bac973e027725f89a4b0c3ba9d
1 //===- unittests/Frontend/CodeGenActionTest.cpp --- FrontendAction tests --===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Unit tests for CodeGenAction.
11 //===----------------------------------------------------------------------===//
13 #include "clang/CodeGen/CodeGenAction.h"
14 #include "clang/Basic/LangStandard.h"
15 #include "clang/CodeGen/BackendUtil.h"
16 #include "clang/Frontend/CompilerInstance.h"
17 #include "clang/Lex/PreprocessorOptions.h"
18 #include "gtest/gtest.h"
20 using namespace llvm;
21 using namespace clang;
22 using namespace clang::frontend;
24 namespace {
27 class NullCodeGenAction : public CodeGenAction {
28 public:
29 NullCodeGenAction(llvm::LLVMContext *_VMContext = nullptr)
30 : CodeGenAction(Backend_EmitMCNull, _VMContext) {}
32 // The action does not call methods of ATContext.
33 void ExecuteAction() override {
34 CompilerInstance &CI = getCompilerInstance();
35 if (!CI.hasPreprocessor())
36 return;
37 if (!CI.hasSema())
38 CI.createSema(getTranslationUnitKind(), nullptr);
43 TEST(CodeGenTest, TestNullCodeGen) {
44 auto Invocation = std::make_shared<CompilerInvocation>();
45 Invocation->getPreprocessorOpts().addRemappedFile(
46 "test.cc",
47 MemoryBuffer::getMemBuffer("").release());
48 Invocation->getFrontendOpts().Inputs.push_back(
49 FrontendInputFile("test.cc", Language::CXX));
50 Invocation->getFrontendOpts().ProgramAction = EmitLLVM;
51 Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu";
52 CompilerInstance Compiler;
53 Compiler.setInvocation(std::move(Invocation));
54 Compiler.createDiagnostics();
55 EXPECT_TRUE(Compiler.hasDiagnostics());
57 std::unique_ptr<FrontendAction> Act(new NullCodeGenAction);
58 bool Success = Compiler.ExecuteAction(*Act);
59 EXPECT_TRUE(Success);