diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2025-05-01 07:31:30 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-01 07:31:30 -0700 |
commit | b69dcb873476cd8e7d3f6f9ffd5b6d0bbe1a3a17 (patch) | |
tree | 91fa427a131edc9cd16c9bef896a64083442218e /clang/unittests/Frontend/OutputStreamTest.cpp | |
parent | 0009a1783490a8ff69251a0ec7df1891a427cfb0 (diff) | |
download | llvm-b69dcb873476cd8e7d3f6f9ffd5b6d0bbe1a3a17.zip llvm-b69dcb873476cd8e7d3f6f9ffd5b6d0bbe1a3a17.tar.gz llvm-b69dcb873476cd8e7d3f6f9ffd5b6d0bbe1a3a17.tar.bz2 |
[clang][frontend] Require invocation to construct `CompilerInstance` (#137668)
This PR makes it so that `CompilerInvocation` needs to be provided to
`CompilerInstance` on construction. There are a couple of benefits in my
view:
* Making it impossible to mis-use some `CompilerInstance` APIs. For
example there are cases, where `createDiagnostics()` was called before
`setInvocation()`, causing the `DiagnosticEngine` to use the
default-constructed `DiagnosticOptions` instead of the intended ones.
* This shrinks `CompilerInstance`'s state space.
* This makes it possible to access **the** invocation in
`CompilerInstance`'s constructor (to be used in a follow-up).
Diffstat (limited to 'clang/unittests/Frontend/OutputStreamTest.cpp')
-rw-r--r-- | clang/unittests/Frontend/OutputStreamTest.cpp | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/clang/unittests/Frontend/OutputStreamTest.cpp b/clang/unittests/Frontend/OutputStreamTest.cpp index 27d2d7f..0eda3a1 100644 --- a/clang/unittests/Frontend/OutputStreamTest.cpp +++ b/clang/unittests/Frontend/OutputStreamTest.cpp @@ -31,14 +31,13 @@ TEST(FrontendOutputTests, TestOutputStream) { FrontendInputFile("test.cc", Language::CXX)); Invocation->getFrontendOpts().ProgramAction = EmitBC; Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; - CompilerInstance Compiler; + CompilerInstance Compiler(std::move(Invocation)); SmallVector<char, 256> IRBuffer; std::unique_ptr<raw_pwrite_stream> IRStream( new raw_svector_ostream(IRBuffer)); Compiler.setOutputStream(std::move(IRStream)); - Compiler.setInvocation(std::move(Invocation)); Compiler.createDiagnostics(*llvm::vfs::getRealFileSystem()); bool Success = ExecuteCompilerInvocation(&Compiler); @@ -56,13 +55,12 @@ TEST(FrontendOutputTests, TestVerboseOutputStreamShared) { FrontendInputFile("test.cc", Language::CXX)); Invocation->getFrontendOpts().ProgramAction = EmitBC; Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; - CompilerInstance Compiler; + CompilerInstance Compiler(std::move(Invocation)); std::string VerboseBuffer; raw_string_ostream VerboseStream(VerboseBuffer); Compiler.setOutputStream(std::make_unique<raw_null_ostream>()); - Compiler.setInvocation(std::move(Invocation)); IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); Compiler.createDiagnostics( *llvm::vfs::getRealFileSystem(), @@ -87,13 +85,12 @@ TEST(FrontendOutputTests, TestVerboseOutputStreamOwned) { FrontendInputFile("test.cc", Language::CXX)); Invocation->getFrontendOpts().ProgramAction = EmitBC; Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; - CompilerInstance Compiler; + CompilerInstance Compiler(std::move(Invocation)); std::unique_ptr<raw_ostream> VerboseStream = std::make_unique<raw_string_ostream>(VerboseBuffer); Compiler.setOutputStream(std::make_unique<raw_null_ostream>()); - Compiler.setInvocation(std::move(Invocation)); IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); Compiler.createDiagnostics( *llvm::vfs::getRealFileSystem(), |