AlexanderLanin created this revision.
AlexanderLanin added a project: clang-tools-extra.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
AlexanderLanin added a comment.

Important: I'm not a python expert. It works fine as far as I can tell. I would 
feel better if someone with more than a day python experience would say that it 
is fine.


The generated file is now small enough to not hinder any post processing.

>> Create a yaml file to store suggested fixes in, which can be applied with 
>> clang-apply-replacements.

So it's enough to store the fixes, not all the warnings.
Before this change the resulting file was simply too large as it contained all 
warnings, least of which had FIX-ITs.

This is trivially achievable with no measureable runtime overhead during 
run-clang-tidy runs, instead of post processing where even parsing the file 
once is extremely slow.


Repository:
  rG LLVM Github Monorepo

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
+def isAutoFixable(diag):
+  if diag["DiagnosticMessage"]["Replacements"]: return True
+
+  if "Notes" in diag:
+    for note in diag["Notes"]:
+      if "Replacements" in note and note["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


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
+def isAutoFixable(diag):
+  if diag["DiagnosticMessage"]["Replacements"]: return True
+
+  if "Notes" in diag:
+    for note in diag["Notes"]:
+      if "Replacements" in note and note["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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to