Skip to content

Commit 5ac1a40

Browse files
committed
Merge from 'main' to 'sycl-web' (3 commits)
2 parents 11a98fb + b69dcb8 commit 5ac1a40

File tree

71 files changed

+1291
-850
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1291
-850
lines changed

clang-tools-extra/clang-include-fixer/IncludeFixer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ bool IncludeFixerActionFactory::runInvocation(
8989
assert(Invocation->getFrontendOpts().Inputs.size() == 1);
9090

9191
// Set up Clang.
92-
clang::CompilerInstance Compiler(PCHContainerOps);
93-
Compiler.setInvocation(std::move(Invocation));
92+
CompilerInstance Compiler(std::move(Invocation), std::move(PCHContainerOps));
9493
Compiler.setFileManager(Files);
9594

9695
// Create the compiler's actual diagnostics engine. We want to drop all

clang-tools-extra/clangd/Compiler.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,7 @@ prepareCompilerInstance(std::unique_ptr<clang::CompilerInvocation> CI,
151151
CI->getFrontendOpts().Inputs[0].getFile(), Buffer.get());
152152
}
153153

154-
auto Clang = std::make_unique<CompilerInstance>(
155-
std::make_shared<PCHContainerOperations>());
156-
Clang->setInvocation(std::move(CI));
154+
auto Clang = std::make_unique<CompilerInstance>(std::move(CI));
157155
Clang->createDiagnostics(*VFS, &DiagsClient, false);
158156

