From: Alexander Kornienko Date: Wed, 21 Nov 2018 01:08:46 +0000 (+0000) Subject: clang::tooling::Diagnostic: Don't store offset in the scratch space. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7ff519cbd858f949b9b5afabfbd824c66cd497de;p=clang clang::tooling::Diagnostic: Don't store offset in the scratch space. These offsets are useless (and even harmful in certain cases) in exported diagnostics. The test will be added to clang-tidy, since it's the main user of the clang::tooling::Diagnostic class. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@347372 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Tooling/Core/Diagnostic.cpp b/lib/Tooling/Core/Diagnostic.cpp index 9e4833f2ef..e3a33d9a37 100644 --- a/lib/Tooling/Core/Diagnostic.cpp +++ b/lib/Tooling/Core/Diagnostic.cpp @@ -23,10 +23,15 @@ DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message) DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message, const SourceManager &Sources, SourceLocation Loc) - : Message(Message) { + : Message(Message), FileOffset(0) { assert(Loc.isValid() && Loc.isFileID()); FilePath = Sources.getFilename(Loc); - FileOffset = Sources.getFileOffset(Loc); + + // Don't store offset in the scratch space. It doesn't tell anything to the + // user. Moreover, it depends on the history of macro expansions and thus + // prevents deduplication of warnings in headers. + if (!FilePath.empty()) + FileOffset = Sources.getFileOffset(Loc); } Diagnostic::Diagnostic(llvm::StringRef DiagnosticName,