Skip to content

Commit 0981b71

Browse files
committed
Adjust calls to clang::DiagnosticsEngine ctor (now takes ref vs. ptr)
See llvm/llvm-project#139584
1 parent 9322c9f commit 0981b71

File tree

7 files changed

+29
-35
lines changed

7 files changed

+29
-35
lines changed

lib/Basic/TargetInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ void printTripleInfo(const CompilerInvocation &invocation,
145145
out << " \"arch\": \"" << swift::getMajorArchitectureName(triple)
146146
<< "\",\n";
147147

148-
clang::DiagnosticsEngine DE{new clang::DiagnosticIDs(),
149-
new clang::DiagnosticOptions(),
148+
clang::DiagnosticOptions diagOpts;
149+
clang::DiagnosticsEngine DE{new clang::DiagnosticIDs(), diagOpts,
150150
new clang::IgnoringDiagConsumer()};
151151

152152
clang::TargetOptions targetOpts;

lib/ClangImporter/ClangDiagnosticConsumer.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ namespace {
3434

3535
public:
3636
ClangDiagRenderer(const clang::LangOptions &langOpts,
37-
clang::DiagnosticOptions *diagOpts,
38-
decltype(callback) fn)
39-
: DiagnosticNoteRenderer(langOpts, diagOpts),
40-
callback(fn) {}
37+
clang::DiagnosticOptions &diagOpts, decltype(callback) fn)
38+
: DiagnosticNoteRenderer(langOpts, diagOpts), callback(fn) {}
4139

4240
private:
4341
/// Is this a diagnostic that doesn't do the user any good to show if it
@@ -107,10 +105,9 @@ namespace {
107105

108106
ClangDiagnosticConsumer::ClangDiagnosticConsumer(
109107
ClangImporter::Implementation &impl,
110-
clang::DiagnosticOptions &clangDiagOptions,
111-
bool dumpToStderr)
112-
: TextDiagnosticPrinter(llvm::errs(), &clangDiagOptions),
113-
ImporterImpl(impl), DumpToStderr(dumpToStderr) {}
108+
clang::DiagnosticOptions &clangDiagOptions, bool dumpToStderr)
109+
: TextDiagnosticPrinter(llvm::errs(), clangDiagOptions), ImporterImpl(impl),
110+
DumpToStderr(dumpToStderr) {}
114111

115112
void ClangDiagnosticConsumer::HandleDiagnostic(
116113
clang::DiagnosticsEngine::Level clangDiagLevel,
@@ -179,7 +176,7 @@ void ClangDiagnosticConsumer::HandleDiagnostic(
179176
assert(clangDiag.hasSourceManager());
180177
auto clangCI = ImporterImpl.getClangInstance();
181178
ClangDiagRenderer renderer(clangCI->getLangOpts(),
182-
&clangCI->getDiagnosticOpts(), emitDiag);
179+
clangCI->getDiagnosticOpts(), emitDiag);
183180
clang::FullSourceLoc clangDiagLoc(clangDiag.getLocation(),
184181
clangDiag.getSourceManager());
185182
renderer.emitDiagnostic(clangDiagLoc, clangDiagLevel, message,

lib/ClangImporter/ClangImporter.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -984,10 +984,11 @@ bool ClangImporter::canReadPCH(StringRef PCHFilename) {
984984
// will try to free it.
985985
invocation->getPreprocessorOpts().RemappedFileBuffers.clear();
986986

987+
clang::DiagnosticOptions diagOpts;
987988
CI.setInvocation(std::move(invocation));
988989
CI.setTarget(&Impl.Instance->getTarget());
989990
CI.setDiagnostics(&*clang::CompilerInstance::createDiagnostics(
990-
Impl.Instance->getVirtualFileSystem(), new clang::DiagnosticOptions()));
991+
Impl.Instance->getVirtualFileSystem(), diagOpts));
991992

992993
// Note: Reusing the file manager is safe; this is a component that's already
993994
// reused when building PCM files for the module cache.
@@ -1139,13 +1140,11 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
11391140
//
11401141
// The long-term client for Clang diagnostics is set up afterwards, after the
11411142
// clang::CompilerInstance is created.
1142-
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> tempDiagOpts{
1143-
new clang::DiagnosticOptions};
1144-
auto *tempDiagClient =
1145-
new ClangDiagnosticConsumer(Impl, *tempDiagOpts,
1146-
ctx.ClangImporterOpts.DumpClangDiagnostics);
1143+
clang::DiagnosticOptions tempDiagOpts;
1144+
auto *tempDiagClient = new ClangDiagnosticConsumer(
1145+
Impl, tempDiagOpts, ctx.ClangImporterOpts.DumpClangDiagnostics);
11471146
auto clangDiags = clang::CompilerInstance::createDiagnostics(
1148-
*VFS, tempDiagOpts.get(), tempDiagClient,
1147+
*VFS, tempDiagOpts, tempDiagClient,
11491148
/*owned*/ true);
11501149

11511150
// If using direct cc1 module build, use extra args to setup ClangImporter.
@@ -1265,10 +1264,10 @@ std::unique_ptr<clang::CompilerInvocation> ClangImporter::createClangInvocation(
12651264
// option here is either generated by dependency scanner or just round tripped
12661265
// from `getClangCC1Arguments` so we don't expect it to fail. Use a simple
12671266
// printing diagnostics consumer for debugging any unexpected error.
1268-
auto diagOpts = llvm::makeIntrusiveRefCnt<clang::DiagnosticOptions>();
1267+
clang::DiagnosticOptions diagOpts;
12691268
clang::DiagnosticsEngine clangDiags(
12701269
new clang::DiagnosticIDs(), diagOpts,
1271-
new clang::TextDiagnosticPrinter(llvm::errs(), diagOpts.get()));
1270+
new clang::TextDiagnosticPrinter(llvm::errs(), diagOpts));
12721271

12731272
// Finally, use the CC1 command-line and the diagnostic engine
12741273
// to instantiate our Invocation.
@@ -4161,8 +4160,8 @@ ClangImporter::getSwiftExplicitModuleDirectCC1Args() const {
41614160
});
41624161

41634162
clang::CompilerInvocation instance;
4164-
clang::DiagnosticsEngine clangDiags(new clang::DiagnosticIDs(),
4165-
new clang::DiagnosticOptions(),
4163+
clang::DiagnosticOptions diagOpts;
4164+
clang::DiagnosticsEngine clangDiags(new clang::DiagnosticIDs(), diagOpts,
41664165
new clang::IgnoringDiagConsumer());
41674166
bool success = clang::CompilerInvocation::CreateFromArgs(instance, clangArgs,
41684167
clangDiags);

lib/ClangImporter/ClangIncludePaths.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,10 @@ ClangImporter::createClangDriver(
130130

131131
auto diagVFS = vfs ? vfs : llvm::vfs::getRealFileSystem();
132132

133+
clang::DiagnosticOptions diagOpts;
133134
auto *silentDiagConsumer = new clang::DiagnosticConsumer();
134135
auto clangDiags = clang::CompilerInstance::createDiagnostics(
135-
*diagVFS, new clang::DiagnosticOptions(), silentDiagConsumer);
136+
*diagVFS, diagOpts, silentDiagConsumer);
136137
clang::driver::Driver clangDriver(ClangImporterOpts.clangPath,
137138
LangOpts.Target.str(), *clangDiags,
138139
"clang LLVM compiler", vfs);

lib/ClangImporter/ClangModuleDependencyScanner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ void ClangImporter::getBridgingHeaderOptions(
228228
// Round-trip clang args to canonicalize and clear the options that swift
229229
// compiler doesn't need.
230230
clang::CompilerInvocation depsInvocation;
231-
clang::DiagnosticsEngine clangDiags(new clang::DiagnosticIDs(),
232-
new clang::DiagnosticOptions(),
231+
clang::DiagnosticOptions diagOpts;
232+
clang::DiagnosticsEngine clangDiags(new clang::DiagnosticIDs(), diagOpts,
233233
new clang::IgnoringDiagConsumer());
234234

235235
llvm::SmallVector<const char *> clangArgs;

lib/IDETool/CompilerInvocation.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,12 @@ bool ide::initCompilerInvocation(
267267
bool ide::initInvocationByClangArguments(ArrayRef<const char *> ArgList,
268268
CompilerInvocation &Invok,
269269
std::string &Error) {
270-
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> DiagOpts{
271-
new clang::DiagnosticOptions()
272-
};
273-
274270
const auto VFS = llvm::vfs::getRealFileSystem();
275271

276272
clang::TextDiagnosticBuffer DiagBuf;
273+
clang::DiagnosticOptions DiagOpts;
277274
llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine> ClangDiags =
278-
clang::CompilerInstance::createDiagnostics(*VFS, DiagOpts.get(), &DiagBuf,
275+
clang::CompilerInstance::createDiagnostics(*VFS, DiagOpts, &DiagBuf,
279276
/*ShouldOwnClient=*/false);
280277

281278
// Clang expects this to be like an actual command line. So we need to pass in

lib/Migrator/Migrator.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@ bool Migrator::performSyntacticPasses(SyntacticPassOptions Opts) {
191191
llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> DummyClangDiagIDs {
192192
new clang::DiagnosticIDs()
193193
};
194-
auto ClangDiags =
195-
std::make_unique<clang::DiagnosticsEngine>(DummyClangDiagIDs,
196-
new clang::DiagnosticOptions,
197-
new clang::DiagnosticConsumer(),
198-
/*ShouldOwnClient=*/true);
194+
195+
clang::DiagnosticOptions diagOpts;
196+
auto ClangDiags = std::make_unique<clang::DiagnosticsEngine>(
197+
DummyClangDiagIDs, diagOpts, new clang::DiagnosticConsumer(),
198+
/*ShouldOwnClient=*/true);
199199

200200
clang::SourceManager ClangSourceManager { *ClangDiags, ClangFileManager };
201201
clang::LangOptions ClangLangOpts;

0 commit comments

Comments
 (0)