159157
if (auto VFSWithRemapping = createVFSFromCompilerInvocation(

clang-tools-extra/include-cleaner/unittests/RecordTest.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -618,14 +618,14 @@ TEST_F(PragmaIncludeTest, ExportInUnnamedBuffer) {
618618
llvm::MemoryBuffer::getMemBufferCopy(Extra.getValue(),
619619
/*BufferName=*/""));
620620

621-
auto Clang = std::make_unique<CompilerInstance>(
622-
std::make_shared<PCHContainerOperations>());
623-
Clang->createDiagnostics(*VFS);
621+
auto DiagOpts = llvm::makeIntrusiveRefCnt<DiagnosticOptions>();
622+
auto Diags = CompilerInstance::createDiagnostics(*VFS, DiagOpts.get());
623+
auto Invocation = std::make_unique<CompilerInvocation>();
624+
ASSERT_TRUE(CompilerInvocation::CreateFromArgs(*Invocation, {Filename.data()},
625+
*Diags, "clang"));
624626

625-
Clang->setInvocation(std::make_unique<CompilerInvocation>());
626-
ASSERT_TRUE(CompilerInvocation::CreateFromArgs(
627-
Clang->getInvocation(), {Filename.data()}, Clang->getDiagnostics(),
628-
"clang"));
627+
auto Clang = std::make_unique<CompilerInstance>(std::move(Invocation));
628+
Clang->createDiagnostics(*VFS);
629629

630630
auto *FM = Clang->createFileManager(VFS);
631631
ASSERT_TRUE(Clang->ExecuteAction(*Inputs.MakeAction()));

clang/include/clang/Frontend/CompilerInstance.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ class CompilerInstance : public ModuleLoader {
204204
void operator=(const CompilerInstance &) = delete;
205205
public:
206206
explicit CompilerInstance(
207+
std::shared_ptr<CompilerInvocation> Invocation =
208+
std::make_shared<CompilerInvocation>(),
207209
std::shared_ptr<PCHContainerOperations> PCHContainerOps =
208210
std::make_shared<PCHContainerOperations>(),
209211
ModuleCache *ModCache = nullptr);
@@ -251,18 +253,10 @@ class CompilerInstance : public ModuleLoader {
251253
/// @name Compiler Invocation and Options
252254
/// @{
253255

254-
bool hasInvocation() const { return Invocation != nullptr; }
255-
256-
CompilerInvocation &getInvocation() {
257-
assert(Invocation && "Compiler instance has no invocation!");
258-
return *Invocation;
259-
}
256+
CompilerInvocation &getInvocation() { return *Invocation; }
260257

261258
std::shared_ptr<CompilerInvocation> getInvocationPtr() { return Invocation; }
262259

263-
/// setInvocation - Replace the current invocation.
264-
void setInvocation(std::shared_ptr<CompilerInvocation> Value);
265-
266260
/// Indicates whether we should (re)build the global module index.
267261
bool shouldBuildGlobalModuleIndex() const;
268262

clang/lib/Frontend/ASTUnit.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,9 +1162,8 @@ bool ASTUnit::Parse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
11621162
}
11631163

11641164
// Create the compiler instance to use for building the AST.
1165-
std::unique_ptr<CompilerInstance> Clang(
1166-
new CompilerInstance(std::move(PCHContainerOps)));
1167-
Clang->setInvocation(CCInvocation);
1165+
auto Clang = std::make_unique<CompilerInstance>(CCInvocation,
1166+
std::move(PCHContainerOps));
11681167

11691168
// Clean up on error, disengage it if the function returns successfully.
11701169
auto CleanOnError = llvm::make_scope_exit([&]() {
@@ -1487,7 +1486,6 @@ void ASTUnit::RealizeTopLevelDeclsFromPreamble() {
14871486
void ASTUnit::transferASTDataFromCompilerInstance(CompilerInstance &CI) {
14881487
// Steal the created target, context, and preprocessor if they have been
14891488
// created.
1490-
assert(CI.hasInvocation() && "missing invocation");
14911489
LangOpts = std::make_unique<LangOptions>(CI.getInvocation().getLangOpts());
14921490
TheSema = CI.takeSema();
14931491
Consumer = CI.takeASTConsumer();
@@ -1601,14 +1599,13 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
16011599
AST->getFileManager().getVirtualFileSystem());
16021600

16031601
// Create the compiler instance to use for building the AST.
1604-
std::unique_ptr<CompilerInstance> Clang(
1605-
new CompilerInstance(std::move(PCHContainerOps)));
1602+
auto Clang = std::make_unique<CompilerInstance>(std::move(CI),
1603+
std::move(PCHContainerOps));
16061604

16071605
// Recover resources if we crash before exiting this method.
16081606
llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
16091607
CICleanup(Clang.get());
16101608

1611-
Clang->setInvocation(std::move(CI));
16121609
AST->OriginalSourceFile =
16131610
std::string(Clang->getFrontendOpts().Inputs[0].getFile());
16141611

@@ -2232,15 +2229,14 @@ void ASTUnit::CodeComplete(
22322229
LangOpts.SpellChecking = false;
22332230
CCInvocation->getDiagnosticOpts().IgnoreWarnings = true;
22342231

2235-
std::unique_ptr<CompilerInstance> Clang(
2236-
new CompilerInstance(PCHContainerOps));
2232+
auto Clang = std::make_unique<CompilerInstance>(std::move(CCInvocation),
2233+
PCHContainerOps);
22372234

22382235
// Recover resources if we crash before exiting this method.
22392236
llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
22402237
CICleanup(Clang.get());
22412238

2242-
auto &Inv = *CCInvocation;
2243-
Clang->setInvocation(std::move(CCInvocation));
2239+
auto &Inv = Clang->getInvocation();
22442240
OriginalSourceFile =
22452241
std::string(Clang->getFrontendOpts().Inputs[0].getFile());
22462242

@@ -2254,7 +2250,6 @@ void ASTUnit::CodeComplete(
22542250

22552251
// Create the target instance.
22562252
if (!Clang->createTarget()) {
2257-
Clang->setInvocation(nullptr);
22582253
return;
22592254
}
22602255

clang/lib/Frontend/ChainedIncludesSource.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,8 @@ IntrusiveRefCntPtr<ExternalSemaSource> clang::createChainedIncludesSource(
122122
IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
123123
new DiagnosticsEngine(DiagID, &CI.getDiagnosticOpts(), DiagClient));
124124

125-
std::unique_ptr<CompilerInstance> Clang(
126-
new CompilerInstance(CI.getPCHContainerOperations()));
127-
Clang->setInvocation(std::move(CInvok));
125+
auto Clang = std::make_unique<CompilerInstance>(
126+
std::move(CInvok), CI.getPCHContainerOperations());
128127
Clang->setDiagnostics(Diags.get());
129128
Clang->setTarget(TargetInfo::CreateTargetInfo(
130129
Clang->getDiagnostics(), Clang->getInvocation().getTargetOpts()));

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,20 @@
6767
using namespace clang;
6868

6969
CompilerInstance::CompilerInstance(
70+
std::shared_ptr<CompilerInvocation> Invocation,
7071
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
7172
ModuleCache *ModCache)
7273
: ModuleLoader(/*BuildingModule=*/ModCache),
73-
Invocation(new CompilerInvocation()),
74+
Invocation(std::move(Invocation)),
7475
ModCache(ModCache ? ModCache : createCrossProcessModuleCache()),
75-
ThePCHContainerOperations(std::move(PCHContainerOps)) {}
76+
ThePCHContainerOperations(std::move(PCHContainerOps)) {
77+
assert(this->Invocation && "Invocation must not be null");
78+
}
7679

7780
CompilerInstance::~CompilerInstance() {
7881
assert(OutputFiles.empty() && "Still output files in flight?");
7982
}
8083

81-
void CompilerInstance::setInvocation(
82-
std::shared_ptr<CompilerInvocation> Value) {
83-
Invocation = std::move(Value);
84-
}
85-
8684
bool CompilerInstance::shouldBuildGlobalModuleIndex() const {
8785
return (BuildGlobalModuleIndex ||
8886
(TheASTReader && TheASTReader->isGlobalIndexUnavailable() &&
@@ -1213,11 +1211,10 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl(
12131211
// CompilerInstance::CompilerInstance is responsible for finalizing the
12141212
// buffers to prevent use-after-frees.
12151213
auto InstancePtr = std::make_unique<CompilerInstance>(
1216-
getPCHContainerOperations(), &getModuleCache());
1214+
std::move(Invocation), getPCHContainerOperations(), &getModuleCache());
12171215
auto &Instance = *InstancePtr;
12181216

1219-
auto &Inv = *Invocation;
1220-
Instance.setInvocation(std::move(Invocation));
1217+
auto &Inv = Instance.getInvocation();
12211218

12221219
if (ThreadSafeConfig) {
12231220
Instance.createFileManager(ThreadSafeConfig->getVFS());

clang/lib/Frontend/PrecompiledPreamble.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,13 @@ llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build(
454454
PreprocessorOpts.GeneratePreamble = true;
455455

456456
// Create the compiler instance to use for building the precompiled preamble.
457-
std::unique_ptr<CompilerInstance> Clang(
458-
new CompilerInstance(std::move(PCHContainerOps)));
457+
auto Clang = std::make_unique<CompilerInstance>(std::move(PreambleInvocation),
458+
std::move(PCHContainerOps));
459459

460460
// Recover resources if we crash before exiting this method.
461461
llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance> CICleanup(
462462
Clang.get());
463463

464-
Clang->setInvocation(std::move(PreambleInvocation));
465464
Clang->setDiagnostics(&Diagnostics);
466465

467466
// Create the target instance.

clang/lib/Frontend/Rewrite/FrontendActions.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,9 @@ class RewriteIncludesAction::RewriteImportsListener : public ASTReaderListener {
242242
(*OS) << '\n';
243243

244244
// Rewrite the contents of the module in a separate compiler instance.
245-
CompilerInstance Instance(CI.getPCHContainerOperations(),
246-
&CI.getModuleCache());
247-
Instance.setInvocation(
248-
std::make_shared<CompilerInvocation>(CI.getInvocation()));
245+
CompilerInstance Instance(
246+
std::make_shared<CompilerInvocation>(CI.getInvocation()),
247+
CI.getPCHContainerOperations(), &CI.getModuleCache());
249248
Instance.createDiagnostics(
250249
CI.getVirtualFileSystem(),
251250
new ForwardingDiagnosticConsumer(CI.getDiagnosticClient()),

clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ void ModelInjector::onBodySynthesis(const NamedDecl *D) {
7575

7676
// Modules are parsed by a separate CompilerInstance, so this code mimics that
7777
// behavior for models
78-
CompilerInstance Instance(CI.getPCHContainerOperations());
79-
Instance.setInvocation(std::move(Invocation));
78+
CompilerInstance Instance(std::move(Invocation),
79+
CI.getPCHContainerOperations());
8080
Instance.createDiagnostics(
8181
CI.getVirtualFileSystem(),
8282
new ForwardingDiagnosticConsumer(CI.getDiagnosticClient()),

0 commit comments

Comments
 (0)