diff options
Diffstat (limited to 'clang/unittests/Frontend')
-rw-r--r-- | clang/unittests/Frontend/ASTUnitTest.cpp | 37 | ||||
-rw-r--r-- | clang/unittests/Frontend/CompilerInstanceTest.cpp | 11 | ||||
-rw-r--r-- | clang/unittests/Frontend/CompilerInvocationTest.cpp | 3 | ||||
-rw-r--r-- | clang/unittests/Frontend/OutputStreamTest.cpp | 12 | ||||
-rw-r--r-- | clang/unittests/Frontend/PCHPreambleTest.cpp | 7 | ||||
-rw-r--r-- | clang/unittests/Frontend/ReparseWorkingDirTest.cpp | 6 | ||||
-rw-r--r-- | clang/unittests/Frontend/SearchPathTest.cpp | 4 | ||||
-rw-r--r-- | clang/unittests/Frontend/TextDiagnosticTest.cpp | 8 | ||||
-rw-r--r-- | clang/unittests/Frontend/UtilsTest.cpp | 9 |
9 files changed, 53 insertions, 44 deletions
diff --git a/clang/unittests/Frontend/ASTUnitTest.cpp b/clang/unittests/Frontend/ASTUnitTest.cpp index 08daca9..afa64b5 100644 --- a/clang/unittests/Frontend/ASTUnitTest.cpp +++ b/clang/unittests/Frontend/ASTUnitTest.cpp @@ -30,6 +30,8 @@ protected: int FD; llvm::SmallString<256> InputFileName; std::unique_ptr<ToolOutputFile> input_file; + std::shared_ptr<DiagnosticOptions> DiagOpts = + std::make_shared<DiagnosticOptions>(); IntrusiveRefCntPtr<DiagnosticsEngine> Diags; std::shared_ptr<CompilerInvocation> CInvok; std::shared_ptr<PCHContainerOperations> PCHContainerOps; @@ -43,7 +45,7 @@ protected: const char *Args[] = {"clang", "-xc++", InputFileName.c_str()}; auto VFS = llvm::vfs::getRealFileSystem(); - Diags = CompilerInstance::createDiagnostics(*VFS, new DiagnosticOptions()); + Diags = CompilerInstance::createDiagnostics(*VFS, *DiagOpts); CreateInvocationOptions CIOpts; CIOpts.Diags = Diags; @@ -57,8 +59,8 @@ protected: PCHContainerOps = std::make_shared<PCHContainerOperations>(); return ASTUnit::LoadFromCompilerInvocation( - CInvok, PCHContainerOps, Diags, FileMgr, false, CaptureDiagsKind::None, - 0, TU_Complete, false, false, isVolatile); + CInvok, PCHContainerOps, DiagOpts, Diags, FileMgr, false, + CaptureDiagsKind::None, 0, TU_Complete, false, false, isVolatile); } }; @@ -95,7 +97,7 @@ TEST_F(ASTUnitTest, SaveLoadPreservesLangOptionsInPrintingPolicy) { std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile( ASTFileName, PCHContainerOps->getRawReader(), ASTUnit::LoadEverything, - Diags, FileSystemOptions(), HSOpts); + DiagOpts, Diags, FileSystemOptions(), HSOpts); if (!AU) FAIL() << "failed to load ASTUnit"; @@ -136,8 +138,7 @@ TEST_F(ASTUnitTest, ModuleTextualHeader) { const char *Args[] = {"clang", "test.cpp", "-fmodule-map-file=m.modulemap", "-fmodule-name=M"}; - Diags = - CompilerInstance::createDiagnostics(*InMemoryFs, new DiagnosticOptions()); + Diags = CompilerInstance::createDiagnostics(*InMemoryFs, *DiagOpts); CreateInvocationOptions CIOpts; CIOpts.Diags = Diags; CInvok = createInvocation(Args, std::move(CIOpts)); @@ -147,8 +148,8 @@ TEST_F(ASTUnitTest, ModuleTextualHeader) { PCHContainerOps = std::make_shared<PCHContainerOperations>(); auto AU = ASTUnit::LoadFromCompilerInvocation( - CInvok, PCHContainerOps, Diags, FileMgr, false, CaptureDiagsKind::None, 1, - TU_Complete, false, false, false); + CInvok, PCHContainerOps, DiagOpts, Diags, FileMgr, false, + CaptureDiagsKind::None, 1, TU_Complete, false, false, false); ASSERT_TRUE(AU); auto File = AU->getFileManager().getFileRef("Textual.h", false, false); ASSERT_TRUE(bool(File)); @@ -166,15 +167,15 @@ TEST_F(ASTUnitTest, LoadFromCommandLineEarlyError) { const char *Args[] = {"clang", "-target", "foobar", InputFileName.c_str()}; auto Diags = CompilerInstance::createDiagnostics( - *llvm::vfs::getRealFileSystem(), new DiagnosticOptions()); + *llvm::vfs::getRealFileSystem(), *DiagOpts); auto PCHContainerOps = std::make_shared<PCHContainerOperations>(); std::unique_ptr<clang::ASTUnit> ErrUnit; std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromCommandLine( - &Args[0], &Args[4], PCHContainerOps, Diags, "", false, "", false, - CaptureDiagsKind::All, {}, true, 0, TU_Complete, false, false, false, - SkipFunctionBodiesScope::None, false, true, false, false, std::nullopt, - &ErrUnit, nullptr); + &Args[0], &Args[4], PCHContainerOps, DiagOpts, Diags, "", false, "", + false, CaptureDiagsKind::All, {}, true, 0, TU_Complete, false, false, + false, SkipFunctionBodiesScope::None, false, true, false, false, + std::nullopt, &ErrUnit, nullptr); ASSERT_EQ(AST, nullptr); ASSERT_NE(ErrUnit, nullptr); @@ -194,15 +195,15 @@ TEST_F(ASTUnitTest, LoadFromCommandLineWorkingDirectory) { InputFileName.c_str()}; auto Diags = CompilerInstance::createDiagnostics( - *llvm::vfs::getRealFileSystem(), new DiagnosticOptions()); + *llvm::vfs::getRealFileSystem(), *DiagOpts); auto PCHContainerOps = std::make_shared<PCHContainerOperations>(); std::unique_ptr<clang::ASTUnit> ErrUnit; std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromCommandLine( - &Args[0], &Args[4], PCHContainerOps, Diags, "", false, "", false, - CaptureDiagsKind::All, {}, true, 0, TU_Complete, false, false, false, - SkipFunctionBodiesScope::None, false, true, false, false, std::nullopt, - &ErrUnit, nullptr); + &Args[0], &Args[4], PCHContainerOps, DiagOpts, Diags, "", false, "", + false, CaptureDiagsKind::All, {}, true, 0, TU_Complete, false, false, + false, SkipFunctionBodiesScope::None, false, true, false, false, + std::nullopt, &ErrUnit, nullptr); ASSERT_NE(AST, nullptr); ASSERT_FALSE(Diags->hasErrorOccurred()); diff --git a/clang/unittests/Frontend/CompilerInstanceTest.cpp b/clang/unittests/Frontend/CompilerInstanceTest.cpp index 6e9a6f5..a7b258d 100644 --- a/clang/unittests/Frontend/CompilerInstanceTest.cpp +++ b/clang/unittests/Frontend/CompilerInstanceTest.cpp @@ -53,9 +53,10 @@ TEST(CompilerInstance, DefaultVFSOverlayFromInvocation) { const std::string VFSArg = "-ivfsoverlay" + FileNameStr; const char *Args[] = {"clang", VFSArg.c_str(), "-xc++", "-"}; + DiagnosticOptions DiagOpts; IntrusiveRefCntPtr<DiagnosticsEngine> Diags = CompilerInstance::createDiagnostics(*llvm::vfs::getRealFileSystem(), - new DiagnosticOptions()); + DiagOpts); CreateInvocationOptions CIOpts; CIOpts.Diags = Diags; @@ -76,17 +77,17 @@ TEST(CompilerInstance, DefaultVFSOverlayFromInvocation) { } TEST(CompilerInstance, AllowDiagnosticLogWithUnownedDiagnosticConsumer) { - auto DiagOpts = new DiagnosticOptions(); + DiagnosticOptions DiagOpts; // Tell the diagnostics engine to emit the diagnostic log to STDERR. This // ensures that a chained diagnostic consumer is created so that the test can // exercise the unowned diagnostic consumer in a chained consumer. - DiagOpts->DiagnosticLogFile = "-"; + DiagOpts.DiagnosticLogFile = "-"; // Create the diagnostic engine with unowned consumer. std::string DiagnosticOutput; llvm::raw_string_ostream DiagnosticsOS(DiagnosticOutput); - auto DiagPrinter = std::make_unique<TextDiagnosticPrinter>( - DiagnosticsOS, new DiagnosticOptions()); + auto DiagPrinter = + std::make_unique<TextDiagnosticPrinter>(DiagnosticsOS, DiagOpts); CompilerInstance Instance; IntrusiveRefCntPtr<DiagnosticsEngine> Diags = Instance.createDiagnostics(*llvm::vfs::getRealFileSystem(), DiagOpts, diff --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp b/clang/unittests/Frontend/CompilerInvocationTest.cpp index 94ab9fe..75390aa 100644 --- a/clang/unittests/Frontend/CompilerInvocationTest.cpp +++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp @@ -29,6 +29,7 @@ using ::testing::StartsWith; namespace { class CommandLineTest : public ::testing::Test { public: + DiagnosticOptions DiagOpts; IntrusiveRefCntPtr<DiagnosticsEngine> Diags; SmallVector<const char *, 32> GeneratedArgs; BumpPtrAllocator Alloc; @@ -41,7 +42,7 @@ public: CommandLineTest() : Diags(CompilerInstance::createDiagnostics( - *llvm::vfs::getRealFileSystem(), new DiagnosticOptions(), + *llvm::vfs::getRealFileSystem(), DiagOpts, new TextDiagnosticBuffer())), StringPool(Alloc) {} }; diff --git a/clang/unittests/Frontend/OutputStreamTest.cpp b/clang/unittests/Frontend/OutputStreamTest.cpp index 0eda3a1..dfb5a54 100644 --- a/clang/unittests/Frontend/OutputStreamTest.cpp +++ b/clang/unittests/Frontend/OutputStreamTest.cpp @@ -61,10 +61,10 @@ TEST(FrontendOutputTests, TestVerboseOutputStreamShared) { raw_string_ostream VerboseStream(VerboseBuffer); Compiler.setOutputStream(std::make_unique<raw_null_ostream>()); - IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); - Compiler.createDiagnostics( - *llvm::vfs::getRealFileSystem(), - new TextDiagnosticPrinter(llvm::nulls(), &*DiagOpts), true); + DiagnosticOptions DiagOpts; + Compiler.createDiagnostics(*llvm::vfs::getRealFileSystem(), + new TextDiagnosticPrinter(llvm::nulls(), DiagOpts), + true); Compiler.setVerboseOutputStream(VerboseStream); bool Success = ExecuteCompilerInvocation(&Compiler); @@ -91,10 +91,10 @@ TEST(FrontendOutputTests, TestVerboseOutputStreamOwned) { std::make_unique<raw_string_ostream>(VerboseBuffer); Compiler.setOutputStream(std::make_unique<raw_null_ostream>()); - IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); + DiagnosticOptions DiagOpts; Compiler.createDiagnostics( *llvm::vfs::getRealFileSystem(), - new TextDiagnosticPrinter(llvm::nulls(), &*DiagOpts), true); + new TextDiagnosticPrinter(llvm::nulls(), DiagOpts), true); Compiler.setVerboseOutputStream(std::move(VerboseStream)); Success = ExecuteCompilerInvocation(&Compiler); diff --git a/clang/unittests/Frontend/PCHPreambleTest.cpp b/clang/unittests/Frontend/PCHPreambleTest.cpp index 58ec2e2..faad408 100644 --- a/clang/unittests/Frontend/PCHPreambleTest.cpp +++ b/clang/unittests/Frontend/PCHPreambleTest.cpp @@ -53,6 +53,8 @@ class PCHPreambleTest : public ::testing::Test { IntrusiveRefCntPtr<ReadCountingInMemoryFileSystem> VFS; StringMap<std::string> RemappedFiles; std::shared_ptr<PCHContainerOperations> PCHContainerOpts; + std::shared_ptr<DiagnosticOptions> DiagOpts = + std::make_shared<DiagnosticOptions>(); FileSystemOptions FSOpts; public: @@ -95,13 +97,14 @@ public: PPOpts.RemappedFilesKeepOriginalName = true; IntrusiveRefCntPtr<DiagnosticsEngine> Diags( - CompilerInstance::createDiagnostics(*VFS, new DiagnosticOptions, + CompilerInstance::createDiagnostics(*VFS, *DiagOpts, new DiagnosticConsumer)); FileManager *FileMgr = new FileManager(FSOpts, VFS); std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromCompilerInvocation( - CI, PCHContainerOpts, Diags, FileMgr, false, CaptureDiagsKind::None, + CI, PCHContainerOpts, DiagOpts, Diags, FileMgr, false, + CaptureDiagsKind::None, /*PrecompilePreambleAfterNParses=*/1); return AST; } diff --git a/clang/unittests/Frontend/ReparseWorkingDirTest.cpp b/clang/unittests/Frontend/ReparseWorkingDirTest.cpp index b0f2d51..1b8051f 100644 --- a/clang/unittests/Frontend/ReparseWorkingDirTest.cpp +++ b/clang/unittests/Frontend/ReparseWorkingDirTest.cpp @@ -57,14 +57,16 @@ public: CI->getFileSystemOpts().WorkingDir = *VFS->getCurrentWorkingDirectory(); CI->getTargetOpts().Triple = "i386-unknown-linux-gnu"; + auto DiagOpts = std::make_shared<DiagnosticOptions>(); IntrusiveRefCntPtr<DiagnosticsEngine> Diags( - CompilerInstance::createDiagnostics(*VFS, new DiagnosticOptions, + CompilerInstance::createDiagnostics(*VFS, *DiagOpts, new DiagnosticConsumer)); FileManager *FileMgr = new FileManager(CI->getFileSystemOpts(), VFS); std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromCompilerInvocation( - CI, PCHContainerOpts, Diags, FileMgr, false, CaptureDiagsKind::None, + CI, PCHContainerOpts, DiagOpts, Diags, FileMgr, false, + CaptureDiagsKind::None, /*PrecompilePreambleAfterNParses=*/1); return AST; } diff --git a/clang/unittests/Frontend/SearchPathTest.cpp b/clang/unittests/Frontend/SearchPathTest.cpp index 2ebe74d..c74a5c7 100644 --- a/clang/unittests/Frontend/SearchPathTest.cpp +++ b/clang/unittests/Frontend/SearchPathTest.cpp @@ -40,12 +40,12 @@ namespace { class SearchPathTest : public ::testing::Test { protected: SearchPathTest() - : Diags(new DiagnosticIDs(), new DiagnosticOptions, - new IgnoringDiagConsumer()), + : Diags(new DiagnosticIDs(), DiagOpts, new IgnoringDiagConsumer()), VFS(new llvm::vfs::InMemoryFileSystem), FileMgr(FileSystemOptions(), VFS), SourceMgr(Diags, FileMgr), Invocation(std::make_unique<CompilerInvocation>()) {} + DiagnosticOptions DiagOpts; DiagnosticsEngine Diags; IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS; FileManager FileMgr; diff --git a/clang/unittests/Frontend/TextDiagnosticTest.cpp b/clang/unittests/Frontend/TextDiagnosticTest.cpp index fef5726..8fd8187 100644 --- a/clang/unittests/Frontend/TextDiagnosticTest.cpp +++ b/clang/unittests/Frontend/TextDiagnosticTest.cpp @@ -20,13 +20,12 @@ namespace { /// Prints a diagnostic with the given DiagnosticOptions and the given /// SourceLocation and returns the printed diagnostic text. -static std::string PrintDiag(const DiagnosticOptions &Opts, FullSourceLoc Loc) { +static std::string PrintDiag(DiagnosticOptions &Opts, FullSourceLoc Loc) { std::string Out; llvm::raw_string_ostream OS(Out); clang::LangOptions LangOpts; // Owned by TextDiagnostic. - DiagnosticOptions *DiagOpts = new DiagnosticOptions(Opts); - TextDiagnostic Diag(OS, LangOpts, DiagOpts); + TextDiagnostic Diag(OS, LangOpts, Opts); // Emit a dummy diagnostic that is just 'message'. Diag.emitDiagnostic(Loc, DiagnosticsEngine::Level::Warning, "message", /*Ranges=*/{}, /*FixItHints=*/{}); @@ -38,7 +37,8 @@ TEST(TextDiagnostic, ShowLine) { FileSystemOptions FSOpts; FileManager FileMgr(FSOpts); IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs); - DiagnosticsEngine DiagEngine(DiagID, new DiagnosticOptions, + DiagnosticOptions DiagEngineOpts; + DiagnosticsEngine DiagEngine(DiagID, DiagEngineOpts, new IgnoringDiagConsumer()); SourceManager SrcMgr(DiagEngine, FileMgr); diff --git a/clang/unittests/Frontend/UtilsTest.cpp b/clang/unittests/Frontend/UtilsTest.cpp index 47ca321..cf385a5 100644 --- a/clang/unittests/Frontend/UtilsTest.cpp +++ b/clang/unittests/Frontend/UtilsTest.cpp @@ -26,11 +26,12 @@ TEST(BuildCompilerInvocationTest, RecoverMultipleJobs) { std::vector<const char *> Args = {"clang", "--target=macho", "-arch", "i386", "-arch", "x86_64", "foo.cpp"}; clang::IgnoringDiagConsumer D; + clang::DiagnosticOptions DiagOpts; CreateInvocationOptions Opts; Opts.RecoverOnError = true; Opts.VFS = new llvm::vfs::InMemoryFileSystem(); - Opts.Diags = clang::CompilerInstance::createDiagnostics( - *Opts.VFS, new DiagnosticOptions, &D, false); + Opts.Diags = clang::CompilerInstance::createDiagnostics(*Opts.VFS, DiagOpts, + &D, false); std::unique_ptr<CompilerInvocation> CI = createInvocation(Args, Opts); ASSERT_TRUE(CI); EXPECT_THAT(CI->getTargetOpts().Triple, testing::StartsWith("i386-")); @@ -45,9 +46,9 @@ TEST(BuildCompilerInvocationTest, ProbePrecompiled) { FS->addFile("foo.h.pch", 0, llvm::MemoryBuffer::getMemBuffer("")); clang::IgnoringDiagConsumer D; + clang::DiagnosticOptions DiagOpts; llvm::IntrusiveRefCntPtr<DiagnosticsEngine> CommandLineDiagsEngine = - clang::CompilerInstance::createDiagnostics(*FS, new DiagnosticOptions, &D, - false); + clang::CompilerInstance::createDiagnostics(*FS, DiagOpts, &D, false); // Default: ProbePrecompiled=false CreateInvocationOptions CIOpts; CIOpts.Diags = CommandLineDiagsEngine; |