Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flang/include/flang/Frontend/CompilerInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class CompilerInstance {
///
/// \return The new object on success, or null on failure.
static clang::IntrusiveRefCntPtr<clang::DiagnosticsEngine>
createDiagnostics(clang::DiagnosticOptions *opts,
createDiagnostics(clang::DiagnosticOptions &opts,
clang::DiagnosticConsumer *client = nullptr,
bool shouldOwnClient = true);
void createDiagnostics(clang::DiagnosticConsumer *client = nullptr,
Expand Down
2 changes: 1 addition & 1 deletion flang/include/flang/Frontend/CompilerInvocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bool parseDiagnosticArgs(clang::DiagnosticOptions &opts,
class CompilerInvocationBase {
public:
/// Options controlling the diagnostic engine.
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> diagnosticOpts;
std::shared_ptr<clang::DiagnosticOptions> diagnosticOpts;
/// Options for the preprocessor.
std::shared_ptr<Fortran::frontend::PreprocessorOptions> preprocessorOpts;

Expand Down
4 changes: 2 additions & 2 deletions flang/include/flang/Frontend/TextDiagnosticPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ class TextDiagnostic;

class TextDiagnosticPrinter : public clang::DiagnosticConsumer {
raw_ostream &os;
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> diagOpts;
clang::DiagnosticOptions &diagOpts;

/// A string to prefix to error messages.
std::string prefix;

public:
TextDiagnosticPrinter(raw_ostream &os, clang::DiagnosticOptions *diags);
TextDiagnosticPrinter(raw_ostream &os, clang::DiagnosticOptions &diags);
~TextDiagnosticPrinter() override;

/// Set the diagnostic printer prefix string, which will be printed at the
Expand Down
5 changes: 2 additions & 3 deletions flang/lib/Frontend/CompilerInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,11 @@ bool CompilerInstance::executeAction(FrontendAction &act) {

void CompilerInstance::createDiagnostics(clang::DiagnosticConsumer *client,
bool shouldOwnClient) {
diagnostics =
createDiagnostics(&getDiagnosticOpts(), client, shouldOwnClient);
diagnostics = createDiagnostics(getDiagnosticOpts(), client, shouldOwnClient);
}

clang::IntrusiveRefCntPtr<clang::DiagnosticsEngine>
CompilerInstance::createDiagnostics(clang::DiagnosticOptions *opts,
CompilerInstance::createDiagnostics(clang::DiagnosticOptions &opts,
clang::DiagnosticConsumer *client,
bool shouldOwnClient) {
clang::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagID(
Expand Down
8 changes: 4 additions & 4 deletions flang/lib/Frontend/TextDiagnosticPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
using namespace Fortran::frontend;

TextDiagnosticPrinter::TextDiagnosticPrinter(raw_ostream &diagOs,
clang::DiagnosticOptions *diags)
clang::DiagnosticOptions &diags)
: os(diagOs), diagOpts(diags) {}

TextDiagnosticPrinter::~TextDiagnosticPrinter() {}
Expand Down Expand Up @@ -81,7 +81,7 @@ void TextDiagnosticPrinter::printLocForRemarks(
llvm::sys::path::make_preferred(absPath);

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

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

Fortran::frontend::TextDiagnostic::printDiagnosticLevel(os, level,
diagOpts->ShowColors);
diagOpts.ShowColors);
Fortran::frontend::TextDiagnostic::printDiagnosticMessage(
os,
/*IsSupplemental=*/level == clang::DiagnosticsEngine::Note, diagMsg,
diagOpts->ShowColors);
diagOpts.ShowColors);

os.flush();
}
10 changes: 5 additions & 5 deletions flang/tools/flang-driver/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ std::string getExecutablePath(const char *argv0) {

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

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

// Create DiagnosticsEngine for the compiler driver
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> diagOpts =
std::unique_ptr<clang::DiagnosticOptions> diagOpts =
createAndPopulateDiagOpts(args);
llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagID(
new clang::DiagnosticIDs());
Fortran::frontend::TextDiagnosticPrinter *diagClient =
new Fortran::frontend::TextDiagnosticPrinter(llvm::errs(), &*diagOpts);
new Fortran::frontend::TextDiagnosticPrinter(llvm::errs(), *diagOpts);

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

clang::DiagnosticsEngine diags(diagID, &*diagOpts, diagClient);
clang::DiagnosticsEngine diags(diagID, *diagOpts, diagClient);

// Prepare the driver
clang::driver::Driver theDriver(driverPath,
Expand Down
5 changes: 2 additions & 3 deletions flang/tools/flang-driver/fc1_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ int fc1_main(llvm::ArrayRef<const char *> argv, const char *argv0) {
// for parsing the arguments
llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagID(
new clang::DiagnosticIDs());
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> diagOpts =
new clang::DiagnosticOptions();
clang::DiagnosticsEngine diags(diagID, &*diagOpts, diagsBuffer);
clang::DiagnosticOptions diagOpts;
clang::DiagnosticsEngine diags(diagID, diagOpts, diagsBuffer);
bool success = CompilerInvocation::createFromArgs(flang->getInvocation(),
argv, diags, argv0);

Expand Down
3 changes: 2 additions & 1 deletion flang/unittests/Frontend/CodeGenActionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ class LLVMConversionFailureCodeGenAction : public CodeGenAction {
TEST(CodeGenAction, GracefullyHandleLLVMConversionFailure) {
std::string diagnosticOutput;
llvm::raw_string_ostream diagnosticsOS(diagnosticOutput);
clang::DiagnosticOptions diagOpts;
auto diagPrinter = std::make_unique<Fortran::frontend::TextDiagnosticPrinter>(
diagnosticsOS, new clang::DiagnosticOptions());
diagnosticsOS, diagOpts);

CompilerInstance ci;
ci.createDiagnostics(diagPrinter.get(), /*ShouldOwnClient=*/false);
Expand Down
7 changes: 4 additions & 3 deletions flang/unittests/Frontend/CompilerInstanceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,19 @@ TEST(CompilerInstance, AllowDiagnosticLogWithUnownedDiagnosticConsumer) {
// 1. Set-up a basic DiagnosticConsumer
std::string diagnosticOutput;
llvm::raw_string_ostream diagnosticsOS(diagnosticOutput);
clang::DiagnosticOptions diagPrinterOpts;
auto diagPrinter = std::make_unique<Fortran::frontend::TextDiagnosticPrinter>(
diagnosticsOS, new clang::DiagnosticOptions());
diagnosticsOS, diagPrinterOpts);

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

// 3. Set-up DiagnosticOptions
auto diagOpts = new clang::DiagnosticOptions();
clang::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 = "-";

// 4. Create a DiagnosticEngine with an unowned consumer
IntrusiveRefCntPtr<clang::DiagnosticsEngine> diags =
Expand Down
Loading