[clang] df00267 - clang-format: Add a consumer to diagnostics engine
Krasimir Georgiev via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 29 03:29:07 PDT 2020
Author: Krasimir Georgiev
Date: 2020-10-29T11:28:27+01:00
New Revision: df00267f1fdb0b098dc42f1caa8a59b29c8e0e5f
URL: https://github.com/llvm/llvm-project/commit/df00267f1fdb0b098dc42f1caa8a59b29c8e0e5f
DIFF: https://github.com/llvm/llvm-project/commit/df00267f1fdb0b098dc42f1caa8a59b29c8e0e5f.diff
LOG: clang-format: Add a consumer to diagnostics engine
Contributed by dmikis (Kirill Dmitrenko)!
Otherwise problems like trying to format readonly file in-place led to crashes.
I've added reviewers by looking at `git blame` and other reviews to the changed file, so may have missed someone.
Reviewed By: krasimir
Differential Revision: https://reviews.llvm.org/D90121
Added:
Modified:
clang/tools/clang-format/CMakeLists.txt
clang/tools/clang-format/ClangFormat.cpp
Removed:
################################################################################
diff --git a/clang/tools/clang-format/CMakeLists.txt b/clang/tools/clang-format/CMakeLists.txt
index 35ecdb11253c..28ac4fb5913e 100644
--- a/clang/tools/clang-format/CMakeLists.txt
+++ b/clang/tools/clang-format/CMakeLists.txt
@@ -7,6 +7,7 @@ add_clang_tool(clang-format
set(CLANG_FORMAT_LIB_DEPS
clangBasic
clangFormat
+ clangFrontend
clangRewrite
clangToolingCore
)
diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp
index 3a7247deab46..d7b768329bcc 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -18,6 +18,7 @@
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/Version.h"
#include "clang/Format/Format.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "clang/Rewrite/Core/Rewriter.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
@@ -423,9 +424,11 @@ static bool format(StringRef FileName) {
IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
new llvm::vfs::InMemoryFileSystem);
FileManager Files(FileSystemOptions(), InMemoryFileSystem);
+ IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions());
+ TextDiagnosticPrinter DiagnosticsConsumer(errs(), &*DiagOpts);
DiagnosticsEngine Diagnostics(
- IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs),
- new DiagnosticOptions);
+ IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), &*DiagOpts,
+ &DiagnosticsConsumer, false);
SourceManager Sources(Diagnostics, Files);
FileID ID = createInMemoryFile(AssumedFileName, Code.get(), Sources, Files,
InMemoryFileSystem.get());
More information about the cfe-commits
mailing list