[PATCH] D72730: [clang-tidy] run-clang-tidy -export-fixes exports only fixes, not all warnings

Alexander Lanin via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 1 13:20:14 PST 2020


AlexanderLanin updated this revision to Diff 241895.
AlexanderLanin added a comment.

Review findings applied (no real measurable difference in speed, maybe 100ms) but it's indeed more readable.
Without this fix the export took 12.96 seconds, with this patch 11.07 seconds.
Difference is even bigger when there are less auto fixable findings (70% with FIX-IT in my example).

As there is no test suite available I run this without and with the change and manually compared the output.
All warnings without FIX-IT have disappeared from exported, all warnings with FIX-IT are unmodified.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72730/new/

https://reviews.llvm.org/D72730

Files:
  clang-tools-extra/clang-tidy/tool/run-clang-tidy.py


Index: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
===================================================================
--- clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -105,6 +105,16 @@
   start.append(f)
   return start
 
+# returns whether passed yaml Diagnostic (see mergekey) element contains FIX-IT
+# FIX-IT replacements can be within the warning directly or within the notes.
+def isAutoFixable(diag):
+  if diag["DiagnosticMessage"]["Replacements"]: return True
+
+  for note in diag.get("Notes", []):
+    if note.get("Replacements", []):
+      return True
+
+  return False
 
 def merge_replacement_files(tmpdir, mergefile):
   """Merge all replacement files in a directory into a single file"""
@@ -116,7 +126,9 @@
     content = yaml.safe_load(open(replacefile, 'r'))
     if not content:
       continue # Skip empty files.
-    merged.extend(content.get(mergekey, []))
+    for d in content.get(mergekey, []):
+      if isAutoFixable(d):
+        merged.append(d)
 
   if merged:
     # MainSourceFile: The key is required by the definition inside


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72730.241895.patch
Type: text/x-patch
Size: 1137 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200201/82b82379/attachment.bin>


More information about the cfe-commits mailing list