[PATCH] D53194: [clang-tidy] Fix check_clang_tidy.py trivially passing default CHECK

Zinovy Nis via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 12 05:34:51 PDT 2018


zinovy.nis created this revision.
zinovy.nis added reviewers: ymandel, alexfh.
zinovy.nis added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, xazax.hun.

In https://reviews.llvm.org/D52971#1262200, @ymandel wrote:

> Hi,
> 
> It looks like this change has disabled FileCheck for all clang-tidy lit tests that don't use check-prefixes.  So, they all trivially pass even if their CHECK... lines are wrong.  An easy repro is just to randomly modify any CHECK line in a lit file (e.g. llvm/tools/clang/tools/extra/test/clang-tidy/readability-avoid-const-params-in-decls.cpp) and run ninja check-clang-tools.
> 
> In check_clang_tidy.py, if you add back (slightly modified) lines 93-95 to the else branch (line 132), it seems to fix the problem.  For example, add:
> 
>   has_check_fixes = check_fixes_prefixes[0] in input_text
>   has_check_messages = check_messages_prefixes[0] in input_text
>   has_check_notes = check_notes_prefixes[0] in input_text


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53194

Files:
  test/clang-tidy/check_clang_tidy.py


Index: test/clang-tidy/check_clang_tidy.py
===================================================================
--- test/clang-tidy/check_clang_tidy.py
+++ test/clang-tidy/check_clang_tidy.py
@@ -51,7 +51,7 @@
   parser.add_argument('check_name')
   parser.add_argument('temp_file_name')
   parser.add_argument('-check-suffix', '-check-suffixes',
-                      default=[], type=csv,
+                      default=[''], type=csv,
                       help="comma-separated list of FileCheck suffixes")
 
   args, extra_args = parser.parse_known_args()
@@ -96,41 +96,37 @@
   has_check_messages = False
   has_check_notes = False
 
-  if any(args.check_suffix):
-    for check in args.check_suffix:
-      if not re.match('^[A-Z0-9\-]+$', check):
-        sys.exit('Only A..Z, 0..9 and "-" are ' +
-          'allowed in check suffixes list, but "%s" was given' % (check))
-
-      file_check_suffix = '-' + check
-      check_fixes_prefix = 'CHECK-FIXES' + file_check_suffix
-      check_messages_prefix = 'CHECK-MESSAGES' + file_check_suffix
-      check_notes_prefix = 'CHECK-NOTES' + file_check_suffix
-
-      has_check_fix = check_fixes_prefix in input_text 
-      has_check_message = check_messages_prefix in input_text
-      has_check_note = check_notes_prefix in input_text 
-
-      if has_check_note and has_check_message:
-        sys.exit('Please use either %s or %s but not both' %
-          (check_notes_prefix, check_messages_prefix))
-
-      if not has_check_fix and not has_check_message and not has_check_note:
-        sys.exit('%s, %s or %s not found in the input' %
-          (check_fixes_prefix, check_messages_prefix, check_notes_prefix))
-
-      has_check_fixes = has_check_fixes or has_check_fix
-      has_check_messages = has_check_messages or has_check_message
-      has_check_notes = has_check_notes or has_check_note
-
-      check_fixes_prefixes.append(check_fixes_prefix)
-      check_messages_prefixes.append(check_messages_prefix)
-      check_notes_prefixes.append(check_notes_prefix)
-  else:
-    check_fixes_prefixes = ['CHECK-FIXES']
-    check_messages_prefixes = ['CHECK-MESSAGES']
-    check_notes_prefixes = ['CHECK-NOTES']
+  for check in args.check_suffix:
+    if check and not re.match('^[A-Z0-9\-]+$', check):
+      sys.exit('Only A..Z, 0..9 and "-" are ' +
+        'allowed in check suffixes list, but "%s" was given' % (check))
 
+    file_check_suffix = ('-' + check) if check else ''
+    check_fixes_prefix = 'CHECK-FIXES' + file_check_suffix
+    check_messages_prefix = 'CHECK-MESSAGES' + file_check_suffix
+    check_notes_prefix = 'CHECK-NOTES' + file_check_suffix
+
+    has_check_fix = check_fixes_prefix in input_text
+    has_check_message = check_messages_prefix in input_text
+    has_check_note = check_notes_prefix in input_text
+
+    if has_check_note and has_check_message:
+      sys.exit('Please use either %s or %s but not both' %
+        (check_notes_prefix, check_messages_prefix))
+
+    if not has_check_fix and not has_check_message and not has_check_note:
+      sys.exit('%s, %s or %s not found in the input' %
+        (check_fixes_prefix, check_messages_prefix, check_notes_prefix))
+
+    has_check_fixes = has_check_fixes or has_check_fix
+    has_check_messages = has_check_messages or has_check_message
+    has_check_notes = has_check_notes or has_check_note
+
+    check_fixes_prefixes.append(check_fixes_prefix)
+    check_messages_prefixes.append(check_messages_prefix)
+    check_notes_prefixes.append(check_notes_prefix)
+
+  assert has_check_fixes or has_check_messages or has_check_notes
   # Remove the contents of the CHECK lines to avoid CHECKs matching on
   # themselves.  We need to keep the comments to preserve line numbers while
   # avoiding empty lines which could potentially trigger formatting-related


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53194.169379.patch
Type: text/x-patch
Size: 3827 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181012/4a781638/attachment.bin>


More information about the cfe-commits mailing list