Skip to content

Commit 3ea2cec

Browse files
authored
[flang] Fix build after 9e306ad (#141134)
1 parent 45d8759 commit 3ea2cec

File tree

9 files changed

+23
-23
lines changed

9 files changed

+23
-23
lines changed

flang/include/flang/Frontend/CompilerInstance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ class CompilerInstance {
347347
///
348348
/// \return The new object on success, or null on failure.
349349
static clang::IntrusiveRefCntPtr<clang::DiagnosticsEngine>
350-
createDiagnostics(clang::DiagnosticOptions *opts,
350+
createDiagnostics(clang::DiagnosticOptions &opts,
351351
clang::DiagnosticConsumer *client = nullptr,
352352
bool shouldOwnClient = true);
353353
void createDiagnostics(clang::DiagnosticConsumer *client = nullptr,

flang/include/flang/Frontend/CompilerInvocation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ bool parseDiagnosticArgs(clang::DiagnosticOptions &opts,
4343
class CompilerInvocationBase {
4444
public:
4545
/// Options controlling the diagnostic engine.
46-
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> diagnosticOpts;
46+
std::shared_ptr<clang::DiagnosticOptions> diagnosticOpts;
4747
/// Options for the preprocessor.
4848
std::shared_ptr<Fortran::frontend::PreprocessorOptions> preprocessorOpts;
4949

flang/include/flang/Frontend/TextDiagnosticPrinter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ class TextDiagnostic;
3737

3838
class TextDiagnosticPrinter : public clang::DiagnosticConsumer {
3939
raw_ostream &os;
40-
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> diagOpts;
40+
clang::DiagnosticOptions &diagOpts;
4141

4242
/// A string to prefix to error messages.
4343
std::string prefix;
4444

4545
public:
46-
TextDiagnosticPrinter(raw_ostream &os, clang::DiagnosticOptions *diags);
46+
TextDiagnosticPrinter(raw_ostream &os, clang::DiagnosticOptions &diags);
4747
~TextDiagnosticPrinter() override;
4848

4949
/// Set the diagnostic printer prefix string, which will be printed at the

flang/lib/Frontend/CompilerInstance.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,11 @@ bool CompilerInstance::executeAction(FrontendAction &act) {
226226

227227
void CompilerInstance::createDiagnostics(clang::DiagnosticConsumer *client,
228228
bool shouldOwnClient) {
229-
diagnostics =
230-
createDiagnostics(&getDiagnosticOpts(), client, shouldOwnClient);
229+
diagnostics = createDiagnostics(getDiagnosticOpts(), client, shouldOwnClient);
231230
}
232231

233232
clang::IntrusiveRefCntPtr<clang::DiagnosticsEngine>
234-
CompilerInstance::createDiagnostics(clang::DiagnosticOptions *opts,
233+
CompilerInstance::createDiagnostics(clang::DiagnosticOptions &opts,
235234
clang::DiagnosticConsumer *client,
236235
bool shouldOwnClient) {
237236
clang::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagID(

flang/lib/Frontend/TextDiagnosticPrinter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
using namespace Fortran::frontend;
2828

2929
TextDiagnosticPrinter::TextDiagnosticPrinter(raw_ostream &diagOs,
30-
clang::DiagnosticOptions *diags)
30+
clang::DiagnosticOptions &diags)
3131
: os(diagOs), diagOpts(diags) {}
3232

3333
TextDiagnosticPrinter::~TextDiagnosticPrinter() {}
@@ -81,7 +81,7 @@ void TextDiagnosticPrinter::printLocForRemarks(
8181
llvm::sys::path::make_preferred(absPath);
8282

8383
// Used for changing only the bold attribute
84-
if (diagOpts->ShowColors)
84+
if (diagOpts.ShowColors)
8585
os.changeColor(llvm::raw_ostream::SAVEDCOLOR, true);
8686

8787
// Print path, file name, line and column
@@ -113,11 +113,11 @@ void TextDiagnosticPrinter::HandleDiagnostic(
113113
printLocForRemarks(diagMessageStream, diagMsg);
114114

115115
Fortran::frontend::TextDiagnostic::printDiagnosticLevel(os, level,
116-
diagOpts->ShowColors);
116+
diagOpts.ShowColors);
117117
Fortran::frontend::TextDiagnostic::printDiagnosticMessage(
118118
os,
119119
/*IsSupplemental=*/level == clang::DiagnosticsEngine::Note, diagMsg,
120-
diagOpts->ShowColors);
120+
diagOpts.ShowColors);
121121

122122
os.flush();
123123
}

flang/tools/flang-driver/driver.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ std::string getExecutablePath(const char *argv0) {
4343

4444
// This lets us create the DiagnosticsEngine with a properly-filled-out
4545
// DiagnosticOptions instance
46-
static clang::DiagnosticOptions *
46+
static std::unique_ptr<clang::DiagnosticOptions>
4747
createAndPopulateDiagOpts(llvm::ArrayRef<const char *> argv) {
48-
auto *diagOpts = new clang::DiagnosticOptions;
48+
auto diagOpts = std::make_unique<clang::DiagnosticOptions>();
4949

5050
// Ignore missingArgCount and the return value of ParseDiagnosticArgs.
5151
// Any errors that would be diagnosed here will also be diagnosed later,
@@ -114,17 +114,17 @@ int main(int argc, const char **argv) {
114114
// Not in the frontend mode - continue in the compiler driver mode.
115115

116116
// Create DiagnosticsEngine for the compiler driver
117-
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> diagOpts =
117+
std::unique_ptr<clang::DiagnosticOptions> diagOpts =
118118
createAndPopulateDiagOpts(args);
119119
llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagID(
120120
new clang::DiagnosticIDs());
121121
Fortran::frontend::TextDiagnosticPrinter *diagClient =
122-
new Fortran::frontend::TextDiagnosticPrinter(llvm::errs(), &*diagOpts);
122+
new Fortran::frontend::TextDiagnosticPrinter(llvm::errs(), *diagOpts);
123123

124124
diagClient->setPrefix(
125125
std::string(llvm::sys::path::stem(getExecutablePath(args[0]))));
126126

127-
clang::DiagnosticsEngine diags(diagID, &*diagOpts, diagClient);
127+
clang::DiagnosticsEngine diags(diagID, *diagOpts, diagClient);
128128

129129
// Prepare the driver
130130
clang::driver::Driver theDriver(driverPath,

flang/tools/flang-driver/fc1_main.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ int fc1_main(llvm::ArrayRef<const char *> argv, const char *argv0) {
6767
// for parsing the arguments
6868
llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagID(
6969
new clang::DiagnosticIDs());
70-
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> diagOpts =
71-
new clang::DiagnosticOptions();
72-
clang::DiagnosticsEngine diags(diagID, &*diagOpts, diagsBuffer);
70+
clang::DiagnosticOptions diagOpts;
71+
clang::DiagnosticsEngine diags(diagID, diagOpts, diagsBuffer);
7372
bool success = CompilerInvocation::createFromArgs(flang->getInvocation(),
7473
argv, diags, argv0);
7574

flang/unittests/Frontend/CodeGenActionTest.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ class LLVMConversionFailureCodeGenAction : public CodeGenAction {
8686
TEST(CodeGenAction, GracefullyHandleLLVMConversionFailure) {
8787
std::string diagnosticOutput;
8888
llvm::raw_string_ostream diagnosticsOS(diagnosticOutput);
89+
clang::DiagnosticOptions diagOpts;
8990
auto diagPrinter = std::make_unique<Fortran::frontend::TextDiagnosticPrinter>(
90-
diagnosticsOS, new clang::DiagnosticOptions());
91+
diagnosticsOS, diagOpts);
9192

9293
CompilerInstance ci;
9394
ci.createDiagnostics(diagPrinter.get(), /*ShouldOwnClient=*/false);

flang/unittests/Frontend/CompilerInstanceTest.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,19 @@ TEST(CompilerInstance, AllowDiagnosticLogWithUnownedDiagnosticConsumer) {
6767
// 1. Set-up a basic DiagnosticConsumer
6868
std::string diagnosticOutput;
6969
llvm::raw_string_ostream diagnosticsOS(diagnosticOutput);
70+
clang::DiagnosticOptions diagPrinterOpts;
7071
auto diagPrinter = std::make_unique<Fortran::frontend::TextDiagnosticPrinter>(
71-
diagnosticsOS, new clang::DiagnosticOptions());
72+
diagnosticsOS, diagPrinterOpts);
7273

7374
// 2. Create a CompilerInstance (to manage a DiagnosticEngine)
7475
CompilerInstance compInst;
7576

7677
// 3. Set-up DiagnosticOptions
77-
auto diagOpts = new clang::DiagnosticOptions();
78+
clang::DiagnosticOptions diagOpts;
7879
// Tell the diagnostics engine to emit the diagnostic log to STDERR. This
7980
// ensures that a chained diagnostic consumer is created so that the test can
8081
// exercise the unowned diagnostic consumer in a chained consumer.
81-
diagOpts->DiagnosticLogFile = "-";
82+
diagOpts.DiagnosticLogFile = "-";
8283

8384
// 4. Create a DiagnosticEngine with an unowned consumer
8485
IntrusiveRefCntPtr<clang::DiagnosticsEngine> diags =

0 commit comments

Comments
 (0)