[clang] 5298057 - [clang-format] refactor the use of the SMDiagnostics in replacement warnings
via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 13 12:56:19 PST 2019
Author: mydeveloperday
Date: 2019-11-13T20:55:44Z
New Revision: 52980576ee4a5683aa9a428b76335ed617f142ab
URL: https://github.com/llvm/llvm-project/commit/52980576ee4a5683aa9a428b76335ed617f142ab
DIFF: https://github.com/llvm/llvm-project/commit/52980576ee4a5683aa9a428b76335ed617f142ab.diff
LOG: [clang-format] refactor the use of the SMDiagnostics in replacement warnings
Summary:
Review comments in {D69854} recommended a simpler approach of creating the SMDiagnostics to remove much of the complexity. (thanks @thakis)
@vlad.tsyrklevich I've rebuilt on both Windows and Linux (running Linux with Address and Undefined sanitizers) over the clang code base
Reviewers: thakis, klimek, mitchell-stellar, vlad.tsyrklevich
Reviewed By: thakis
Subscribers: cfe-commits, thakis, vlad.tsyrklevich
Tags: #clang-format, #clang
Differential Revision: https://reviews.llvm.org/D69921
Added:
Modified:
clang/tools/clang-format/ClangFormat.cpp
Removed:
################################################################################
diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp
index faf645108da7..aa40bab52df5 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -292,56 +292,25 @@ static void outputReplacementsXML(const Replacements &Replaces) {
static bool
emitReplacementWarnings(const Replacements &Replaces, StringRef AssumedFileName,
const std::unique_ptr<llvm::MemoryBuffer> &Code) {
- if (Replaces.empty()) {
+ if (Replaces.empty())
return false;
- }
-
- IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
- DiagOpts->ShowColors = (ShowColors && !NoShowColors);
-
- IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
- IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
- new DiagnosticsEngine(DiagID, &*DiagOpts));
-
- IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
- new llvm::vfs::InMemoryFileSystem);
- FileManager Files(FileSystemOptions(), InMemoryFileSystem);
- SourceManager Sources(*Diags, Files);
- FileID FileID = createInMemoryFile(AssumedFileName, Code.get(), Sources,
- Files, InMemoryFileSystem.get());
-
- FileManager &FileMgr = Sources.getFileManager();
- llvm::ErrorOr<const FileEntry *> FileEntryPtr =
- FileMgr.getFile(AssumedFileName);
unsigned Errors = 0;
if (WarnFormat && !NoWarnFormat) {
llvm::SourceMgr Mgr;
- for (const auto &R : Replaces) {
- PresumedLoc PLoc = Sources.getPresumedLoc(
- Sources.getLocForStartOfFile(FileID).getLocWithOffset(R.getOffset()));
-
- SourceLocation LineBegin =
- Sources.translateFileLineCol(FileEntryPtr.get(), PLoc.getLine(), 1);
- SourceLocation NextLineBegin = Sources.translateFileLineCol(
- FileEntryPtr.get(), PLoc.getLine() + 1, 1);
+ const char *StartBuf = Code->getBufferStart();
- const char *StartBuf = Sources.getCharacterData(LineBegin);
- const char *EndBuf = Sources.getCharacterData(NextLineBegin);
-
- StringRef Line(StartBuf, (EndBuf - StartBuf) - 1);
-
- SMDiagnostic Diag(
- Mgr, SMLoc::getFromPointer(StartBuf), AssumedFileName,
- PLoc.getLine(), PLoc.getColumn(),
+ Mgr.AddNewSourceBuffer(
+ MemoryBuffer::getMemBuffer(StartBuf, AssumedFileName), SMLoc());
+ for (const auto &R : Replaces) {
+ SMDiagnostic Diag = Mgr.GetMessage(
+ SMLoc::getFromPointer(StartBuf + R.getOffset()),
WarningsAsErrors ? SourceMgr::DiagKind::DK_Error
: SourceMgr::DiagKind::DK_Warning,
- "code should be clang-formatted [-Wclang-format-violations]", Line,
- ArrayRef<std::pair<unsigned, unsigned>>());
+ "code should be clang-formatted [-Wclang-format-violations]");
Diag.print(nullptr, llvm::errs(), (ShowColors && !NoShowColors));
- Errors++;
- if (ErrorLimit && Errors >= ErrorLimit)
+ if (ErrorLimit && ++Errors >= ErrorLimit)
break;
}
}
More information about the cfe-commits
mailing list