[Libreoffice-commits] core.git: compilerplugins/clang

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Fri Jan 17 22:58:49 UTC 2020


 compilerplugins/clang/duplicate-defines.cxx |   23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

New commits:
commit a169864a242588066c075ae626a27467dc9ff199
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Fri Jan 17 18:38:37 2020 +0100
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Fri Jan 17 23:58:11 2020 +0100

    Adapt loplugin:duplicatedefines to include/premac.h
    
    Change-Id: I2f79409f0fe2a18ba00585a35b6f1cf6243b7c1b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86995
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/compilerplugins/clang/duplicate-defines.cxx b/compilerplugins/clang/duplicate-defines.cxx
index ba4a69d2f867..fc0c49655a22 100644
--- a/compilerplugins/clang/duplicate-defines.cxx
+++ b/compilerplugins/clang/duplicate-defines.cxx
@@ -9,6 +9,7 @@
  *
  */
 
+#include <cassert>
 #include <iostream>
 #include <unordered_map>
 
@@ -89,12 +90,28 @@ void DuplicateDefines::MacroDefined(const Token& rMacroNameTok, const MacroDirec
         || aMacroName == "STR_TABLE_NUMFORMAT" || aMacroName == "STR_DELETE")
         return;
 
-    if (!m_aDefMap.emplace(aMacroName, Entry{ aLoc }).second)
+    if (m_aDefMap.emplace(aMacroName, Entry{ aLoc }).second)
     {
-        report(DiagnosticsEngine::Warning, "duplicate defines", aLoc);
-        report(DiagnosticsEngine::Note, "previous define", m_aDefMap[aMacroName].m_aLoc);
         return;
     }
+
+    // Happens e.g. with macros defined in include/premac.h, which is intended to be included
+    // (without include guards) multiple times:
+    auto const other = m_aDefMap[aMacroName].m_aLoc;
+    assert(aLoc == compiler.getSourceManager().getSpellingLoc(aLoc));
+    assert(other == compiler.getSourceManager().getSpellingLoc(other));
+    if ((compiler.getSourceManager().getFilename(aLoc)
+         == compiler.getSourceManager().getFilename(other))
+        && (compiler.getSourceManager().getSpellingLineNumber(aLoc)
+            == compiler.getSourceManager().getSpellingLineNumber(other))
+        && (compiler.getSourceManager().getSpellingColumnNumber(aLoc)
+            == compiler.getSourceManager().getSpellingColumnNumber(other)))
+    {
+        return;
+    }
+
+    report(DiagnosticsEngine::Warning, "duplicate defines", aLoc);
+    report(DiagnosticsEngine::Note, "previous define", other);
 }
 
 void DuplicateDefines::MacroUndefined(const Token& rMacroNameTok, const MacroDefinition& /*MD*/,


More information about the Libreoffice-commits mailing list