]> granicus.if.org Git - clang/commitdiff
clang::tooling::Diagnostic: Don't store offset in the scratch space.
authorAlexander Kornienko <alexfh@google.com>
Wed, 21 Nov 2018 01:08:46 +0000 (01:08 +0000)
committerAlexander Kornienko <alexfh@google.com>
Wed, 21 Nov 2018 01:08:46 +0000 (01:08 +0000)
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

lib/Tooling/Core/Diagnostic.cpp

index 9e4833f2eff4d6f0d8d92bd340ccba3803946888..e3a33d9a37556177d314d2c31b9ebf6cebba27d6 100644 (file)
@@ -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,