[clang-tools-extra] r333003 - [clang-tidy] SimplifyBoolenExpr doesn't add parens if unary negotiation is of ExprWithCleanups type

2018-05-22 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Tue May 22 10:24:28 2018
New Revision: 333003

URL: http://llvm.org/viewvc/llvm-project?rev=333003&view=rev
Log:
[clang-tidy] SimplifyBoolenExpr doesn't add parens if unary negotiation is of 
ExprWithCleanups type

bool foo(A &S) {
  if (S != (A)S)
return false;
  return true;
}
is fixed into (w/o this patch)

...
return !S != (A)S; // negotiation affects first operand only
}
instead of (with this patch)

...
return S == (A)S; // note == instead of !=
}

Differential Revision: https://reviews.llvm.org/D47122


Modified:
clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/readability-simplify-bool-expr.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp?rev=333003&r1=333002&r2=333003&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp 
Tue May 22 10:24:28 2018
@@ -195,6 +195,9 @@ std::string compareExpressionToZero(cons
 std::string replacementExpression(const MatchFinder::MatchResult &Result,
   bool Negated, const Expr *E) {
   E = E->ignoreParenBaseCasts();
+  if (const auto *EC = dyn_cast(E))
+E = EC->getSubExpr();
+
   const bool NeedsStaticCast = needsStaticCast(E);
   if (Negated) {
 if (const auto *UnOp = dyn_cast(E)) {

Modified: 
clang-tools-extra/trunk/test/clang-tidy/readability-simplify-bool-expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-simplify-bool-expr.cpp?rev=333003&r1=333002&r2=333003&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/readability-simplify-bool-expr.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-simplify-bool-expr.cpp 
Tue May 22 10:24:28 2018
@@ -938,3 +938,13 @@ bool integer_member_implicit_cast(A *p)
 }
 // CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
 // CHECK-FIXES: return p->m != 0;{{$}}
+
+bool operator!=(const A&, const A&) { return false; }
+bool expr_with_cleanups(A &S) {
+  if (S != (A)S)
+return false;
+
+  return true;
+}
+// CHECK-MESSAGES: :[[@LINE-4]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: S == (A)S;{{$}}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r334829 - [clang-tidy] This patch is a fix for D45405 where spaces were mistakenly considered as a part of a type name. So length("int *") was 5 instead of 3 with RemoveStars=0 or

2018-06-15 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Fri Jun 15 06:35:40 2018
New Revision: 334829

URL: http://llvm.org/viewvc/llvm-project?rev=334829&view=rev
Log:
[clang-tidy] This patch is a fix for D45405 where spaces were mistakenly 
considered as a part of a type name. So length("int *") was 5 instead of 3 with 
RemoveStars=0 or 4 with RemoveStars=1

Differential Revision: https://reviews.llvm.org/D45927


Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-auto.rst

clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-min-type-name-length.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp?rev=334829&r1=334828&r2=334829&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp Fri Jun 15 
06:35:40 2018
@@ -11,6 +11,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/CharInfo.h"
 #include "clang/Tooling/FixIt.h"
 
 using namespace clang;
@@ -27,6 +28,34 @@ const char DeclWithNewId[] = "decl_new";
 const char DeclWithCastId[] = "decl_cast";
 const char DeclWithTemplateCastId[] = "decl_template";
 
+size_t GetTypeNameLength(bool RemoveStars, StringRef Text) {
+  enum CharType { Space, Alpha, Punctuation };
+  CharType LastChar = Space, BeforeSpace = Punctuation;
+  size_t NumChars = 0;
+  int TemplateTypenameCntr = 0;
+  for (const unsigned char C : Text) {
+if (C == '<')
+  ++TemplateTypenameCntr;
+else if (C == '>')
+  --TemplateTypenameCntr;
+const CharType NextChar =
+isAlphanumeric(C)
+? Alpha
+: (isWhitespace(C) ||
+   (!RemoveStars && TemplateTypenameCntr == 0 && C == '*'))
+  ? Space
+  : Punctuation;
+if (NextChar != Space) {
+  ++NumChars; // Count the non-space character.
+  if (LastChar == Space && NextChar == Alpha && BeforeSpace == Alpha)
+++NumChars; // Count a single space character between two words.
+  BeforeSpace = NextChar;
+}
+LastChar = NextChar;
+  }
+  return NumChars;
+}
+
 /// \brief Matches variable declarations that have explicit initializers that
 /// are not initializer lists.
 ///
@@ -419,8 +448,10 @@ void UseAutoCheck::replaceExpr(
   SourceRange Range(Loc.getSourceRange());
 
   if (MinTypeNameLength != 0 &&
-  tooling::fixit::getText(Loc.getSourceRange(), FirstDecl->getASTContext())
-  .size() < MinTypeNameLength)
+  GetTypeNameLength(RemoveStars,
+tooling::fixit::getText(Loc.getSourceRange(),
+FirstDecl->getASTContext())) <
+  MinTypeNameLength)
 return;
 
   auto Diag = diag(Range.getBegin(), Message);

Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-auto.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-auto.rst?rev=334829&r1=334828&r2=334829&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-auto.rst 
(original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-auto.rst Fri 
Jun 15 06:35:40 2018
@@ -182,20 +182,37 @@ Options
If the option is set to non-zero (default `5`), the check will ignore type
names having a length less than the option value. The option affects
expressions only, not iterators.
+   Spaces between multi-lexeme type names (``long int``) are considered as one.
+   If ``RemoveStars`` option (see below) is set to non-zero, then ``*s`` in
+   the type are also counted as a part of the type name.
 
 .. code-block:: c++
 
-  // MinTypeNameLength = 0
+  // MinTypeNameLength = 0, RemoveStars=0
 
   int a = static_cast(foo());// ---> auto a = ...
-  bool b = new bool;  // ---> auto b = ...
+  // length(bool *) = 4
+  bool *b = new bool; // ---> auto *b = ...
   unsigned c = static_cast(foo());  // ---> auto c = ...
 
-  // MinTypeNameLength = 8
+  // MinTypeNameLength = 5, RemoveStars=0
 
-  int a = static_cast(foo());// ---> int  a = ...
-  bool b = new bool;  // ---> bool b = ...
-  unsigned c = static_cast(foo());  // ---> auto c = ...
+  int a = static_cast(foo()); // ---> int  a = ...
+  bool b = static_cast(foo());   // ---> bool b = ...
+  bool *pb = static_cast(foo());// ---> bool *pb = ...
+  unsigned c = static_cast(foo());   // ---> auto c = ...
+  // length(long  int) = 8
+  long int d = static_cast(foo()

[clang-tools-extra] r344343 - [clang-tidy] Fix check_clang_tidy.py trivially passing default CHECK

2018-10-12 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Fri Oct 12 06:35:47 2018
New Revision: 344343

URL: http://llvm.org/viewvc/llvm-project?rev=344343&view=rev
Log:
[clang-tidy] Fix check_clang_tidy.py trivially passing default CHECK

Differential Revision: https://reviews.llvm.org/D53194

Modified:
clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py

Modified: clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py?rev=344343&r1=344342&r2=344343&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py (original)
+++ clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py Fri Oct 12 
06:35:47 2018
@@ -51,7 +51,7 @@ def main():
   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 @@ def main():
   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


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r351867 - [doc] Replace 'class' with 'struct' for 'public' by default

2019-01-22 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Tue Jan 22 12:27:02 2019
New Revision: 351867

URL: http://llvm.org/viewvc/llvm-project?rev=351867&view=rev
Log:
[doc] Replace 'class' with 'struct' for 'public' by default

Make sample syntax correct.


Modified:

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-parent-virtual-call.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-parent-virtual-call.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-parent-virtual-call.rst?rev=351867&r1=351866&r2=351867&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-parent-virtual-call.rst 
(original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-parent-virtual-call.rst 
Tue Jan 22 12:27:02 2019
@@ -8,15 +8,15 @@ to overridden parent's virtual methods.
 
 .. code-block:: c++
 
-  class A {
+  struct A {
 int virtual foo() {...}
   };
 
-  class B: public A {
+  struct B: public A {
 int foo() override {...}
   };
 
-  class C: public B {
+  struct C: public B {
 int foo() override { A::foo(); }
   // 
   // warning: qualified name A::foo refers to a member overridden in subclass; 
did you mean 'B'?  [bugprone-parent-virtual-call]


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r351925 - [doc] Fix svn property for bugprone-parent-virtual-call.rst

2019-01-22 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Tue Jan 22 22:46:27 2019
New Revision: 351925

URL: http://llvm.org/viewvc/llvm-project?rev=351925&view=rev
Log:
[doc] Fix svn property for bugprone-parent-virtual-call.rst

Modified:

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-parent-virtual-call.rst 
  (props changed)

Propchange: 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-parent-virtual-call.rst
--
--- svn:executable (original)
+++ svn:executable (removed)
@@ -1 +0,0 @@
-*


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r356547 - [clang-tidy] Parallelize clang-tidy-diff.py

2019-03-20 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Wed Mar 20 04:30:05 2019
New Revision: 356547

URL: http://llvm.org/viewvc/llvm-project?rev=356547&view=rev
Log:
[clang-tidy] Parallelize clang-tidy-diff.py

This patch has 2 rationales:

- large patches lead to long command lines and often cause max command line 
length restrictions imposed by OS;
- clang-tidy runs on modified files are independent and can be done in 
parallel, the same as done for run-clang-tidy.

Differential Revision: https://reviews.llvm.org/D57662


Modified:
clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py

Modified: clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py?rev=356547&r1=356546&r2=356547&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py Wed Mar 20 
04:30:05 2019
@@ -24,10 +24,88 @@ Example usage for git/svn users:
 """
 
 import argparse
+import glob
 import json
+import multiprocessing
+import os
 import re
+import shutil
 import subprocess
 import sys
+import tempfile
+import threading
+import traceback
+import yaml
+
+is_py2 = sys.version[0] == '2'
+
+if is_py2:
+import Queue as queue
+else:
+import queue as queue
+
+
+def run_tidy(task_queue, lock, timeout):
+  watchdog = None
+  while True:
+command = task_queue.get()
+try:
+  proc = subprocess.Popen(command,
+  stdout=subprocess.PIPE,
+  stderr=subprocess.PIPE)
+
+  if timeout is not None:
+watchdog = threading.Timer(timeout, proc.kill)
+watchdog.start()
+
+  stdout, stderr = proc.communicate()
+
+  with lock:
+sys.stdout.write(stdout.decode('utf-8') + '\n')
+if stderr:
+  sys.stderr.write(stderr.decode('utf-8') + '\n')
+except Exception as e:
+  with lock:
+sys.stderr.write('Failed: ' + str(e) + ': '.join(command) + '\n')
+finally:
+  with lock:
+if (not timeout is None) and (not watchdog is None):
+  if not watchdog.is_alive():
+  sys.stderr.write('Terminated by timeout: ' +
+   ' '.join(command) + '\n')
+  watchdog.cancel()
+  task_queue.task_done()
+
+
+def start_workers(max_tasks, tidy_caller, task_queue, lock, timeout):
+  for _ in range(max_tasks):
+t = threading.Thread(target=tidy_caller, args=(task_queue, lock, timeout))
+t.daemon = True
+t.start()
+
+def merge_replacement_files(tmpdir, mergefile):
+  """Merge all replacement files in a directory into a single file"""
+  # The fixes suggested by clang-tidy >= 4.0.0 are given under
+  # the top level key 'Diagnostics' in the output yaml files
+  mergekey="Diagnostics"
+  merged=[]
+  for replacefile in glob.iglob(os.path.join(tmpdir, '*.yaml')):
+content = yaml.safe_load(open(replacefile, 'r'))
+if not content:
+  continue # Skip empty files.
+merged.extend(content.get(mergekey, []))
+
+  if merged:
+# MainSourceFile: The key is required by the definition inside
+# include/clang/Tooling/ReplacementsYaml.h, but the value
+# is actually never used inside clang-apply-replacements,
+# so we set it to '' here.
+output = { 'MainSourceFile': '', mergekey: merged }
+with open(mergefile, 'w') as out:
+  yaml.safe_dump(output, out)
+  else:
+# Empty the file:
+open(mergefile, 'w').close()
 
 
 def main():
@@ -48,6 +126,10 @@ def main():
   help='custom pattern selecting file paths to check '
   '(case insensitive, overridden by -regex)')
 
+  parser.add_argument('-j', type=int, default=1,
+  help='number of tidy instances to be run in parallel.')
+  parser.add_argument('-timeout', type=int, default=None,
+  help='timeout per each file in seconds.')
   parser.add_argument('-fix', action='store_true', default=False,
   help='apply suggested fixes')
   parser.add_argument('-checks',
@@ -84,7 +166,7 @@ def main():
 match = re.search('^\+\+\+\ \"?(.*?/){%s}([^ \t\n\"]*)' % args.p, line)
 if match:
   filename = match.group(2)
-if filename == None:
+if filename is None:
   continue
 
 if args.regex is not None:
@@ -102,44 +184,83 @@ def main():
 line_count = int(match.group(3))
   if line_count == 0:
 continue
-  end_line = start_line + line_count - 1;
+  end_line = start_line + line_count - 1
   lines_by_file.setdefault(filename, []).append([start_line, end_line])
 
-  if len(lines_by_file) == 0:
+  if not any(lines_by_file):
 print("No relevant changes found.")
 sys.exit(0)
 
-  line_filter_json = json.dumps(
-[{"name" : name, "lines" : lines_by_file[name]} for name in lines_by_file],
-separators = (',',

[clang-tools-extra] r356548 - [clang-tidy] Cosmetic fix

2019-03-20 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Wed Mar 20 04:34:29 2019
New Revision: 356548

URL: http://llvm.org/viewvc/llvm-project?rev=356548&view=rev
Log:
[clang-tidy] Cosmetic fix

Differential Revision: https://reviews.llvm.org/D57662


Modified:
clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py

Modified: clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py?rev=356548&r1=356547&r2=356548&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py Wed Mar 20 
04:34:29 2019
@@ -87,8 +87,8 @@ def merge_replacement_files(tmpdir, merg
   """Merge all replacement files in a directory into a single file"""
   # The fixes suggested by clang-tidy >= 4.0.0 are given under
   # the top level key 'Diagnostics' in the output yaml files
-  mergekey="Diagnostics"
-  merged=[]
+  mergekey = "Diagnostics"
+  merged = []
   for replacefile in glob.iglob(os.path.join(tmpdir, '*.yaml')):
 content = yaml.safe_load(open(replacefile, 'r'))
 if not content:


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r356565 - Reland r356547 after fixing the tests for Linux.

2019-03-20 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Wed Mar 20 08:50:26 2019
New Revision: 356565

URL: http://llvm.org/viewvc/llvm-project?rev=356565&view=rev
Log:
Reland r356547 after fixing the tests for Linux.

[clang-tidy] Parallelize clang-tidy-diff.py

This patch has 2 rationales:

- large patches lead to long command lines and often cause max command line 
length restrictions imposed by OS;
- clang-tidy runs on modified files are independent and can be done in 
parallel, the same as done for run-clang-tidy.

Differential Revision: https://reviews.llvm.org/D57662


Modified:
clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py

Modified: clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py?rev=356565&r1=356564&r2=356565&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py Wed Mar 20 
08:50:26 2019
@@ -24,10 +24,90 @@ Example usage for git/svn users:
 """
 
 import argparse
+import glob
 import json
+import multiprocessing
+import os
 import re
+import shutil
 import subprocess
 import sys
+import tempfile
+import threading
+import traceback
+import yaml
+
+is_py2 = sys.version[0] == '2'
+
+if is_py2:
+import Queue as queue
+else:
+import queue as queue
+
+
+def run_tidy(task_queue, lock, timeout):
+  watchdog = None
+  while True:
+command = task_queue.get()
+try:
+  proc = subprocess.Popen(command,
+  stdout=subprocess.PIPE,
+  stderr=subprocess.PIPE)
+
+  if timeout is not None:
+watchdog = threading.Timer(timeout, proc.kill)
+watchdog.start()
+
+  stdout, stderr = proc.communicate()
+
+  with lock:
+sys.stdout.write(stdout.decode('utf-8') + '\n')
+sys.stdout.flush()
+if stderr:
+  sys.stderr.write(stderr.decode('utf-8') + '\n')
+  sys.stderr.flush()
+except Exception as e:
+  with lock:
+sys.stderr.write('Failed: ' + str(e) + ': '.join(command) + '\n')
+finally:
+  with lock:
+if (not timeout is None) and (not watchdog is None):
+  if not watchdog.is_alive():
+  sys.stderr.write('Terminated by timeout: ' +
+   ' '.join(command) + '\n')
+  watchdog.cancel()
+  task_queue.task_done()
+
+
+def start_workers(max_tasks, tidy_caller, task_queue, lock, timeout):
+  for _ in range(max_tasks):
+t = threading.Thread(target=tidy_caller, args=(task_queue, lock, timeout))
+t.daemon = True
+t.start()
+
+def merge_replacement_files(tmpdir, mergefile):
+  """Merge all replacement files in a directory into a single file"""
+  # The fixes suggested by clang-tidy >= 4.0.0 are given under
+  # the top level key 'Diagnostics' in the output yaml files
+  mergekey = "Diagnostics"
+  merged = []
+  for replacefile in glob.iglob(os.path.join(tmpdir, '*.yaml')):
+content = yaml.safe_load(open(replacefile, 'r'))
+if not content:
+  continue # Skip empty files.
+merged.extend(content.get(mergekey, []))
+
+  if merged:
+# MainSourceFile: The key is required by the definition inside
+# include/clang/Tooling/ReplacementsYaml.h, but the value
+# is actually never used inside clang-apply-replacements,
+# so we set it to '' here.
+output = { 'MainSourceFile': '', mergekey: merged }
+with open(mergefile, 'w') as out:
+  yaml.safe_dump(output, out)
+  else:
+# Empty the file:
+open(mergefile, 'w').close()
 
 
 def main():
@@ -47,7 +127,10 @@ def main():
   r'.*\.(cpp|cc|c\+\+|cxx|c|cl|h|hpp|m|mm|inc)',
   help='custom pattern selecting file paths to check '
   '(case insensitive, overridden by -regex)')
-
+  parser.add_argument('-j', type=int, default=1,
+  help='number of tidy instances to be run in parallel.')
+  parser.add_argument('-timeout', type=int, default=None,
+  help='timeout per each file in seconds.')
   parser.add_argument('-fix', action='store_true', default=False,
   help='apply suggested fixes')
   parser.add_argument('-checks',
@@ -84,7 +167,7 @@ def main():
 match = re.search('^\+\+\+\ \"?(.*?/){%s}([^ \t\n\"]*)' % args.p, line)
 if match:
   filename = match.group(2)
-if filename == None:
+if filename is None:
   continue
 
 if args.regex is not None:
@@ -102,44 +185,79 @@ def main():
 line_count = int(match.group(3))
   if line_count == 0:
 continue
-  end_line = start_line + line_count - 1;
+  end_line = start_line + line_count - 1
   lines_by_file.setdefault(filename, []).append([start_line, end_line])
 
-  if len(lines_by_file) == 0:
+  if not any(lines_by_file):
 print("No r

[clang-tools-extra] r356589 - [clang-tidy] Fix redundant check breaking the test on many platforms.

2019-03-20 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Wed Mar 20 11:37:04 2019
New Revision: 356589

URL: http://llvm.org/viewvc/llvm-project?rev=356589&view=rev
Log:
[clang-tidy] Fix redundant check breaking the test on many platforms.

Differential Revision: https://reviews.llvm.org/D57662


Modified:
clang-tools-extra/trunk/test/clang-tidy/clang-tidy-diff.cpp

Modified: clang-tools-extra/trunk/test/clang-tidy/clang-tidy-diff.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/clang-tidy-diff.cpp?rev=356589&r1=356588&r2=356589&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/clang-tidy-diff.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/clang-tidy-diff.cpp Wed Mar 20 
11:37:04 2019
@@ -23,5 +23,4 @@ struct B : public A {
 // CHECK-QUIET-NOT: warning:
 };
 // CHECK-SANITY-NOT: Suppressed
-// CHECK: Suppressed 1 warnings (1 due to line filter).
 // CHECK-QUIET-NOT: Suppressed


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r356649 - Reland r356547 after fixing the YAML module missing issue.

2019-03-21 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Thu Mar 21 01:32:07 2019
New Revision: 356649

URL: http://llvm.org/viewvc/llvm-project?rev=356649&view=rev
Log:
Reland r356547 after fixing the YAML module missing issue.

[clang-tidy] Parallelize clang-tidy-diff.py

This patch has 2 rationales:

- large patches lead to long command lines and often cause max command line 
length restrictions imposed by OS;
- clang-tidy runs on modified files are independent and can be done in 
parallel, the same as done for run-clang-tidy.

Differential Revision: https://reviews.llvm.org/D5766

Modified:
clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py

Modified: clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py?rev=356649&r1=356648&r2=356649&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py Thu Mar 21 
01:32:07 2019
@@ -24,10 +24,95 @@ Example usage for git/svn users:
 """
 
 import argparse
+import glob
 import json
+import multiprocessing
+import os
 import re
+import shutil
 import subprocess
 import sys
+import tempfile
+import threading
+import traceback
+
+yaml_imported = True
+try:
+  import yaml
+except ImportError:
+  yaml_imported = False
+
+is_py2 = sys.version[0] == '2'
+
+if is_py2:
+import Queue as queue
+else:
+import queue as queue
+
+
+def run_tidy(task_queue, lock, timeout):
+  watchdog = None
+  while True:
+command = task_queue.get()
+try:
+  proc = subprocess.Popen(command,
+  stdout=subprocess.PIPE,
+  stderr=subprocess.PIPE)
+
+  if timeout is not None:
+watchdog = threading.Timer(timeout, proc.kill)
+watchdog.start()
+
+  stdout, stderr = proc.communicate()
+
+  with lock:
+sys.stdout.write(stdout.decode('utf-8') + '\n')
+sys.stdout.flush()
+if stderr:
+  sys.stderr.write(stderr.decode('utf-8') + '\n')
+  sys.stderr.flush()
+except Exception as e:
+  with lock:
+sys.stderr.write('Failed: ' + str(e) + ': '.join(command) + '\n')
+finally:
+  with lock:
+if (not timeout is None) and (not watchdog is None):
+  if not watchdog.is_alive():
+  sys.stderr.write('Terminated by timeout: ' +
+   ' '.join(command) + '\n')
+  watchdog.cancel()
+  task_queue.task_done()
+
+
+def start_workers(max_tasks, tidy_caller, task_queue, lock, timeout):
+  for _ in range(max_tasks):
+t = threading.Thread(target=tidy_caller, args=(task_queue, lock, timeout))
+t.daemon = True
+t.start()
+
+def merge_replacement_files(tmpdir, mergefile):
+  """Merge all replacement files in a directory into a single file"""
+  # The fixes suggested by clang-tidy >= 4.0.0 are given under
+  # the top level key 'Diagnostics' in the output yaml files
+  mergekey = "Diagnostics"
+  merged = []
+  for replacefile in glob.iglob(os.path.join(tmpdir, '*.yaml')):
+content = yaml.safe_load(open(replacefile, 'r'))
+if not content:
+  continue # Skip empty files.
+merged.extend(content.get(mergekey, []))
+
+  if merged:
+# MainSourceFile: The key is required by the definition inside
+# include/clang/Tooling/ReplacementsYaml.h, but the value
+# is actually never used inside clang-apply-replacements,
+# so we set it to '' here.
+output = { 'MainSourceFile': '', mergekey: merged }
+with open(mergefile, 'w') as out:
+  yaml.safe_dump(output, out)
+  else:
+# Empty the file:
+open(mergefile, 'w').close()
 
 
 def main():
@@ -47,7 +132,10 @@ def main():
   r'.*\.(cpp|cc|c\+\+|cxx|c|cl|h|hpp|m|mm|inc)',
   help='custom pattern selecting file paths to check '
   '(case insensitive, overridden by -regex)')
-
+  parser.add_argument('-j', type=int, default=1,
+  help='number of tidy instances to be run in parallel.')
+  parser.add_argument('-timeout', type=int, default=None,
+  help='timeout per each file in seconds.')
   parser.add_argument('-fix', action='store_true', default=False,
   help='apply suggested fixes')
   parser.add_argument('-checks',
@@ -56,9 +144,10 @@ def main():
   default='')
   parser.add_argument('-path', dest='build_path',
   help='Path used to read a compile command database.')
-  parser.add_argument('-export-fixes', metavar='FILE', dest='export_fixes',
-  help='Create a yaml file to store suggested fixes in, '
-  'which can be applied with clang-apply-replacements.')
+  if yaml_imported:
+parser.add_argument('-export-fixes', metavar='FILE', dest='export_fixes',
+

[clang-tools-extra] r357114 - [clang-tidy] Handle missing yaml module in run-clang-tidy.py

2019-03-27 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Wed Mar 27 12:21:32 2019
New Revision: 357114

URL: http://llvm.org/viewvc/llvm-project?rev=357114&view=rev
Log:
[clang-tidy] Handle missing yaml module in run-clang-tidy.py

The Yaml module is missing on some systems and on many of clang buildbots. 
But the test for run-clang-tidy.py doesn't fail due to 'NOT' statement masking 
a python runtime error.

This patch conditionally imports and enables the yaml module only if it's 
present in the system. 
If not, then '-export-fixes' is disabled.

Differential Revision: https://reviews.llvm.org/D59734

Modified:
clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py
clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py
clang-tools-extra/trunk/test/clang-tidy/bugprone-parent-virtual-call.cpp   
(props changed)
clang-tools-extra/trunk/test/clang-tidy/run-clang-tidy.cpp

Modified: clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py?rev=357114&r1=357113&r2=357114&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py Wed Mar 27 
12:21:32 2019
@@ -36,11 +36,10 @@ import tempfile
 import threading
 import traceback
 
-yaml_imported = True
 try:
   import yaml
 except ImportError:
-  yaml_imported = False
+  yaml = None
 
 is_py2 = sys.version[0] == '2'
 
@@ -144,7 +143,7 @@ def main():
   default='')
   parser.add_argument('-path', dest='build_path',
   help='Path used to read a compile command database.')
-  if yaml_imported:
+  if yaml:
 parser.add_argument('-export-fixes', metavar='FILE', dest='export_fixes',
 help='Create a yaml file to store suggested fixes in, '
 'which can be applied with clang-apply-replacements.')
@@ -204,7 +203,7 @@ def main():
   max_task_count = min(len(lines_by_file), max_task_count)
 
   tmpdir = None
-  if yaml_imported and args.export_fixes:
+  if yaml and args.export_fixes:
 tmpdir = tempfile.mkdtemp()
 
   # Tasks for clang-tidy.
@@ -238,7 +237,7 @@ def main():
 # Run clang-tidy on files containing changes.
 command = [args.clang_tidy_binary]
 command.append('-line-filter=' + line_filter_json)
-if yaml_imported and args.export_fixes:
+if yaml and args.export_fixes:
   # Get a temporary file. We immediately close the handle so clang-tidy can
   # overwrite it.
   (handle, tmp_name) = tempfile.mkstemp(suffix='.yaml', dir=tmpdir)
@@ -253,7 +252,7 @@ def main():
   # Wait for all threads to be done.
   task_queue.join()
 
-  if yaml_imported and args.export_fixes:
+  if yaml and args.export_fixes:
 print('Writing fixes to ' + args.export_fixes + ' ...')
 try:
   merge_replacement_files(tmpdir, args.export_fixes)

Modified: clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py?rev=357114&r1=357113&r2=357114&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py Wed Mar 27 
12:21:32 2019
@@ -47,7 +47,11 @@ import sys
 import tempfile
 import threading
 import traceback
-import yaml
+
+try:
+  import yaml
+except ImportError:
+  yaml = None
 
 is_py2 = sys.version[0] == '2'
 
@@ -199,9 +203,10 @@ def main():
   'headers to output diagnostics from. Diagnostics from '
   'the main file of each translation unit are always '
   'displayed.')
-  parser.add_argument('-export-fixes', metavar='filename', dest='export_fixes',
-  help='Create a yaml file to store suggested fixes in, '
-  'which can be applied with clang-apply-replacements.')
+  if yaml:
+parser.add_argument('-export-fixes', metavar='filename', 
dest='export_fixes',
+help='Create a yaml file to store suggested fixes in, '
+'which can be applied with clang-apply-replacements.')
   parser.add_argument('-j', type=int, default=0,
   help='number of tidy instances to be run in parallel.')
   parser.add_argument('files', nargs='*', default=['.*'],
@@ -254,7 +259,7 @@ def main():
 max_task = multiprocessing.cpu_count()
 
   tmpdir = None
-  if args.fix or args.export_fixes:
+  if args.fix or (yaml and args.export_fixes):
 check_clang_apply_replacements_binary(args)
 tmpdir = tempfile.mkdtemp()
 
@@ -292,7 +297,7 @@ def main():
   shutil.rmtree(tmpdir)
 os.kill(0, 9)
 
-  if args.export_fixes:
+  if yaml and args.export_fixes:
 print('Writing fixes to ' + args.export_fixes

[clang-tools-extra] r344015 - [clang-tidy] The patch extends the existing command line option -check-suffix

2018-10-08 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Mon Oct  8 22:40:03 2018
New Revision: 344015

URL: http://llvm.org/viewvc/llvm-project?rev=344015&view=rev
Log:
[clang-tidy] The patch extends the existing command line option -check-suffix 
(with alias -check-suffixes) to accept multiple comma-separated FileCheck 
prefixes.

Usage:

// RUN: %check_clang_tidy -check-suffix=USING-C,USING-D %s 
misc-unused-using-decls %t -- -- ...
or for the same:
// RUN: %check_clang_tidy -check-suffixes=USING-C,USING-D %s 
misc-unused-using-decls %t -- -- ...

Differential Revision: https://reviews.llvm.org/D52971

Modified:
clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.cpp
clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py

Modified: clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.cpp?rev=344015&r1=344014&r2=344015&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.cpp Mon Oct  8 
22:40:03 2018
@@ -1,21 +1,32 @@
 // RUN: %check_clang_tidy -check-suffix=USING-A %s misc-unused-using-decls %t 
-- -- -DUSING_A
 // RUN: %check_clang_tidy -check-suffix=USING-B %s misc-unused-using-decls %t 
-- -- -DUSING_B
+// RUN: %check_clang_tidy -check-suffix=USING-C,USING-D %s 
misc-unused-using-decls %t -- -- -DUSING_C_D
+// RUN: %check_clang_tidy -check-suffixes=USING-C,USING-D %s 
misc-unused-using-decls %t -- -- -DUSING_C_D
 // RUN: %check_clang_tidy %s misc-unused-using-decls %t
 
-namespace a {class A {}; class B {}; class C {}; }
+namespace a {class A {}; class B {}; class C {}; class D {}; class E {};}
 namespace b {
 #if defined(USING_A)
 using a::A;
 #elif  defined(USING_B)
 using a::B;
-#else
+#elif  defined(USING_C_D)
 using a::C;
+using a::D;
+#else
+using a::E;
 #endif
 }
 namespace c {}
-// CHECK-MESSAGES-USING-A: :[[@LINE-8]]:10: warning: using decl 'A' {{.*}}
-// CHECK-MESSAGES-USING-B: :[[@LINE-7]]:10: warning: using decl 'B' {{.*}}
-// CHECK-MESSAGES: :[[@LINE-6]]:10: warning: using decl 'C' {{.*}}
+// CHECK-MESSAGES-USING-A: warning: using decl 'A' {{.*}}
+// CHECK-MESSAGES-USING-B: warning: using decl 'B' {{.*}}
+// CHECK-MESSAGES-USING-C: warning: using decl 'C' {{.*}}
+// CHECK-MESSAGES-USING-D: warning: using decl 'D' {{.*}}
+// CHECK-MESSAGES: warning: using decl 'E' {{.*}}
 // CHECK-FIXES-USING-A-NOT: using a::A;$
 // CHECK-FIXES-USING-B-NOT: using a::B;$
-// CHECK-FIXES-NOT: using a::C;$
+// CHECK-FIXES-USING-C-NOT: using a::C;$
+// CHECK-FIXES-USING-C-NOT: using a::D;$
+// CHECK-FIXES-USING-D-NOT: using a::C;$
+// CHECK-FIXES-USING-D-NOT: using a::D;$
+// CHECK-FIXES-NOT: using a::E;$

Modified: clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py?rev=344015&r1=344014&r2=344015&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py (original)
+++ clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py Mon Oct  8 
22:40:03 2018
@@ -18,7 +18,8 @@ This script runs clang-tidy in fix mode
 Usage:
   check_clang_tidy.py [-resource-dir=] \
 [-assume-filename=] \
-[-check-suffix=] \
+[-check-suffix=] \
+[-check-suffixes=] \
\
 -- [optional clang-tidy arguments]
 
@@ -38,15 +39,20 @@ def write_file(file_name, text):
 f.write(text)
 f.truncate()
 
+def csv(string):
+  return string.split(',')
+
 def main():
   parser = argparse.ArgumentParser()
   parser.add_argument('-expect-clang-tidy-error', action='store_true')
   parser.add_argument('-resource-dir')
   parser.add_argument('-assume-filename')
-  parser.add_argument('-check-suffix', default='')
   parser.add_argument('input_file_name')
   parser.add_argument('check_name')
   parser.add_argument('temp_file_name')
+  parser.add_argument('-check-suffix', '-check-suffixes',
+  default=[], type=csv,
+  help="comma-separated list of FileCheck suffixes")
 
   args, extra_args = parser.parse_known_args()
 
@@ -72,14 +78,6 @@ def main():
   clang_tidy_extra_args.extend(
   ['-fobjc-abi-version=2', '-fobjc-arc'])
 
-  if args.check_suffix and not re.match('^[A-Z0-9\-]+$', args.check_suffix):
-sys.exit('Only A..Z, 0..9 and "-" are allowed in check suffix, but "%s" 
was given' % (args.check_suffix))
-
-  file_check_suffix = ('-' + args.check_suffix) if args.check_suffix 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
-
   # Tests should not rely on STL being available, and instead provide mock
   # implementations of relevant APIs.
   clang_tidy_extra_args.appen

[clang-tools-extra] r344016 - [clang-tidy][docs] Update docs for `--check-suffixes`

2018-10-08 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Mon Oct  8 22:48:57 2018
New Revision: 344016

URL: http://llvm.org/viewvc/llvm-project?rev=344016&view=rev
Log:
[clang-tidy][docs] Update docs for `--check-suffixes`

Differential Revision: https://reviews.llvm.org/D52971

Modified:
clang-tools-extra/trunk/docs/clang-tidy/index.rst

Modified: clang-tools-extra/trunk/docs/clang-tidy/index.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/index.rst?rev=344016&r1=344015&r2=344016&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/index.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/index.rst Mon Oct  8 22:48:57 2018
@@ -680,9 +680,10 @@ source code is at `test/clang-tidy/googl
 // CHECK-FIXES: int b = a;
   }
 
-To check more than one scenario in the same test file use 
-``-check-suffix=SUFFIX-NAME`` on ``check_clang_tidy.py`` command line.
-With ``-check-suffix=SUFFIX-NAME`` you need to replace your ``CHECK-*`` 
+To check more than one scenario in the same test file use
+``-check-suffix=SUFFIX-NAME`` on ``check_clang_tidy.py`` command line or
+``-check-suffixes=SUFFIX-NAME-1,SUFFIX-NAME-2,...``.
+With ``-check-suffix[es]=SUFFIX-NAME`` you need to replace your ``CHECK-*``
 directives with ``CHECK-MESSAGES-SUFFIX-NAME`` and ``CHECK-FIXES-SUFFIX-NAME``.
 
 Here's an example:


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r367785 - [clang-tidy] Add FixItHint for performance-noexcept-move-constructor

2019-08-04 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Sun Aug  4 06:32:39 2019
New Revision: 367785

URL: http://llvm.org/viewvc/llvm-project?rev=367785&view=rev
Log:
[clang-tidy] Add FixItHint for performance-noexcept-move-constructor

Differential Revision: https://reviews.llvm.org/D65104


Added:

clang-tools-extra/trunk/test/clang-tidy/performance-noexcept-move-constructor-fix.cpp
Modified:

clang-tools-extra/trunk/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp?rev=367785&r1=367784&r2=367785&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp 
Sun Aug  4 06:32:39 2019
@@ -9,6 +9,7 @@
 #include "NoexceptMoveConstructorCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Tooling/FixIt.h"
 
 using namespace clang::ast_matchers;
 
@@ -47,9 +48,20 @@ void NoexceptMoveConstructorCheck::check
   return;
 
 if (!isNoexceptExceptionSpec(ProtoType->getExceptionSpecType())) {
-  diag(Decl->getLocation(), "move %0s should be marked noexcept")
+  auto Diag =
+  diag(Decl->getLocation(), "move %0s should be marked noexcept")
   << MethodType;
-  // FIXME: Add a fixit.
+  // Add FixIt hints.
+  SourceManager &SM = *Result.SourceManager;
+  assert(Decl->getNumParams() > 0);
+  SourceLocation NoexceptLoc = Decl->getParamDecl(Decl->getNumParams() - 1)
+   ->getSourceRange()
+   .getEnd();
+  if (NoexceptLoc.isValid())
+NoexceptLoc = Lexer::findLocationAfterToken(
+NoexceptLoc, tok::r_paren, SM, Result.Context->getLangOpts(), 
true);
+  if (NoexceptLoc.isValid())
+Diag << FixItHint::CreateInsertion(NoexceptLoc, " noexcept ");
   return;
 }
 

Added: 
clang-tools-extra/trunk/test/clang-tidy/performance-noexcept-move-constructor-fix.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/performance-noexcept-move-constructor-fix.cpp?rev=367785&view=auto
==
--- 
clang-tools-extra/trunk/test/clang-tidy/performance-noexcept-move-constructor-fix.cpp
 (added)
+++ 
clang-tools-extra/trunk/test/clang-tidy/performance-noexcept-move-constructor-fix.cpp
 Sun Aug  4 06:32:39 2019
@@ -0,0 +1,67 @@
+// RUN: %check_clang_tidy %s performance-noexcept-move-constructor %t
+
+struct C_1 {
+ ~C_1() {}
+ C_1(int a) {}
+ C_1(C_1&& a) :C_1(5) {}
+ // CHECK-FIXES: ){{.*}}noexcept{{.*}}:
+ C_1& operator=(C_1&&) { return *this; }
+ // CHECK-FIXES: ){{.*}}noexcept{{.*}} {
+};
+
+struct C_2 {
+ ~C_2() {}
+ C_2(C_2&& a);
+// CHECK-FIXES: ){{.*}}noexcept{{.*}};
+ C_2& operator=(C_2&&);
+// CHECK-FIXES: ){{.*}}noexcept{{.*}};
+};
+
+C_2::C_2(C_2&& a) {}
+// CHECK-FIXES: ){{.*}}noexcept{{.*}} {}
+C_2& C_2::operator=(C_2&&) { return *this; }
+// CHECK-FIXES: ){{.*}}noexcept{{.*}} {
+
+struct C_3 {
+ ~C_3() {}
+ C_3(C_3&& a);
+// CHECK-FIXES: ){{.*}}noexcept{{.*}};
+ C_3& operator=(C_3&& a);
+// CHECK-FIXES: ){{.*}}noexcept{{.*}};
+};
+
+C_3::C_3(C_3&& a) = default;
+// CHECK-FIXES: ){{.*}}noexcept{{.*}} = default;
+C_3& C_3::operator=(C_3&& a) = default;
+// CHECK-FIXES: ){{.*}}noexcept{{.*}} = default;
+
+template 
+struct C_4 {
+ C_4(C_4&&) {}
+// CHECK-FIXES: ){{.*}}noexcept{{.*}} {}
+ ~C_4() {}
+ C_4& operator=(C_4&& a) = default;
+// CHECK-FIXES: ){{.*}}noexcept{{.*}} = default;
+};
+
+template 
+struct C_5 {
+ C_5(C_5&&) {}
+// CHECK-FIXES:){{.*}}noexcept{{.*}} {}
+ ~C_5() {}
+ auto operator=(C_5&& a)->C_5 = default;
+// CHECK-FIXES:){{.*}}noexcept{{.*}} = default;
+};
+
+template 
+struct C_6 {
+ C_6(C_6&&) {}
+// CHECK-FIXES:){{.*}}noexcept{{.*}} {}
+ ~C_6() {}
+ auto operator=(C_6&& a)->C_6;
+// CHECK-FIXES:){{.*}}noexcept{{.*}};
+};
+
+template 
+auto C_6::operator=(C_6&& a) -> C_6 {}
+// CHECK-FIXES: ){{.*}}noexcept{{.*}} {}
\ No newline at end of file


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r329873 - [clang-tidy] [modernize-use-auto] Get only a length of token, not the token itself

2018-04-11 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Wed Apr 11 22:41:24 2018
New Revision: 329873

URL: http://llvm.org/viewvc/llvm-project?rev=329873&view=rev
Log:
[clang-tidy] [modernize-use-auto] Get only a length of token, not the token 
itself


Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp?rev=329873&r1=329872&r2=329873&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp Wed Apr 11 
22:41:24 2018
@@ -11,6 +11,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Lex/Lexer.h"
 #include "clang/Tooling/FixIt.h"
 
 using namespace clang;
@@ -419,8 +420,8 @@ void UseAutoCheck::replaceExpr(
   SourceRange Range(Loc.getSourceRange());
 
   if (MinTypeNameLength != 0 &&
-  tooling::fixit::getText(Loc.getSourceRange(), FirstDecl->getASTContext())
-  .size() < MinTypeNameLength)
+  Lexer::MeasureTokenLength(Loc.getLocStart(), Context->getSourceManager(),
+getLangOpts()) < MinTypeNameLength)
 return;
 
   auto Diag = diag(Range.getBegin(), Message);


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r329875 - [Documentation] Fix options order for Release Notes in modernize-use-auto.

2018-04-11 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Wed Apr 11 22:45:16 2018
New Revision: 329875

URL: http://llvm.org/viewvc/llvm-project?rev=329875&view=rev
Log:
[Documentation] Fix options order for Release Notes in modernize-use-auto.


Modified:
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-auto.rst

Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-auto.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-auto.rst?rev=329875&r1=329874&r2=329875&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-auto.rst 
(original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-auto.rst Wed 
Apr 11 22:45:16 2018
@@ -177,24 +177,6 @@ Known Limitations
 Options
 ---
 
-.. option:: RemoveStars
-
-   If the option is set to non-zero (default is `0`), the check will remove
-   stars from the non-typedef pointer types when replacing type names with
-   ``auto``. Otherwise, the check will leave stars. For example:
-
-.. code-block:: c++
-
-  TypeName *my_first_pointer = new TypeName, *my_second_pointer = new TypeName;
-
-  // RemoveStars = 0
-
-  auto *my_first_pointer = new TypeName, *my_second_pointer = new TypeName;
-
-  // RemoveStars = 1
-
-  auto my_first_pointer = new TypeName, my_second_pointer = new TypeName;
-
 .. option:: MinTypeNameLength
 
If the option is set to non-zero (default `5`), the check will ignore type
@@ -214,3 +196,21 @@ Options
   int a = static_cast(foo());// ---> int  a = ...
   bool b = new bool;  // ---> bool b = ...
   unsigned c = static_cast(foo());  // ---> auto c = ...
+
+.. option:: RemoveStars
+
+   If the option is set to non-zero (default is `0`), the check will remove
+   stars from the non-typedef pointer types when replacing type names with
+   ``auto``. Otherwise, the check will leave stars. For example:
+
+.. code-block:: c++
+
+  TypeName *my_first_pointer = new TypeName, *my_second_pointer = new TypeName;
+
+  // RemoveStars = 0
+
+  auto *my_first_pointer = new TypeName, *my_second_pointer = new TypeName;
+
+  // RemoveStars = 1
+
+  auto my_first_pointer = new TypeName, my_second_pointer = new TypeName;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r329881 - [clang-tidy] [modernize-use-auto] Fix test modernize-use-auto-new-remove-stars.cpp after improvement

2018-04-11 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Wed Apr 11 23:45:47 2018
New Revision: 329881

URL: http://llvm.org/viewvc/llvm-project?rev=329881&view=rev
Log:
[clang-tidy] [modernize-use-auto] Fix test 
modernize-use-auto-new-remove-stars.cpp  after improvement

'tooling::fixit::getText' considers a length of "int *" to be 5 instead of 3 
in a new algorithm in https://reviews.llvm.org/rCTE329873. It was the root of 
the test failure.


Modified:

clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-new-remove-stars.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-new-remove-stars.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-new-remove-stars.cpp?rev=329881&r1=329880&r2=329881&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-new-remove-stars.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-new-remove-stars.cpp 
Wed Apr 11 23:45:47 2018
@@ -1,5 +1,5 @@
 // RUN: %check_clang_tidy %s modernize-use-auto %t -- \
-// RUN:   -config="{CheckOptions: [{key: modernize-use-auto.RemoveStars, 
value: '1'}]}" \
+// RUN:   -config="{CheckOptions: [{key: modernize-use-auto.RemoveStars, 
value: '1'}, {key: modernize-use-auto.MinTypeNameLength, value: '0'}]}" \
 // RUN:   -- -std=c++11
 
 class MyType {};


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang-tools-extra] r329873 - [clang-tidy] [modernize-use-auto] Get only a length of token, not the token itself

2018-04-12 Thread Zinovy Nis via cfe-commits
Yes, due to to incorrect token length returned by the old code, the test
was passing. I fixed it.

Hm, you are right, clangTooling is not requirted anymore.

чт, 12 апр. 2018 г. в 10:25, Roman Lebedev :

> Also, i guess you now can remove linking to clangTooling that was
> required to unbreak the build.
> I'm guessing clangLex contains Lexer::MeasureTokenLength() ?
>
> On Thu, Apr 12, 2018 at 10:22 AM, Roman Lebedev 
> wrote:
> > Test?
> >
> > On Thu, Apr 12, 2018 at 8:41 AM, Zinovy Nis via cfe-commits
> >  wrote:
> >> Author: zinovy.nis
> >> Date: Wed Apr 11 22:41:24 2018
> >> New Revision: 329873
> >>
> >> URL: http://llvm.org/viewvc/llvm-project?rev=329873&view=rev
> >> Log:
> >> [clang-tidy] [modernize-use-auto] Get only a length of token, not the
> token itself
> >>
> >>
> >> Modified:
> >> clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
> >>
> >> Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
> >> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp?rev=329873&r1=329872&r2=329873&view=diff
> >>
> ==
> >> --- clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
> (original)
> >> +++ clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp Wed
> Apr 11 22:41:24 2018
> >> @@ -11,6 +11,7 @@
> >>  #include "clang/AST/ASTContext.h"
> >>  #include "clang/ASTMatchers/ASTMatchFinder.h"
> >>  #include "clang/ASTMatchers/ASTMatchers.h"
> >> +#include "clang/Lex/Lexer.h"
> >>  #include "clang/Tooling/FixIt.h"
> >>
> >>  using namespace clang;
> >> @@ -419,8 +420,8 @@ void UseAutoCheck::replaceExpr(
> >>SourceRange Range(Loc.getSourceRange());
> >>
> >>if (MinTypeNameLength != 0 &&
> >> -  tooling::fixit::getText(Loc.getSourceRange(),
> FirstDecl->getASTContext())
> >> -  .size() < MinTypeNameLength)
> >> +  Lexer::MeasureTokenLength(Loc.getLocStart(),
> Context->getSourceManager(),
> >> +getLangOpts()) < MinTypeNameLength)
> >>  return;
> >>
> >>auto Diag = diag(Range.getBegin(), Message);
> >>
> >>
> >> ___
> >> cfe-commits mailing list
> >> cfe-commits@lists.llvm.org
> >> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang-tools-extra] r329873 - [clang-tidy] [modernize-use-auto] Get only a length of token, not the token itself

2018-04-12 Thread Zinovy Nis via cfe-commits
Yes, a test that should fail, did not fail with old code. And it's a
problem)


чт, 12 апр. 2018 г. в 10:35, Roman Lebedev :

> On Thu, Apr 12, 2018 at 10:30 AM, Zinovy Nis  wrote:
> > Yes, due to to incorrect token length returned by the old code, the test
> was
> > passing. I fixed it.
> Let me rephrase.
> If i revert just the
> clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp change,
> will the corresponding tests in
> clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-cast.cpp
> break?
> No, they won't. And that is a problem.
>
> > Hm, you are right, clangTooling is not requirted anymore.
> >
> > чт, 12 апр. 2018 г. в 10:25, Roman Lebedev :
> >>
> >> Also, i guess you now can remove linking to clangTooling that was
> >> required to unbreak the build.
> >> I'm guessing clangLex contains Lexer::MeasureTokenLength() ?
> >>
> >> On Thu, Apr 12, 2018 at 10:22 AM, Roman Lebedev 
> >> wrote:
> >> > Test?
> >> >
> >> > On Thu, Apr 12, 2018 at 8:41 AM, Zinovy Nis via cfe-commits
> >> >  wrote:
> >> >> Author: zinovy.nis
> >> >> Date: Wed Apr 11 22:41:24 2018
> >> >> New Revision: 329873
> >> >>
> >> >> URL: http://llvm.org/viewvc/llvm-project?rev=329873&view=rev
> >> >> Log:
> >> >> [clang-tidy] [modernize-use-auto] Get only a length of token, not the
> >> >> token itself
> >> >>
> >> >>
> >> >> Modified:
> >> >> clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
> >> >>
> >> >> Modified:
> clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
> >> >> URL:
> >> >>
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp?rev=329873&r1=329872&r2=329873&view=diff
> >> >>
> >> >>
> ==
> >> >> --- clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
> >> >> (original)
> >> >> +++ clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp Wed
> >> >> Apr 11 22:41:24 2018
> >> >> @@ -11,6 +11,7 @@
> >> >>  #include "clang/AST/ASTContext.h"
> >> >>  #include "clang/ASTMatchers/ASTMatchFinder.h"
> >> >>  #include "clang/ASTMatchers/ASTMatchers.h"
> >> >> +#include "clang/Lex/Lexer.h"
> >> >>  #include "clang/Tooling/FixIt.h"
> >> >>
> >> >>  using namespace clang;
> >> >> @@ -419,8 +420,8 @@ void UseAutoCheck::replaceExpr(
> >> >>SourceRange Range(Loc.getSourceRange());
> >> >>
> >> >>if (MinTypeNameLength != 0 &&
> >> >> -  tooling::fixit::getText(Loc.getSourceRange(),
> >> >> FirstDecl->getASTContext())
> >> >> -  .size() < MinTypeNameLength)
> >> >> +  Lexer::MeasureTokenLength(Loc.getLocStart(),
> >> >> Context->getSourceManager(),
> >> >> +getLangOpts()) < MinTypeNameLength)
> >> >>  return;
> >> >>
> >> >>auto Diag = diag(Range.getBegin(), Message);
> >> >>
> >> >>
> >> >> ___
> >> >> cfe-commits mailing list
> >> >> cfe-commits@lists.llvm.org
> >> >> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang-tools-extra] r329873 - [clang-tidy] [modernize-use-auto] Get only a length of token, not the token itself

2018-04-12 Thread Zinovy Nis via cfe-commits
I composed a test and you are right - for multi-token type names new code
returns wrong result. So this new code was a premature optimization. Sorry.
I'll see how to fix it in a better way and create a review on it. Thanks
for poiting.

чт, 12 апр. 2018 г. в 20:01, Alexander Kornienko :

> On Thu, Apr 12, 2018 at 7:44 AM Zinovy Nis via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: zinovy.nis
>> Date: Wed Apr 11 22:41:24 2018
>> New Revision: 329873
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=329873&view=rev
>> Log:
>> [clang-tidy] [modernize-use-auto] Get only a length of token, not the
>> token itself
>>
>>
>> Modified:
>> clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
>>
>> Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp?rev=329873&r1=329872&r2=329873&view=diff
>>
>> ==
>> --- clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
>> (original)
>> +++ clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp Wed Apr
>> 11 22:41:24 2018
>> @@ -11,6 +11,7 @@
>>  #include "clang/AST/ASTContext.h"
>>  #include "clang/ASTMatchers/ASTMatchFinder.h"
>>  #include "clang/ASTMatchers/ASTMatchers.h"
>> +#include "clang/Lex/Lexer.h"
>>  #include "clang/Tooling/FixIt.h"
>>
>>  using namespace clang;
>> @@ -419,8 +420,8 @@ void UseAutoCheck::replaceExpr(
>>SourceRange Range(Loc.getSourceRange());
>>
>>if (MinTypeNameLength != 0 &&
>> -  tooling::fixit::getText(Loc.getSourceRange(),
>> FirstDecl->getASTContext())
>> -  .size() < MinTypeNameLength)
>> +  Lexer::MeasureTokenLength(Loc.getLocStart(),
>> Context->getSourceManager(),
>> +getLangOpts()) < MinTypeNameLength)
>>
>
> What about type names consisting of multiple tokens (`unsigned long long`,
> `struct VeryLongStructName`, etc.)?
>
>
>>  return;
>>
>>auto Diag = diag(Range.getBegin(), Message);
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r329949 - Revert "[clang-tidy] [modernize-use-auto] Get only a length of token, not the token itself"

2018-04-12 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Thu Apr 12 13:33:24 2018
New Revision: 329949

URL: http://llvm.org/viewvc/llvm-project?rev=329949&view=rev
Log:
Revert "[clang-tidy] [modernize-use-auto] Get only a length of token, not the 
token itself"

This reverts r329873 as getting only a single token length is wrong for 
multi-token type names,
like 'unsigned long int'.


Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp?rev=329949&r1=329948&r2=329949&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp Thu Apr 12 
13:33:24 2018
@@ -11,7 +11,6 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
-#include "clang/Lex/Lexer.h"
 #include "clang/Tooling/FixIt.h"
 
 using namespace clang;
@@ -420,8 +419,8 @@ void UseAutoCheck::replaceExpr(
   SourceRange Range(Loc.getSourceRange());
 
   if (MinTypeNameLength != 0 &&
-  Lexer::MeasureTokenLength(Loc.getLocStart(), Context->getSourceManager(),
-getLangOpts()) < MinTypeNameLength)
+  tooling::fixit::getText(Loc.getSourceRange(), FirstDecl->getASTContext())
+  .size() < MinTypeNameLength)
 return;
 
   auto Diag = diag(Range.getBegin(), Message);


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r329994 - [clang-tidy] [bugprone-parent-virtual-call] Minor cosmetic changes. NFC

2018-04-13 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Fri Apr 13 00:46:27 2018
New Revision: 329994

URL: http://llvm.org/viewvc/llvm-project?rev=329994&view=rev
Log:
[clang-tidy] [bugprone-parent-virtual-call] Minor cosmetic changes. NFC


Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp?rev=329994&r1=329993&r2=329994&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp Fri 
Apr 13 00:46:27 2018
@@ -11,6 +11,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Tooling/FixIt.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include 
 #include 
@@ -27,13 +28,12 @@ static bool isParentOf(const CXXRecordDe
const CXXRecordDecl &ThisClass) {
   if (Parent.getCanonicalDecl() == ThisClass.getCanonicalDecl())
 return true;
-  for (const CXXBaseSpecifier &Base : ThisClass.bases()) {
-auto *BaseDecl = Base.getType()->getAsCXXRecordDecl();
-assert(BaseDecl);
-if (Parent.getCanonicalDecl() == BaseDecl->getCanonicalDecl())
-  return true;
-  }
-  return false;
+  return ThisClass.bases_end() !=
+ llvm::find_if(ThisClass.bases(), [=](const CXXBaseSpecifier &Base) {
+   auto *BaseDecl = Base.getType()->getAsCXXRecordDecl();
+   assert(BaseDecl);
+   return Parent.getCanonicalDecl() == BaseDecl->getCanonicalDecl();
+ });
 }
 
 static BasesVector getParentsByGrandParent(const CXXRecordDecl &GrandParent,
@@ -76,9 +76,9 @@ static std::string getExprAsString(const
clang::ASTContext &AC) {
   std::string Text = tooling::fixit::getText(E, AC).str();
   Text.erase(
-  std::remove_if(
-  Text.begin(), Text.end(),
-  [](char c) { return std::isspace(static_cast(c)); }),
+  llvm::remove_if(
+  Text,
+  [](char C) { return std::isspace(static_cast(C)); }),
   Text.end());
   return Text;
 }
@@ -92,16 +92,11 @@ void ParentVirtualCallCheck::registerMat
 hasSourceExpression(cxxThisExpr(hasType(
 type(anything()).bind("thisType")))
  .bind("member")),
-  callee(cxxMethodDecl(isVirtual(
-  .bind("call"),
+  callee(cxxMethodDecl(isVirtual(,
   this);
 }
 
 void ParentVirtualCallCheck::check(const MatchFinder::MatchResult &Result) {
-  const auto *MatchedDecl = Result.Nodes.getNodeAs("call");
-  (void)MatchedDecl;
-  assert(MatchedDecl);
-
   const auto *Member = Result.Nodes.getNodeAs("member");
   assert(Member);
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r329999 - [clang-tidy] Fix ParentVirtualCallCheck for old MSVS compilers

2018-04-13 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Fri Apr 13 01:43:47 2018
New Revision: 32

URL: http://llvm.org/viewvc/llvm-project?rev=32&view=rev
Log:
[clang-tidy] Fix ParentVirtualCallCheck for old MSVS compilers


Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp?rev=32&r1=329998&r2=32&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp Fri 
Apr 13 01:43:47 2018
@@ -28,11 +28,12 @@ static bool isParentOf(const CXXRecordDe
const CXXRecordDecl &ThisClass) {
   if (Parent.getCanonicalDecl() == ThisClass.getCanonicalDecl())
 return true;
+  const CXXRecordDecl *ParentCanonicalDecl = Parent.getCanonicalDecl();
   return ThisClass.bases_end() !=
  llvm::find_if(ThisClass.bases(), [=](const CXXBaseSpecifier &Base) {
auto *BaseDecl = Base.getType()->getAsCXXRecordDecl();
assert(BaseDecl);
-   return Parent.getCanonicalDecl() == BaseDecl->getCanonicalDecl();
+   return ParentCanonicalDecl == BaseDecl->getCanonicalDecl();
  });
 }
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r330509 - [clang-apply-replacements] Make clang-apply-replacements installable

2018-04-21 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Sat Apr 21 08:01:33 2018
New Revision: 330509

URL: http://llvm.org/viewvc/llvm-project?rev=330509&view=rev
Log:
[clang-apply-replacements] Make clang-apply-replacements installable

Add a new target for install: install-clang-apply-replacements.
So if you need clang-tidy and clang-apply-replacements tools only, 
you may build and install only these tools:

make install-clang-tidy install-clang-apply-replacements

Differential Revision: https://reviews.llvm.org/D45160


Modified:
clang-tools-extra/trunk/clang-apply-replacements/tool/CMakeLists.txt

Modified: clang-tools-extra/trunk/clang-apply-replacements/tool/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-apply-replacements/tool/CMakeLists.txt?rev=330509&r1=330508&r2=330509&view=diff
==
--- clang-tools-extra/trunk/clang-apply-replacements/tool/CMakeLists.txt 
(original)
+++ clang-tools-extra/trunk/clang-apply-replacements/tool/CMakeLists.txt Sat 
Apr 21 08:01:33 2018
@@ -2,7 +2,7 @@ set(LLVM_LINK_COMPONENTS
   Support
   )
 
-add_clang_executable(clang-apply-replacements
+add_clang_tool(clang-apply-replacements
   ClangApplyReplacementsMain.cpp
   )
 target_link_libraries(clang-apply-replacements


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r330511 - [clang-tidy] Customize FileCheck prefix in check_clang-tidy.py

2018-04-21 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Sat Apr 21 08:23:56 2018
New Revision: 330511

URL: http://llvm.org/viewvc/llvm-project?rev=330511&view=rev
Log:
[clang-tidy] Customize FileCheck prefix in check_clang-tidy.py

The patch introduces a new command line option '-check-suffix' for 
check_clang_tidy.py 
to allow multiple %check_clang_tidy% in a single test file.

Sample:

// RUN: %check_clang_tidy -check-suffix=FLAG-1 %s misc-unused-using-decls %t -- 
-- 
// RUN: %check_clang_tidy -check-suffix=FLAG-2 %s misc-unused-using-decls %t -- 
--  
...
+// CHECK-MESSAGES-FLAG-1: :[[@LINE-4]]:10: warning: using decl 'B' is unused 
[misc-unused-using-decls]
+// CHECK-MESSAGES-FLAG-2: :[[@LINE-7]]:10: warning: using decl 'A' is unused 
[misc-unused-using-decls]
+// CHECK-FIXES-FLAG-1-NOT: using a::A;$
+// CHECK-FIXES-FLAG-2-NOT: using a::B;$

Differential Revision: https://reviews.llvm.org/D45776

Added:
clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.cpp
Modified:
clang-tools-extra/trunk/docs/clang-tidy/index.rst
clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py

Modified: clang-tools-extra/trunk/docs/clang-tidy/index.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/index.rst?rev=330511&r1=330510&r2=330511&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/index.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/index.rst Sat Apr 21 08:23:56 2018
@@ -673,6 +673,27 @@ source code is at `test/clang-tidy/googl
 // CHECK-FIXES: int b = a;
   }
 
+To check more than one scenario in the same test file use 
+``-check-suffix=SUFFIX-NAME`` on ``check_clang_tidy.py`` command line.
+With ``-check-suffix=SUFFIX-NAME`` you need to replace your ``CHECK-*`` 
+directives with ``CHECK-MESSAGES-SUFFIX-NAME`` and ``CHECK-FIXES-SUFFIX-NAME``.
+
+Here's an example:
+
+.. code-block:: c++
+
+   // RUN: %check_clang_tidy -check-suffix=USING-A %s misc-unused-using-decls 
%t -- -- -DUSING_A
+   // RUN: %check_clang_tidy -check-suffix=USING-B %s misc-unused-using-decls 
%t -- -- -DUSING_B
+   // RUN: %check_clang_tidy %s misc-unused-using-decls %t
+   ...
+   // CHECK-MESSAGES-USING-A: :[[@LINE-8]]:10: warning: using decl 'A' {{.*}}
+   // CHECK-MESSAGES-USING-B: :[[@LINE-7]]:10: warning: using decl 'B' {{.*}}
+   // CHECK-MESSAGES: :[[@LINE-6]]:10: warning: using decl 'C' {{.*}}
+   // CHECK-FIXES-USING-A-NOT: using a::A;$
+   // CHECK-FIXES-USING-B-NOT: using a::B;$
+   // CHECK-FIXES-NOT: using a::C;$
+
+
 There are many dark corners in the C++ language, and it may be difficult to 
make
 your check work perfectly in all cases, especially if it issues fix-it hints. 
The
 most frequent pitfalls are macros and templates:

Added: clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.cpp?rev=330511&view=auto
==
--- clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.cpp Sat Apr 21 
08:23:56 2018
@@ -0,0 +1,21 @@
+// RUN: %check_clang_tidy -check-suffix=USING-A %s misc-unused-using-decls %t 
-- -- -DUSING_A
+// RUN: %check_clang_tidy -check-suffix=USING-B %s misc-unused-using-decls %t 
-- -- -DUSING_B
+// RUN: %check_clang_tidy %s misc-unused-using-decls %t
+
+namespace a {class A {}; class B {}; class C {}; }
+namespace b {
+#if defined(USING_A)
+using a::A;
+#elif  defined(USING_B)
+using a::B;
+#else
+using a::C;
+#endif
+}
+namespace c {}
+// CHECK-MESSAGES-USING-A: :[[@LINE-8]]:10: warning: using decl 'A' {{.*}}
+// CHECK-MESSAGES-USING-B: :[[@LINE-7]]:10: warning: using decl 'B' {{.*}}
+// CHECK-MESSAGES: :[[@LINE-6]]:10: warning: using decl 'C' {{.*}}
+// CHECK-FIXES-USING-A-NOT: using a::A;$
+// CHECK-FIXES-USING-B-NOT: using a::B;$
+// CHECK-FIXES-NOT: using a::C;$

Modified: clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py?rev=330511&r1=330510&r2=330511&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py (original)
+++ clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py Sat Apr 21 
08:23:56 2018
@@ -16,8 +16,9 @@ ClangTidy Test Helper
 This script runs clang-tidy in fix mode and verify fixes, messages or both.
 
 Usage:
-  check_clang_tidy.py [-resource-dir ] \
-[-assume-filename ] \
+  check_clang_tidy.py [-resource-dir=] \
+[-assume-filename=] \
+[-check-suffix=] \
\
 -- [optional clang-tidy arguments]
 
@@ -42,6 +43,7 @@ def main():
   parser.add_argument('-expect-clang-tidy-error', action='store_true')
   parser.add_argument('-resource-dir')
   parser.add_argument('-assume-filename')
+  par

Re: [PATCH] D45927: [clang-tidy] [modernize-use-auto] Correct way to calculate a type name length for multi-token types

2018-04-22 Thread Zinovy Nis via cfe-commits
> I think spaces that will be removed should be counted - long long is 9.

I thought about it, but what about "long   long  int
  ** * *"? Is it still 9?
I think it's a business of clang-format to remove excessive spaces, not of
clang-tidy.


вс, 22 апр. 2018 г. в 10:11, Malcolm Parsons via Phabricator <
revi...@reviews.llvm.org>:

> malcolm.parsons added a comment.
>
> I think spaces that will be removed should be counted - long long is 9.
>
> OTOH, MinTypeNameLength isn't likely to be set high enough for that to
> matter.
>
>
> Repository:
>   rCTE Clang Tools Extra
>
> https://reviews.llvm.org/D45927
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r331297 - [clang-tidy][modernize-raw-string-literal] Don't replace upper ASCII with raw literals

2018-05-01 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Tue May  1 11:46:32 2018
New Revision: 331297

URL: http://llvm.org/viewvc/llvm-project?rev=331297&view=rev
Log:
[clang-tidy][modernize-raw-string-literal] Don't replace upper ASCII with raw 
literals

It's useless and not safe to replace UTF-8 encoded with escaped ASCII to raw 
UTF-8 chars:
"\xE2\x98\x83" ---> 
So don't do it.


Modified:
clang-tools-extra/trunk/clang-tidy/modernize/RawStringLiteralCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/RawStringLiteralCheck.h
clang-tools-extra/trunk/test/clang-tidy/modernize-raw-string-literal.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/RawStringLiteralCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/RawStringLiteralCheck.cpp?rev=331297&r1=331296&r2=331297&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/RawStringLiteralCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/RawStringLiteralCheck.cpp Tue 
May  1 11:46:32 2018
@@ -42,28 +42,15 @@ bool isRawStringLiteral(StringRef Text)
 }
 
 bool containsEscapedCharacters(const MatchFinder::MatchResult &Result,
-   const StringLiteral *Literal) {
+   const StringLiteral *Literal,
+   const CharsBitSet &DisallowedChars) {
   // FIXME: Handle L"", u8"", u"" and U"" literals.
   if (!Literal->isAscii())
 return false;
 
-  StringRef Bytes = Literal->getBytes();
-  // Non-printing characters disqualify this literal:
-  // \007 = \a bell
-  // \010 = \b backspace
-  // \011 = \t horizontal tab
-  // \012 = \n new line
-  // \013 = \v vertical tab
-  // \014 = \f form feed
-  // \015 = \r carriage return
-  // \177 = delete
-  if (Bytes.find_first_of(StringRef("\000\001\002\003\004\005\006\a"
-"\b\t\n\v\f\r\016\017"
-"\020\021\022\023\024\025\026\027"
-"\030\031\032\033\034\035\036\037"
-"\177",
-33)) != StringRef::npos)
-return false;
+  for (const unsigned char C : Literal->getBytes())
+if (DisallowedChars.test(C))
+  return false;
 
   CharSourceRange CharRange = Lexer::makeFileCharRange(
   CharSourceRange::getTokenRange(Literal->getSourceRange()),
@@ -102,7 +89,28 @@ RawStringLiteralCheck::RawStringLiteralC
  ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
   DelimiterStem(Options.get("DelimiterStem", "lit")),
-  ReplaceShorterLiterals(Options.get("ReplaceShorterLiterals", false)) {}
+  ReplaceShorterLiterals(Options.get("ReplaceShorterLiterals", false)) {
+  // Non-printing characters are disallowed:
+  // \007 = \a bell
+  // \010 = \b backspace
+  // \011 = \t horizontal tab
+  // \012 = \n new line
+  // \013 = \v vertical tab
+  // \014 = \f form feed
+  // \015 = \r carriage return
+  // \177 = delete
+  for (const unsigned char C : StringRef("\000\001\002\003\004\005\006\a"
+ "\b\t\n\v\f\r\016\017"
+ "\020\021\022\023\024\025\026\027"
+ "\030\031\032\033\034\035\036\037"
+ "\177",
+ 33))
+DisallowedChars.set(C);
+
+  // Non-ASCII are disallowed too.
+  for (unsigned int C = 0x80u; C <= 0xFFu; ++C)
+DisallowedChars.set(static_cast(C));
+}
 
 void RawStringLiteralCheck::storeOptions(ClangTidyOptions::OptionMap &Options) 
{
   ClangTidyCheck::storeOptions(Options);
@@ -124,7 +132,7 @@ void RawStringLiteralCheck::check(const
   if (Literal->getLocStart().isMacroID())
 return;
 
-  if (containsEscapedCharacters(Result, Literal)) {
+  if (containsEscapedCharacters(Result, Literal, DisallowedChars)) {
 std::string Replacement = asRawStringLiteral(Literal, DelimiterStem);
 if (ReplaceShorterLiterals ||
 Replacement.length() <=

Modified: clang-tools-extra/trunk/clang-tidy/modernize/RawStringLiteralCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/RawStringLiteralCheck.h?rev=331297&r1=331296&r2=331297&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/RawStringLiteralCheck.h 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/RawStringLiteralCheck.h Tue 
May  1 11:46:32 2018
@@ -11,11 +11,14 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_RAW_STRING_LITERAL_H
 
 #include "../ClangTidy.h"
+#include 
 
 namespace clang {
 namespace tidy {
 namespace modernize {
 
+using CharsBitSet = std::bitset<1 << CHAR_BIT>;
+
 /// This check replaces string literals with escaped characters to
 /// raw s

[clang-tools-extra] r331474 - [clang-tidy] Define __clang_analyzer__ macro for clang-tidy for compatibility with clang static analyzer

2018-05-03 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Thu May  3 11:26:39 2018
New Revision: 331474

URL: http://llvm.org/viewvc/llvm-project?rev=331474&view=rev
Log:
[clang-tidy] Define __clang_analyzer__ macro for clang-tidy for compatibility 
with clang static analyzer

This macro is widely used in many well-known projects, ex. Chromium.
But it's not set for clang-tidy, so for ex. DCHECK in Chromium is not considered
as [[no-return]], and a lot of false-positive warnings about nullptr
dereferenced are emitted.

Differential Revision: https://reviews.llvm.org/D46325


Added:

clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=331474&r1=331473&r2=331474&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Thu May  3 11:26:39 2018
@@ -524,6 +524,18 @@ void runClangTidy(clang::tidy::ClangTidy
 ActionFactory(ClangTidyContext &Context) : ConsumerFactory(Context) {}
 FrontendAction *create() override { return new Action(&ConsumerFactory); }
 
+bool runInvocation(std::shared_ptr Invocation,
+   FileManager *Files,
+   std::shared_ptr PCHContainerOps,
+   DiagnosticConsumer *DiagConsumer) override {
+  // Explicitly set ProgramAction to RunAnalysis to make the preprocessor
+  // define __clang_analyzer__ macro. The frontend analyzer action will not
+  // be called here.
+  Invocation->getFrontendOpts().ProgramAction = frontend::RunAnalysis;
+  return FrontendActionFactory::runInvocation(
+  Invocation, Files, PCHContainerOps, DiagConsumer);
+}
+
   private:
 class Action : public ASTFrontendAction {
 public:

Added: 
clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp?rev=331474&view=auto
==
--- 
clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp 
(added)
+++ 
clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp 
Thu May  3 11:26:39 2018
@@ -0,0 +1,10 @@
+// RUN: clang-tidy %s -checks=-*,modernize-use-nullptr -- | count 0
+
+#if !defined(__clang_analyzer__)
+#error __clang_analyzer__ is not defined
+#endif
+// RUN: clang-tidy %s -checks=-*,modernize-use-nullptr -- | count 0
+
+#if !defined(__clang_analyzer__)
+#error __clang_analyzer__ is not defined
+#endif


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r331475 - Simplify test clang-tidy-__clang_analyzer__macro.cpp

2018-05-03 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Thu May  3 11:31:39 2018
New Revision: 331475

URL: http://llvm.org/viewvc/llvm-project?rev=331475&view=rev
Log:
Simplify test clang-tidy-__clang_analyzer__macro.cpp 


Modified:

clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp?rev=331475&r1=331474&r2=331475&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp 
Thu May  3 11:31:39 2018
@@ -3,8 +3,3 @@
 #if !defined(__clang_analyzer__)
 #error __clang_analyzer__ is not defined
 #endif
-// RUN: clang-tidy %s -checks=-*,modernize-use-nullptr -- | count 0
-
-#if !defined(__clang_analyzer__)
-#error __clang_analyzer__ is not defined
-#endif


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 6271b96 - [clang-tidy][modernize-loop-convert] Make loop var type human readable

2020-06-04 Thread Zinovy Nis via cfe-commits

Author: Zinovy Nis
Date: 2020-06-04T19:51:45+03:00
New Revision: 6271b96bef479882cf43397941a4c95aa9f47403

URL: 
https://github.com/llvm/llvm-project/commit/6271b96bef479882cf43397941a4c95aa9f47403
DIFF: 
https://github.com/llvm/llvm-project/commit/6271b96bef479882cf43397941a4c95aa9f47403.diff

LOG: [clang-tidy][modernize-loop-convert] Make loop var type human readable

Differential Revision: https://reviews.llvm.org/D80536

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-loop-convert/structures.h

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index aa914ef7bbf5..be3a7141a5cc 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -621,6 +621,7 @@ void LoopConvertCheck::doConversion(
   QualType Type = Context->getAutoDeductType();
   if (!Descriptor.ElemType.isNull() && 
Descriptor.ElemType->isFundamentalType())
 Type = Descriptor.ElemType.getUnqualifiedType();
+  Type = Type.getDesugaredType(*Context);
 
   // If the new variable name is from the aliased variable, then the reference
   // type for the new variable should only be used if the aliased variable was

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-loop-convert/structures.h
 
b/clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-loop-convert/structures.h
index 02d440c21a52..22b70f082d7b 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-loop-convert/structures.h
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-loop-convert/structures.h
@@ -40,13 +40,14 @@ struct S {
 };
 
 struct T {
+  typedef int value_type;
   struct iterator {
-int& operator*();
-const int& operator*()const;
+value_type &operator*();
+const value_type &operator*() const;
 iterator& operator ++();
 bool operator!=(const iterator &other);
-void insert(int);
-int X;
+void insert(value_type);
+value_type X;
   };
   iterator begin();
   iterator end();



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] c063b4a - Fix crash on misc-redundant-expression

2020-06-05 Thread Zinovy Nis via cfe-commits

Author: Zinovy Nis
Date: 2020-06-05T18:43:57+03:00
New Revision: c063b4a72bb39d9ae4bd13851873ddcbc16f6804

URL: 
https://github.com/llvm/llvm-project/commit/c063b4a72bb39d9ae4bd13851873ddcbc16f6804
DIFF: 
https://github.com/llvm/llvm-project/commit/c063b4a72bb39d9ae4bd13851873ddcbc16f6804.diff

LOG: Fix crash on misc-redundant-expression

Differential Revision: https://reviews.llvm.org/D80896

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
index edb765b287f9..aef513a527b5 100644
--- a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -72,8 +72,8 @@ static bool areEquivalentExpr(const Expr *Left, const Expr 
*Right) {
   Expr::const_child_iterator LeftIter = Left->child_begin();
   Expr::const_child_iterator RightIter = Right->child_begin();
   while (LeftIter != Left->child_end() && RightIter != Right->child_end()) {
-if (!areEquivalentExpr(dyn_cast(*LeftIter),
-   dyn_cast(*RightIter)))
+if (!areEquivalentExpr(dyn_cast_or_null(*LeftIter),
+   dyn_cast_or_null(*RightIter)))
   return false;
 ++LeftIter;
 ++RightIter;
@@ -117,6 +117,9 @@ static bool areEquivalentExpr(const Expr *Left, const Expr 
*Right) {
   case Stmt::MemberExprClass:
 return cast(Left)->getMemberDecl() ==
cast(Right)->getMemberDecl();
+  case Stmt::CXXFoldExprClass:
+return cast(Left)->getOperator() ==
+   cast(Right)->getOperator();
   case Stmt::CXXFunctionalCastExprClass:
   case Stmt::CStyleCastExprClass:
 return cast(Left)->getTypeAsWritten() ==

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
index 4a4304be9bf4..c47ef7d36ff5 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
@@ -793,4 +793,10 @@ struct Bar {
 return foo < GetFoo() && foo < maybe_foo;
   }
 };
-}
+
+template 
+struct Bar2 {
+  static_assert((... && (sizeof(Values) > 0)) == (... && (sizeof(Values) > 
0)));
+  // CHECK-MESSAGES: :[[@LINE-1]]:47: warning: both sides of operator are 
equivalent [misc-redundant-expression]
+};
+} // namespace no_crash



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 96c6d01 - [clang-tidy] Fix crash in modernize-use-noexcept on uninstantiated throw class

2020-09-15 Thread Zinovy Nis via cfe-commits

Author: Zinovy Nis
Date: 2020-09-16T08:13:00+03:00
New Revision: 96c6d012dfe2492891d0f0450dd7cd5f3c1ca88c

URL: 
https://github.com/llvm/llvm-project/commit/96c6d012dfe2492891d0f0450dd7cd5f3c1ca88c
DIFF: 
https://github.com/llvm/llvm-project/commit/96c6d012dfe2492891d0f0450dd7cd5f3c1ca88c.diff

LOG: [clang-tidy] Fix crash in modernize-use-noexcept on uninstantiated throw 
class

Bug: https://bugs.llvm.org/show_bug.cgi?id=47446

Differential Revision: https://reviews.llvm.org/D87627

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/modernize-use-noexcept-opt.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp
index cc4bc05a35dd..c4e7f12e74ac 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp
@@ -77,13 +77,16 @@ void UseNoexceptCheck::check(const MatchFinder::MatchResult 
&Result) {
   .getExceptionSpecRange();
   }
 
+  assert(FnTy && "FunctionProtoType is null.");
+  if (isUnresolvedExceptionSpec(FnTy->getExceptionSpecType()))
+return;
+
   assert(Range.isValid() && "Exception Source Range is invalid.");
 
   CharSourceRange CRange = Lexer::makeFileCharRange(
   CharSourceRange::getTokenRange(Range), *Result.SourceManager,
   Result.Context->getLangOpts());
 
-  assert(FnTy && "FunctionProtoType is null.");
   bool IsNoThrow = FnTy->isNothrow();
   StringRef ReplacementStr =
   IsNoThrow

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize-use-noexcept-opt.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize-use-noexcept-opt.cpp
index 92c1387d64d6..b0f52a18edf5 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize-use-noexcept-opt.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize-use-noexcept-opt.cpp
@@ -4,6 +4,7 @@
 // This test is not run in C++17 or later because dynamic exception
 // specifications were removed in C++17.
 
+using size_t = __SIZE_TYPE__;
 class A {};
 class B {};
 
@@ -19,6 +20,11 @@ void k() throw(int(int));
 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: dynamic exception specification 
'throw(int(int))' is deprecated; consider removing it instead 
[modernize-use-noexcept]
 // CHECK-FIXES: void k() ;
 
+// Shouldn't crash due to llvm_unreachable in canThrow() on EST_Uninstantiated
+template  class c { void *operator new(size_t) throw (int);};
+void s() { c<1> doesnt_crash; }
+// CHECK-MESSAGES: :[[@LINE-2]]:53: warning: dynamic exception specification 
'throw (int)' is deprecated; consider removing it instead 
[modernize-use-noexcept]
+
 void foobar() throw(A, B)
 {}
 // CHECK-MESSAGES: :[[@LINE-2]]:15: warning: dynamic exception specification 
'throw(A, B)' is deprecated; consider removing it instead 
[modernize-use-noexcept]



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 709112b - [clang-tidy] false-positive for bugprone-redundant-branch-condition in case of passed-by-ref params

2020-12-11 Thread Zinovy Nis via cfe-commits

Author: Zinovy Nis
Date: 2020-12-11T21:09:51+03:00
New Revision: 709112bce4424a5436f0bb699c62b3fbc837fbb6

URL: 
https://github.com/llvm/llvm-project/commit/709112bce4424a5436f0bb699c62b3fbc837fbb6
DIFF: 
https://github.com/llvm/llvm-project/commit/709112bce4424a5436f0bb699c62b3fbc837fbb6.diff

LOG: [clang-tidy] false-positive for bugprone-redundant-branch-condition in 
case of passed-by-ref params

Inspired by discussion in https://reviews.llvm.org/D91037

Differential Revision: https://reviews.llvm.org/D91495

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
index abb8e8be9b2f..2b0d9630527b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
@@ -23,15 +23,21 @@ namespace bugprone {
 static const char CondVarStr[] = "cond_var";
 static const char OuterIfStr[] = "outer_if";
 static const char InnerIfStr[] = "inner_if";
+static const char OuterIfVar1Str[] = "outer_if_var1";
+static const char OuterIfVar2Str[] = "outer_if_var2";
+static const char InnerIfVar1Str[] = "inner_if_var1";
+static const char InnerIfVar2Str[] = "inner_if_var2";
 static const char FuncStr[] = "func";
 
-/// Returns whether `Var` is changed in `S` before `NextS`.
-static bool isChangedBefore(const Stmt *S, const Stmt *NextS,
+/// Returns whether `Var` is changed in range (`PrevS`..`NextS`).
+static bool isChangedBefore(const Stmt *S, const Stmt *NextS, const Stmt 
*PrevS,
 const VarDecl *Var, ASTContext *Context) {
   ExprMutationAnalyzer MutAn(*S, *Context);
   const auto &SM = Context->getSourceManager();
   const Stmt *MutS = MutAn.findMutation(Var);
   return MutS &&
+ SM.isBeforeInTranslationUnit(PrevS->getEndLoc(),
+  MutS->getBeginLoc()) &&
  SM.isBeforeInTranslationUnit(MutS->getEndLoc(), NextS->getBeginLoc());
 }
 
@@ -43,19 +49,22 @@ void 
RedundantBranchConditionCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   ifStmt(
   hasCondition(ignoringParenImpCasts(anyOf(
-  declRefExpr(hasDeclaration(ImmutableVar)),
+  declRefExpr(hasDeclaration(ImmutableVar)).bind(OuterIfVar1Str),
   binaryOperator(hasOperatorName("&&"),
- 
hasEitherOperand(ignoringParenImpCasts(declRefExpr(
- hasDeclaration(ImmutableVar,
+ hasEitherOperand(ignoringParenImpCasts(
+ declRefExpr(hasDeclaration(ImmutableVar))
+ .bind(OuterIfVar2Str))),
   hasThen(hasDescendant(
   ifStmt(hasCondition(ignoringParenImpCasts(
- anyOf(declRefExpr(hasDeclaration(
-   varDecl(equalsBoundNode(CondVarStr,
+ anyOf(declRefExpr(hasDeclaration(varDecl(
+equalsBoundNode(CondVarStr
+.bind(InnerIfVar1Str),
binaryOperator(
hasAnyOperatorName("&&", "||"),
hasEitherOperand(ignoringParenImpCasts(
declRefExpr(hasDeclaration(varDecl(
-   
equalsBoundNode(CondVarStr)))
+ equalsBoundNode(CondVarStr
+ .bind(InnerIfVar2Str
   .bind(InnerIfStr))),
   forFunction(functionDecl().bind(FuncStr)))
   .bind(OuterIfStr),
@@ -69,15 +78,32 @@ void RedundantBranchConditionCheck::check(const 
MatchFinder::MatchResult &Result
   const auto *CondVar = Result.Nodes.getNodeAs(CondVarStr);
   const auto *Func = Result.Nodes.getNodeAs(FuncStr);
 
+  const DeclRefExpr *OuterIfVar, *InnerIfVar;
+  if (const auto *Inner = Result.Nodes.getNodeAs(InnerIfVar1Str))
+InnerIfVar = Inner;
+  else
+InnerIfVar = Result.Nodes.getNodeAs(InnerIfVar2Str);
+  if (const auto *Outer = Result.Nodes.getNodeAs(OuterIfVar1Str))
+OuterIfVar = Outer;
+  else
+OuterIfVar = Result.Nodes.getNodeAs(OuterIfVar2Str);
+
+  if (OuterIfVar && InnerIfVar) {
+if (isChangedBefore(OuterIf->getThen(), InnerIfVar, OuterIfVar, CondVar,
+Result.Context))
+  return;
+
+if (isChangedBefore(OuterIf->getCond(), InnerIfVar, OuterIfVar, CondVar,
+Result.Context))
+  r

[clang-tools-extra] 4364539 - [clang-tidy] Fix crash in bugprone-redundant-branch-condition on ExprWithCleanups

2020-11-13 Thread Zinovy Nis via cfe-commits

Author: Zinovy Nis
Date: 2020-11-14T08:35:21+03:00
New Revision: 4364539b3a4c5e73561e5ff29e6952a75e89dc43

URL: 
https://github.com/llvm/llvm-project/commit/4364539b3a4c5e73561e5ff29e6952a75e89dc43
DIFF: 
https://github.com/llvm/llvm-project/commit/4364539b3a4c5e73561e5ff29e6952a75e89dc43.diff

LOG: [clang-tidy] Fix crash in bugprone-redundant-branch-condition on 
ExprWithCleanups

Bug: https://bugs.llvm.org/show_bug.cgi?id=48008

Differential Revision: https://reviews.llvm.org/D91037

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
index 137356acbdba..abb8e8be9b2f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
@@ -82,7 +82,9 @@ void RedundantBranchConditionCheck::check(const 
MatchFinder::MatchResult &Result
 
   // For standalone condition variables and for "or" binary operations we 
simply
   // remove the inner `if`.
-  const auto *BinOpCond = dyn_cast(InnerIf->getCond());
+  const auto *BinOpCond =
+  dyn_cast(InnerIf->getCond()->IgnoreParenImpCasts());
+
   if (isa(InnerIf->getCond()->IgnoreParenImpCasts()) ||
   (BinOpCond && BinOpCond->getOpcode() == BO_LOr)) {
 SourceLocation IfBegin = InnerIf->getBeginLoc();
@@ -129,7 +131,8 @@ void RedundantBranchConditionCheck::check(const 
MatchFinder::MatchResult &Result
 // For "and" binary operations we remove the "and" operation with the
 // condition variable from the inner if.
   } else {
-const auto *CondOp = cast(InnerIf->getCond());
+const auto *CondOp =
+cast(InnerIf->getCond()->IgnoreParenImpCasts());
 const auto *LeftDRE =
 dyn_cast(CondOp->getLHS()->IgnoreParenImpCasts());
 if (LeftDRE && LeftDRE->getDecl() == CondVar) {

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
index 2bfd49a82955..dd001e836477 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
@@ -1073,6 +1073,34 @@ void positive_comma_after_condition() {
   }
 }
 
+// ExprWithCleanups doesn't crash
+int positive_expr_with_cleanups() {
+  class RetT {
+  public:
+RetT(const int _code) : code_(_code) {}
+bool Ok() const { return code_ == 0; }
+static RetT Test(bool &_isSet) { return 0; }
+
+  private:
+int code_;
+  };
+
+  bool isSet = false;
+  if (RetT::Test(isSet).Ok() && isSet) {
+if (RetT::Test(isSet).Ok() && isSet) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: redundant condition 'isSet' 
[bugprone-redundant-branch-condition]
+  // CHECK-FIXES: if (RetT::Test(isSet).Ok() ) {
+}
+  }
+  if (isSet) {
+if ((RetT::Test(isSet).Ok() && isSet)) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: redundant condition 'isSet' 
[bugprone-redundant-branch-condition]
+  // CHECK-FIXES: if ((RetT::Test(isSet).Ok() )) {
+}
+  }
+  return 0;
+}
+
 //===--- Special Negatives 
===//
 
 // Aliasing



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 32d565b - [clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs

2020-10-11 Thread Zinovy Nis via cfe-commits

Author: Zinovy Nis
Date: 2020-10-11T18:52:38+03:00
New Revision: 32d565b4618d31511e79dbe77aae8d456f2bf466

URL: 
https://github.com/llvm/llvm-project/commit/32d565b4618d31511e79dbe77aae8d456f2bf466
DIFF: 
https://github.com/llvm/llvm-project/commit/32d565b4618d31511e79dbe77aae8d456f2bf466.diff

LOG: [clang-tidy] Fix crash in readability-function-cognitive-complexity on 
weak refs

Fix for https://bugs.llvm.org/show_bug.cgi?id=47779

Differential Revision: https://reviews.llvm.org/D89194

Added: 


Modified: 

clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
clang/docs/LibASTMatchersReference.html
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/Dynamic/Registry.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
index 96fe9a2e29a4..96854bf2a7ab 100644
--- 
a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -501,9 +501,9 @@ void FunctionCognitiveComplexityCheck::storeOptions(
 
 void FunctionCognitiveComplexityCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  functionDecl(
-  allOf(isDefinition(), unless(anyOf(isDefaulted(), isDeleted(),
- isImplicit(), isInstantiated()
+  functionDecl(isDefinition(),
+   unless(anyOf(isDefaulted(), isDeleted(), isImplicit(),
+isInstantiated(), isWeak(
   .bind("func"),
   this);
 }

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
index 431540c6ee96..0916acd8e675 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
@@ -1013,3 +1013,5 @@ void functionThatCallsTemplatedFunctions() {
 
   templatedFunction();
 }
+
+static void pr47779_dont_crash_on_weak() 
__attribute__((__weakref__("__pr47779_dont_crash_on_weak")));

diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index fd8b217b7bc8..e281c5d3b850 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -3569,6 +3569,17 @@ Narrowing Matchers
 
 
 
+MatcherFunctionDecl>isWeak
+Matches weak function 
declarations.
+
+Given:
+  void foo() __attribute__((__weakref__("__foo")));
+  void bar();
+functionDecl(isWeak())
+  matches the weak declaration "foo", but not "bar".
+
+
+
 MatcherFunctionDecl>parameterCountIsunsigned N
 Matches 
FunctionDecls and FunctionProtoTypes that have a
 specific parameter count.

diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index fd79b176ab4b..51d51d707de4 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4647,6 +4647,17 @@ AST_MATCHER(FunctionDecl, isDefaulted) {
   return Node.isDefaulted();
 }
 
+/// Matches weak function declarations.
+///
+/// Given:
+/// \code
+///   void foo() __attribute__((__weakref__("__foo")));
+///   void bar();
+/// \endcode
+/// functionDecl(isWeak())
+///   matches the weak declaration "foo", but not "bar".
+AST_MATCHER(FunctionDecl, isWeak) { return Node.isWeak(); }
+
 /// Matches functions that have a dynamic exception specification.
 ///
 /// Given:

diff  --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 8e62dce4fab5..00e6abbb477b 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -433,6 +433,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(isVirtual);
   REGISTER_MATCHER(isVirtualAsWritten);
   REGISTER_MATCHER(isVolatileQualified);
+  REGISTER_MATCHER(isWeak);
   REGISTER_MATCHER(isWritten);
   REGISTER_MATCHER(lValueReferenceType);
   REGISTER_MATCHER(labelDecl);



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D44906: [clang-tidy] Define __clang_analyzer__ macro for clang-tidy for compatibility with clang static analyzer

2018-04-02 Thread Zinovy Nis via cfe-commits
Looks like quotes are required.
Thanks for pointing! I'll submit a patch for this.

пн, 2 апр. 2018 г. в 17:28, Nico Weber via Phabricator <
revi...@reviews.llvm.org>:

> thakis added a comment.
>
> Actually, it doesn't pass on non-Windows either:
> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/27665/steps/test/logs/stdio
>
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D44906
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r328932 - [clang-tidy] Define __clang_analyzer__ macro for clang-tidy for compatibility with clang static analyzer

2018-04-02 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Sun Apr  1 04:51:57 2018
New Revision: 328932

URL: http://llvm.org/viewvc/llvm-project?rev=328932&view=rev
Log:
[clang-tidy] Define __clang_analyzer__ macro for clang-tidy for compatibility 
with clang static analyzer

This macro is widely used in many well-known projects, ex. Chromium.
But it's not set for clang-tidy, so for ex. DCHECK in Chromium is not 
considered as [[no-return]], and a lot of false-positive warnings about nullptr 
dereferenced are emitted.
This patch fixes the issue by explicitly added macro definition.

Differential Revision: https://reviews.llvm.org/D44906

Added:

clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp  
 (with props)
Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=328932&r1=328931&r2=328932&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Sun Apr  1 04:51:57 2018
@@ -481,6 +481,16 @@ void runClangTidy(clang::tidy::ClangTidy
   ClangTool Tool(Compilations, InputFiles,
  std::make_shared(), BaseFS);
 
+  // Add __clang_analyzer__ macro definition for compatibility with the clang
+  // static analyzer.
+  ArgumentsAdjuster ClangTidyMacroDefinitionInserter =
+  [&Context](const CommandLineArguments &Args, StringRef Filename) {
+ClangTidyOptions Opts = Context.getOptionsForFile(Filename);
+CommandLineArguments AdjustedArgs = Args;
+AdjustedArgs.emplace_back("-D__clang_analyzer__");
+return AdjustedArgs;
+  };
+
   // Add extra arguments passed by the clang-tidy command-line.
   ArgumentsAdjuster PerFileExtraArgumentsInserter =
   [&Context](const CommandLineArguments &Args, StringRef Filename) {
@@ -515,6 +525,7 @@ void runClangTidy(clang::tidy::ClangTidy
 return AdjustedArgs;
   };
 
+  Tool.appendArgumentsAdjuster(ClangTidyMacroDefinitionInserter);
   Tool.appendArgumentsAdjuster(PerFileExtraArgumentsInserter);
   Tool.appendArgumentsAdjuster(PluginArgumentsRemover);
   if (Profile)

Added: 
clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp?rev=328932&view=auto
==
--- 
clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp 
(added)
+++ 
clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp 
Sun Apr  1 04:51:57 2018
@@ -0,0 +1,8 @@
+// RUN: %check_clang_tidy %s * %t
+
+#if defined(__clang_analyzer__)
+#warning __clang_analyzer__ is defined
+#endif
+// CHECK-MESSAGES: :[[@LINE-2]]:2: warning: __clang_analyzer__ is defined 
[clang-diagnostic-#warnings]
+
+

Propchange: 
clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp
--
svn:executable = *


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r329448 - [clang-tidy] Check if grand-..parent's virtual method was called instead of overridden parent's.

2018-04-06 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Fri Apr  6 13:02:50 2018
New Revision: 329448

URL: http://llvm.org/viewvc/llvm-project?rev=329448&view=rev
Log:
[clang-tidy] Check if grand-..parent's virtual method was called instead of 
overridden parent's. 

class A {...int virtual foo() {...}...}; 
class B: public A {...int foo() override {...}...}; 
class C: public B {...int foo() override {... A::foo()...}};
   warning: qualified name 
A::foo refers to a member overridden in subclass; did you mean 'B'? 
[bugprone-parent-virtual-call] 

Differential Revision: https://reviews.llvm.org/D44295

Added:
clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp   
(with props)
clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.h   
(with props)

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-parent-virtual-call.rst 
  (with props)
clang-tools-extra/trunk/test/clang-tidy/bugprone-parent-virtual-call.cpp   
(with props)
Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp?rev=329448&r1=329447&r2=329448&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Fri Apr  
6 13:02:50 2018
@@ -28,6 +28,7 @@
 #include "MisplacedWideningCastCheck.h"
 #include "MoveForwardingReferenceCheck.h"
 #include "MultipleStatementMacroCheck.h"
+#include "ParentVirtualCallCheck.h"
 #include "SizeofContainerCheck.h"
 #include "SizeofExpressionCheck.h"
 #include "StringConstructorCheck.h"
@@ -90,6 +91,8 @@ public:
 "bugprone-move-forwarding-reference");
 CheckFactories.registerCheck(
 "bugprone-multiple-statement-macro");
+CheckFactories.registerCheck(
+"bugprone-parent-virtual-call");
 CheckFactories.registerCheck(
 "bugprone-sizeof-container");
 CheckFactories.registerCheck(

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt?rev=329448&r1=329447&r2=329448&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt Fri Apr  6 
13:02:50 2018
@@ -20,6 +20,7 @@ add_clang_library(clangTidyBugproneModul
   MisplacedWideningCastCheck.cpp
   MoveForwardingReferenceCheck.cpp
   MultipleStatementMacroCheck.cpp
+  ParentVirtualCallCheck.cpp
   SizeofContainerCheck.cpp
   SizeofExpressionCheck.cpp
   StringConstructorCheck.cpp

Added: clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp?rev=329448&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp Fri 
Apr  6 13:02:50 2018
@@ -0,0 +1,154 @@
+//===--- ParentVirtualCallCheck.cpp - 
clang-tidy---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ParentVirtualCallCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Tooling/FixIt.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace bugprone {
+
+using BasesVector = llvm::SmallVector;
+
+static bool isParentOf(const CXXRecordDecl &Parent,
+   const CXXRecordDecl &ThisClass) {
+  if (Parent.getCanonicalDecl() == ThisClass.getCanonicalDecl())
+return true;
+  const auto ClassIter = llvm::find_if(ThisClass.bases(), [=](auto &Base) {
+auto *BaseDecl = Base.getType()->getAsCXXRecordDecl();
+assert(BaseDecl);
+return Parent.getCanonicalDecl() == BaseDecl->getCanonicalDecl();
+  });
+  return ClassIter != ThisClass.bases_end();
+}
+
+static BasesVector getParentsByGrandParent(const CXXRecordDecl &GrandParent,
+   const CXXRecordDecl &ThisClass,
+

[clang-tools-extra] r329452 - [clang-tidy] Fix compilation for ParentVirtualCallCheck.cpp

2018-04-06 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Fri Apr  6 13:39:23 2018
New Revision: 329452

URL: http://llvm.org/viewvc/llvm-project?rev=329452&view=rev
Log:
[clang-tidy] Fix compilation for ParentVirtualCallCheck.cpp


Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp?rev=329452&r1=329451&r2=329452&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp Fri 
Apr  6 13:39:23 2018
@@ -11,8 +11,8 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Tooling/FixIt.h"
-#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
+#include 
 #include 
 
 using namespace clang::ast_matchers;
@@ -27,11 +27,13 @@ static bool isParentOf(const CXXRecordDe
const CXXRecordDecl &ThisClass) {
   if (Parent.getCanonicalDecl() == ThisClass.getCanonicalDecl())
 return true;
-  const auto ClassIter = llvm::find_if(ThisClass.bases(), [=](auto &Base) {
-auto *BaseDecl = Base.getType()->getAsCXXRecordDecl();
-assert(BaseDecl);
-return Parent.getCanonicalDecl() == BaseDecl->getCanonicalDecl();
-  });
+  const auto ClassIter = std::find_if(
+  ThisClass.bases().begin(), ThisClass.bases().end(),
+  [=](const CXXBaseSpecifier &Base) {
+auto *BaseDecl = Base.getType()->getAsCXXRecordDecl();
+assert(BaseDecl);
+return Parent.getCanonicalDecl() == BaseDecl->getCanonicalDecl();
+  });
   return ClassIter != ThisClass.bases_end();
 }
 
@@ -74,7 +76,8 @@ static std::string getNameAsString(const
 static std::string getExprAsString(const clang::Expr &E,
clang::ASTContext &AC) {
   std::string Text = tooling::fixit::getText(E, AC).str();
-  Text.erase(llvm::remove_if(Text, std::isspace), Text.end());
+  Text.erase(std::remove_if(Text.begin(), Text.end(), std::isspace),
+ Text.end());
   return Text;
 }
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r329454 - [clang-tidy] One more fix compilation for ParentVirtualCallCheck.cpp: find_if predicate

2018-04-06 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Fri Apr  6 14:00:18 2018
New Revision: 329454

URL: http://llvm.org/viewvc/llvm-project?rev=329454&view=rev
Log:
[clang-tidy] One more fix compilation for ParentVirtualCallCheck.cpp: find_if 
predicate


Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp?rev=329454&r1=329453&r2=329454&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp Fri 
Apr  6 14:00:18 2018
@@ -76,8 +76,11 @@ static std::string getNameAsString(const
 static std::string getExprAsString(const clang::Expr &E,
clang::ASTContext &AC) {
   std::string Text = tooling::fixit::getText(E, AC).str();
-  Text.erase(std::remove_if(Text.begin(), Text.end(), std::isspace),
- Text.end());
+  Text.erase(
+  std::remove_if(
+  Text.begin(), Text.end(),
+  [](char c) { return std::isspace(static_cast(c)); }),
+  Text.end());
   return Text;
 }
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r329495 - [clang-tidy] Fix compilation for MSVS@PSP4 for ParentVirtualCallCheck.cpp

2018-04-07 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Sat Apr  7 04:22:01 2018
New Revision: 329495

URL: http://llvm.org/viewvc/llvm-project?rev=329495&view=rev
Log:
[clang-tidy] Fix compilation for MSVS@PSP4 for ParentVirtualCallCheck.cpp

There's an error for PSP4 platform only: 
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\algorithm(95): 
error C2719: '_Pred': formal parameter with requested alignment of 8 won't be 
aligned


Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp?rev=329495&r1=329494&r2=329495&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp Sat 
Apr  7 04:22:01 2018
@@ -27,14 +27,13 @@ static bool isParentOf(const CXXRecordDe
const CXXRecordDecl &ThisClass) {
   if (Parent.getCanonicalDecl() == ThisClass.getCanonicalDecl())
 return true;
-  const auto ClassIter = std::find_if(
-  ThisClass.bases().begin(), ThisClass.bases().end(),
-  [=](const CXXBaseSpecifier &Base) {
-auto *BaseDecl = Base.getType()->getAsCXXRecordDecl();
-assert(BaseDecl);
-return Parent.getCanonicalDecl() == BaseDecl->getCanonicalDecl();
-  });
-  return ClassIter != ThisClass.bases_end();
+  for (const CXXBaseSpecifier &Base : ThisClass.bases()) {
+auto *BaseDecl = Base.getType()->getAsCXXRecordDecl();
+assert(BaseDecl);
+if (Parent.getCanonicalDecl() == BaseDecl->getCanonicalDecl())
+  return true;
+  }
+  return false;
 }
 
 static BasesVector getParentsByGrandParent(const CXXRecordDecl &GrandParent,


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang-tools-extra] r329550 - Fix unused variable warning.

2018-04-09 Thread Zinovy Nis via cfe-commits
Thanks, Chandler.

   assert(Result.Nodes.getNodeAs("call"));

would also be fine.

пн, 9 апр. 2018 г. в 10:29, Chandler Carruth via cfe-commits <
cfe-commits@lists.llvm.org>:

> Author: chandlerc
> Date: Mon Apr  9 00:26:42 2018
> New Revision: 329550
>
> URL: http://llvm.org/viewvc/llvm-project?rev=329550&view=rev
> Log:
> Fix unused variable warning.
>
> Modified:
> clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
>
> Modified:
> clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp?rev=329550&r1=329549&r2=329550&view=diff
>
> ==
> --- clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
> (original)
> +++ clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
> Mon Apr  9 00:26:42 2018
> @@ -99,6 +99,7 @@ void ParentVirtualCallCheck::registerMat
>
>  void ParentVirtualCallCheck::check(const MatchFinder::MatchResult
> &Result) {
>const auto *MatchedDecl =
> Result.Nodes.getNodeAs("call");
> +  (void)MatchedDecl;
>assert(MatchedDecl);
>
>const auto *Member = Result.Nodes.getNodeAs("member");
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang-tools-extra] r329452 - [clang-tidy] Fix compilation for ParentVirtualCallCheck.cpp

2018-04-09 Thread Zinovy Nis via cfe-commits
f(Text, std::isspace), Text.end());
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:71:0,
 from /usr/include/c++/5/algorithm:61,
 from
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/include/llvm/ADT/Optional.h:23,
 from
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/../ClangTidyOptions.h:13,
 from
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/../ClangTidyDiagnosticConsumer.h:13,
 from
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/../ClangTidy.h:13,
 from
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.h:13,
 from
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp:10:
/usr/include/c++/5/bits/predefined_ops.h: In instantiation of 'bool
__gnu_cxx::__ops::_Iter_pred<_Predicate>::operator()(_Iterator) [with
_Iterator = const clang::CXXBaseSpecifier*; _Predicate =
clang::tidy::bugprone::isParentOf(const clang::CXXRecordDecl&, const
clang::CXXRecordDecl&)::]':
/usr/include/c++/5/bits/stl_algo.h:120:14:   required from
'_RandomAccessIterator std::__find_if(_RandomAccessIterator,
_RandomAccessIterator, _Predicate, std::random_access_iterator_tag)
[with _RandomAccessIterator = const clang::CXXBaseSpecifier*;
_Predicate = 
__gnu_cxx::__ops::_Iter_pred
>]'
/usr/include/c++/5/bits/stl_algo.h:161:23:   required from '_Iterator
std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator =
const clang::CXXBaseSpecifier*; _Predicate =
__gnu_cxx::__ops::_Iter_pred
>]'
/usr/include/c++/5/bits/stl_algo.h:3815:28:   required from '_IIter
std::find_if(_IIter, _IIter, _Predicate) [with _IIter = const
clang::CXXBaseSpecifier*; _Predicate =
clang::tidy::bugprone::isParentOf(const clang::CXXRecordDecl&, const
clang::CXXRecordDecl&)::]'
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/include/llvm/ADT/STLExtras.h:875:22:
  required from 'decltype (llvm::adl_begin(Range)) llvm::find_if(R&&,
UnaryPredicate) [with R = llvm::iterator_range; UnaryPredicate =
clang::tidy::bugprone::isParentOf(const clang::CXXRecordDecl&, const
clang::CXXRecordDecl&)::; decltype
(llvm::adl_begin(Range)) = const clang::CXXBaseSpecifier*]'
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp:34:4:
  required from here
/usr/include/c++/5/bits/predefined_ops.h:234:30: error: no match for
call to '(clang::tidy::bugprone::isParentOf(const
clang::CXXRecordDecl&, const clang::CXXRecordDecl&)::)
(const clang::CXXBaseSpecifier&)'
  { return bool(_M_pred(*__it)); }
  ^
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp:30:73:
note: candidate: clang::tidy::bugprone::isParentOf(const
clang::CXXRecordDecl&, const clang::CXXRecordDecl&)::
   const auto ClassIter = llvm::find_if(ThisClass.bases(), [=](auto &Base) {
 ^
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp:30:73:
note:   no known conversion for argument 1 from 'const
clang::CXXBaseSpecifier' to 'int&'ninja: build stopped: subcommand
failed.

--


пн, 9 апр. 2018 г. в 19:43, Alexander Kornienko :

> On Fri, Apr 6, 2018 at 10:42 PM Zinovy Nis via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: zinovy.nis
>> Date: Fri Apr  6 13:39:23 2018
>> New Revision: 329452
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=329452&view=rev
>> Log:
>> [clang-tidy] Fix compilation for ParentVirtualCallCheck.cpp
>>
>>
>> Modified:
>> clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
>>
>> Modified:
>> clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp?rev=329452&r1=329451&r2=329452&view=diff
>>
>> ==
>> ---
>> clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
>> (original)
>> +++
>> cl

Re: [clang-tools-extra] r329452 - [clang-tidy] Fix compilation for ParentVirtualCallCheck.cpp

2018-04-10 Thread Zinovy Nis via cfe-commits
and/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/../ClangTidy.h:13,
>>  from 
>> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.h:13,
>>  from 
>> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp:10:
>> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/include/llvm/ADT/STLExtras.h:886:6:
>>  note: candidate: template decltype 
>> (llvm::adl_begin(Range)) llvm::remove_if(R&&, UnaryPredicate)
>>  auto remove_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range)) {
>>   ^
>> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/include/llvm/ADT/STLExtras.h:886:6:
>>  note:   template argument deduction/substitution failed:
>> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp:77:48:
>>  note:   couldn't deduce template parameter 'UnaryPredicate'
>>Text.erase(llvm::remove_if(Text, std::isspace), Text.end());
>> ^
>> In file included from /usr/include/c++/5/bits/stl_algobase.h:71:0,
>>  from /usr/include/c++/5/algorithm:61,
>>  from 
>> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/include/llvm/ADT/Optional.h:23,
>>  from 
>> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/../ClangTidyOptions.h:13,
>>  from 
>> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/../ClangTidyDiagnosticConsumer.h:13,
>>  from 
>> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/../ClangTidy.h:13,
>>  from 
>> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.h:13,
>>  from 
>> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp:10:
>> /usr/include/c++/5/bits/predefined_ops.h: In instantiation of 'bool 
>> __gnu_cxx::__ops::_Iter_pred<_Predicate>::operator()(_Iterator) [with 
>> _Iterator = const clang::CXXBaseSpecifier*; _Predicate = 
>> clang::tidy::bugprone::isParentOf(const clang::CXXRecordDecl&, const 
>> clang::CXXRecordDecl&)::]':
>> /usr/include/c++/5/bits/stl_algo.h:120:14:   required from 
>> '_RandomAccessIterator std::__find_if(_RandomAccessIterator, 
>> _RandomAccessIterator, _Predicate, std::random_access_iterator_tag) [with 
>> _RandomAccessIterator = const clang::CXXBaseSpecifier*; _Predicate = 
>> __gnu_cxx::__ops::_Iter_pred> clang::CXXRecordDecl&, const clang::CXXRecordDecl&):: >]'
>> /usr/include/c++/5/bits/stl_algo.h:161:23:   required from '_Iterator 
>> std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator = const 
>> clang::CXXBaseSpecifier*; _Predicate = 
>> __gnu_cxx::__ops::_Iter_pred> clang::CXXRecordDecl&, const clang::CXXRecordDecl&):: >]'
>> /usr/include/c++/5/bits/stl_algo.h:3815:28:   required from '_IIter 
>> std::find_if(_IIter, _IIter, _Predicate) [with _IIter = const 
>> clang::CXXBaseSpecifier*; _Predicate = 
>> clang::tidy::bugprone::isParentOf(const clang::CXXRecordDecl&, const 
>> clang::CXXRecordDecl&)::]'
>> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/include/llvm/ADT/STLExtras.h:875:22:
>>required from 'decltype (llvm::adl_begin(Range)) llvm::find_if(R&&, 
>> UnaryPredicate) [with R = llvm::iterator_range> clang::CXXBaseSpecifier*>; UnaryPredicate = 
>> clang::tidy::bugprone::isParentOf(const clang::CXXRecordDecl&, const 
>> clang::CXXRecordDecl&)::; decltype (llvm::adl_begin(Range)) = 
>> const clang::CXXBaseSpecifier*]'
>> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp:34:4:
>>required from here
>> /usr/include/c++/5/bits/predefined_ops.h:234:30: error: no match for call to 
>> '(clang::tidy::bugprone::isParentOf(const clang::CXXRecordDecl&, const 
>> clang::CXXRecordDecl&)::) (const clang::CXXBaseSpecifier&)'
>>   { return bool(_M_pre

Re: [clang-tools-extra] r329452 - [clang-tidy] Fix compilation for ParentVirtualCallCheck.cpp

2018-04-10 Thread Zinovy Nis via cfe-commits
h:3815:28:   required from '_IIter 
>>>> std::find_if(_IIter, _IIter, _Predicate) [with _IIter = const 
>>>> clang::CXXBaseSpecifier*; _Predicate = 
>>>> clang::tidy::bugprone::isParentOf(const clang::CXXRecordDecl&, const 
>>>> clang::CXXRecordDecl&)::]'
>>>> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/include/llvm/ADT/STLExtras.h:875:22:
>>>>required from 'decltype (llvm::adl_begin(Range)) llvm::find_if(R&&, 
>>>> UnaryPredicate) [with R = llvm::iterator_range>>> clang::CXXBaseSpecifier*>; UnaryPredicate = 
>>>> clang::tidy::bugprone::isParentOf(const clang::CXXRecordDecl&, const 
>>>> clang::CXXRecordDecl&)::; decltype (llvm::adl_begin(Range)) 
>>>> = const clang::CXXBaseSpecifier*]'
>>>> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp:34:4:
>>>>required from here
>>>> /usr/include/c++/5/bits/predefined_ops.h:234:30: error: no match for call 
>>>> to '(clang::tidy::bugprone::isParentOf(const clang::CXXRecordDecl&, const 
>>>> clang::CXXRecordDecl&)::) (const clang::CXXBaseSpecifier&)'
>>>>   { return bool(_M_pred(*__it)); }
>>>>   ^
>>>> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp:30:73:
>>>>  note: candidate: clang::tidy::bugprone::isParentOf(const 
>>>> clang::CXXRecordDecl&, const clang::CXXRecordDecl&)::
>>>>const auto ClassIter = llvm::find_if(ThisClass.bases(), [=](auto &Base) 
>>>> {
>>>>  ^
>>>> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp:30:73:
>>>>  note:   no known conversion for argument 1 from 'const 
>>>> clang::CXXBaseSpecifier' to 'int&'ninja: build stopped: subcommand failed.
>>>>
>>>> --
>>>>
>>>>
>>>> пн, 9 апр. 2018 г. в 19:43, Alexander Kornienko :
>>>>
>>>>> On Fri, Apr 6, 2018 at 10:42 PM Zinovy Nis via cfe-commits <
>>>>> cfe-commits@lists.llvm.org> wrote:
>>>>>
>>>>>> Author: zinovy.nis
>>>>>> Date: Fri Apr  6 13:39:23 2018
>>>>>> New Revision: 329452
>>>>>>
>>>>>> URL: http://llvm.org/viewvc/llvm-project?rev=329452&view=rev
>>>>>> Log:
>>>>>> [clang-tidy] Fix compilation for ParentVirtualCallCheck.cpp
>>>>>>
>>>>>>
>>>>>> Modified:
>>>>>>
>>>>>> clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
>>>>>>
>>>>>> Modified:
>>>>>> clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
>>>>>> URL:
>>>>>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp?rev=329452&r1=329451&r2=329452&view=diff
>>>>>>
>>>>>> ==
>>>>>> ---
>>>>>> clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
>>>>>> (original)
>>>>>> +++
>>>>>> clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp 
>>>>>> Fri
>>>>>> Apr  6 13:39:23 2018
>>>>>> @@ -11,8 +11,8 @@
>>>>>>  #include "clang/AST/ASTContext.h"
>>>>>>  #include "clang/ASTMatchers/ASTMatchFinder.h"
>>>>>>  #include "clang/Tooling/FixIt.h"
>>>>>> -#include "llvm/ADT/STLExtras.h"
>>>>>>  #include "llvm/ADT/SmallVector.h"
>>>>>> +#include 
>>>>>>  #include 
>>>>>>
>>>>>>  using namespace clang::ast_matchers;
>>>>>> @@ -27,11 +27,13 @@ static bool isParentOf(const CXXRecordDe
>>>>>> const CXXRecordDecl &ThisClass) {
>>>>>>if (Parent.getCanonicalDecl() == ThisClass.getCanonicalDecl())
>>>>>>  return true;
>>>>>> -  const auto ClassIter = llvm::find_if(ThisClass.bases(), [=](auto
>>>>>> &Base) {
>>>>>> -auto *BaseDecl = Base.getType()->getAsCXXRecordDecl();
>>>>>> -assert(BaseDecl);
>>>>>> -return Parent.getCanonicalDecl() == BaseDecl->getCanonicalDecl();
>>>>>> -  });
>>>>>> +  const auto ClassIter = std::find_if(
>>>>>>
>>>>>
>>>>> So what was wrong with llvm::find_if? Why didn't it work here?
>>>>>
>>>>>
>>>>>> +  ThisClass.bases().begin(), ThisClass.bases().end(),
>>>>>> +  [=](const CXXBaseSpecifier &Base) {
>>>>>> +auto *BaseDecl = Base.getType()->getAsCXXRecordDecl();
>>>>>> +assert(BaseDecl);
>>>>>> +return Parent.getCanonicalDecl() ==
>>>>>> BaseDecl->getCanonicalDecl();
>>>>>> +  });
>>>>>>return ClassIter != ThisClass.bases_end();
>>>>>>  }
>>>>>>
>>>>>> @@ -74,7 +76,8 @@ static std::string getNameAsString(const
>>>>>>  static std::string getExprAsString(const clang::Expr &E,
>>>>>> clang::ASTContext &AC) {
>>>>>>std::string Text = tooling::fixit::getText(E, AC).str();
>>>>>> -  Text.erase(llvm::remove_if(Text, std::isspace), Text.end());
>>>>>> +  Text.erase(std::remove_if(Text.begin(), Text.end(), std::isspace),
>>>>>> + Text.end());
>>>>>>return Text;
>>>>>>  }
>>>>>>
>>>>>>
>>>>>>
>>>>>> ___
>>>>>> cfe-commits mailing list
>>>>>> cfe-commits@lists.llvm.org
>>>>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>>>>>
>>>>>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r329730 - [clang-tidy] [modernize-use-auto] Add a threshold for minimal type name length to be replaced with 'auto'

2018-04-10 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Tue Apr 10 11:05:24 2018
New Revision: 329730

URL: http://llvm.org/viewvc/llvm-project?rev=329730&view=rev
Log:
[clang-tidy] [modernize-use-auto] Add a threshold for minimal type name length 
to be replaced with 'auto'

The threshold option is 'MinTypeNameLength' with default value '5'. 
With MinTypeNameLength == 5 'int'/'bool' and 'const int'/'const bool' 
will not be converted to 'auto', while 'unsigned' will be. 

Differential Revision: https://reviews.llvm.org/D45405

Added:

clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-min-type-name-length.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.h
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-auto.rst

clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-cast.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-new.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp?rev=329730&r1=329729&r2=329730&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp Tue Apr 10 
11:05:24 2018
@@ -11,6 +11,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/FixIt.h"
 
 using namespace clang;
 using namespace clang::ast_matchers;
@@ -286,10 +287,11 @@ StatementMatcher makeCombinedMatcher() {
 } // namespace
 
 UseAutoCheck::UseAutoCheck(StringRef Name, ClangTidyContext *Context)
-: ClangTidyCheck(Name, Context),
-  RemoveStars(Options.get("RemoveStars", 0)) {}
+: ClangTidyCheck(Name, Context), RemoveStars(Options.get("RemoveStars", 
0)),
+  MinTypeNameLength(Options.get("MinTypeNameLength", 5)) {}
 
 void UseAutoCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "MinTypeNameLength", MinTypeNameLength);
   Options.store(Opts, "RemoveStars", RemoveStars ? 1 : 0);
 }
 
@@ -414,6 +416,12 @@ void UseAutoCheck::replaceExpr(
 Loc = Loc.getNextTypeLoc();
   }
   SourceRange Range(Loc.getSourceRange());
+
+  if (MinTypeNameLength != 0 &&
+  tooling::fixit::getText(Loc.getSourceRange(), FirstDecl->getASTContext())
+  .size() < MinTypeNameLength)
+return;
+
   auto Diag = diag(Range.getBegin(), Message);
 
   // Space after 'auto' to handle cases where the '*' in the pointer type is

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.h?rev=329730&r1=329729&r2=329730&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.h Tue Apr 10 
11:05:24 2018
@@ -29,6 +29,7 @@ private:
llvm::function_ref GetType,
StringRef Message);
 
+  const unsigned int MinTypeNameLength;
   const bool RemoveStars;
 };
 

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=329730&r1=329729&r2=329730&view=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Tue Apr 10 11:05:24 2018
@@ -57,6 +57,11 @@ The improvements are...
 Improvements to clang-tidy
 --
 
+- New option `MinTypeNameLength` for `modernize-use-auto` to limit the minimal
+  length of type names to be replaced with 'auto'. Use to skip replacing
+  short type names like 'int'/'bool' -> 'auto'. Default value is 5 which means
+  replace types with the name length >= 5 letters only (ex. double, unsigned).
+
 - New module `abseil` for checks related to the `Abseil `_
   library.
 

Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-auto.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-auto.rst?rev=329730&r1=329729&r2=329730&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-auto.rst 
(original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-auto.rst Tue 
Apr 10 11:05:24 2018
@@ -194,3 +194,23 @@ Options
   // RemoveStars = 1
 
   auto my_first_pointer = new TypeName, my_second_pointe

[clang-tools-extra] r329740 - [clang-tidy] [modernize-use-auto] Fix members initialization order

2018-04-10 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Tue Apr 10 11:56:29 2018
New Revision: 329740

URL: http://llvm.org/viewvc/llvm-project?rev=329740&view=rev
Log:
[clang-tidy] [modernize-use-auto] Fix members initialization order


Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp?rev=329740&r1=329739&r2=329740&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp Tue Apr 10 
11:56:29 2018
@@ -287,8 +287,9 @@ StatementMatcher makeCombinedMatcher() {
 } // namespace
 
 UseAutoCheck::UseAutoCheck(StringRef Name, ClangTidyContext *Context)
-: ClangTidyCheck(Name, Context), RemoveStars(Options.get("RemoveStars", 
0)),
-  MinTypeNameLength(Options.get("MinTypeNameLength", 5)) {}
+: ClangTidyCheck(Name, Context),
+  MinTypeNameLength(Options.get("MinTypeNameLength", 5)),
+  RemoveStars(Options.get("RemoveStars", 0)) {}
 
 void UseAutoCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "MinTypeNameLength", MinTypeNameLength);


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D45405: [clang-tidy] [modernize-use-auto] Add a threshold for minimal type name length to be replaced with 'auto'

2018-04-10 Thread Zinovy Nis via cfe-commits
Roman, I see you've fixed them. Thanks a lot!
I did not face with these errors on MSVS'201 so  had no chance to fix early.


ср, 11 апр. 2018 г. в 0:02, Roman Lebedev via Phabricator <
revi...@reviews.llvm.org>:

> lebedev.ri added a comment.
>
> This change had two different problems.
> Please watch the bots?
>
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D45405
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 19d7a0b - [clang-tidy] [bugprone-assert-side-effect] Ignore list for functions/methods

2022-01-25 Thread Zinovy Nis via cfe-commits

Author: Zinovy Nis
Date: 2022-01-25T21:04:07+03:00
New Revision: 19d7a0b47b6849923576845f87a3278e012e049b

URL: 
https://github.com/llvm/llvm-project/commit/19d7a0b47b6849923576845f87a3278e012e049b
DIFF: 
https://github.com/llvm/llvm-project/commit/19d7a0b47b6849923576845f87a3278e012e049b.diff

LOG: [clang-tidy] [bugprone-assert-side-effect] Ignore list for 
functions/methods

A semicolon-separated list of the names of functions or methods to be 
considered as not having side-effects was added for 
bugprone-assert-side-effect. It can be used to exclude methods like 
iterator::begin/end from being considered as having side-effects.

Differential Revision: https://reviews.llvm.org/D116478

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/bugprone-assert-side-effect.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
index 4e2359ff4f67b..eba6b29f56af9 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
@@ -7,6 +7,8 @@
 
//===--===//
 
 #include "AssertSideEffectCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Frontend/CompilerInstance.h"
@@ -25,7 +27,9 @@ namespace bugprone {
 
 namespace {
 
-AST_MATCHER_P(Expr, hasSideEffect, bool, CheckFunctionCalls) {
+AST_MATCHER_P2(Expr, hasSideEffect, bool, CheckFunctionCalls,
+   clang::ast_matchers::internal::Matcher,
+   IgnoredFunctionsMatcher) {
   const Expr *E = &Node;
 
   if (const auto *Op = dyn_cast(E)) {
@@ -55,7 +59,8 @@ AST_MATCHER_P(Expr, hasSideEffect, bool, CheckFunctionCalls) {
 bool Result = CheckFunctionCalls;
 if (const auto *FuncDecl = CExpr->getDirectCallee()) {
   if (FuncDecl->getDeclName().isIdentifier() &&
-  FuncDecl->getName() == "__builtin_expect") // exceptions come here
+  IgnoredFunctionsMatcher.matches(*FuncDecl, Finder,
+  Builder)) // exceptions come here
 Result = false;
   else if (const auto *MethodDecl = dyn_cast(FuncDecl))
 Result &= !MethodDecl->isConst();
@@ -72,8 +77,9 @@ AssertSideEffectCheck::AssertSideEffectCheck(StringRef Name,
  ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
   CheckFunctionCalls(Options.get("CheckFunctionCalls", false)),
-  RawAssertList(Options.get("AssertMacros",
-"assert,NSAssert,NSCAssert")) {
+  RawAssertList(Options.get("AssertMacros", "assert,NSAssert,NSCAssert")),
+  IgnoredFunctions(utils::options::parseStringList(
+  "__builtin_expect;" + Options.get("IgnoredFunctions", ""))) {
   StringRef(RawAssertList).split(AssertMacros, ",", -1, false);
 }
 
@@ -81,11 +87,17 @@ AssertSideEffectCheck::AssertSideEffectCheck(StringRef Name,
 void AssertSideEffectCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "CheckFunctionCalls", CheckFunctionCalls);
   Options.store(Opts, "AssertMacros", RawAssertList);
+  Options.store(Opts, "IgnoredFunctions",
+utils::options::serializeStringList(IgnoredFunctions));
 }
 
 void AssertSideEffectCheck::registerMatchers(MatchFinder *Finder) {
+  auto IgnoredFunctionsMatcher =
+  matchers::matchesAnyListedName(IgnoredFunctions);
+
   auto DescendantWithSideEffect =
-  traverse(TK_AsIs, 
hasDescendant(expr(hasSideEffect(CheckFunctionCalls;
+  traverse(TK_AsIs, hasDescendant(expr(hasSideEffect(
+CheckFunctionCalls, IgnoredFunctionsMatcher;
   auto ConditionWithSideEffect = hasCondition(DescendantWithSideEffect);
   Finder->addMatcher(
   stmt(

diff  --git a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.h
index 15d1a69cb8cd0..c240f362e71e6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.h
@@ -42,6 +42,7 @@ class AssertSideEffectCheck : public ClangTidyCheck {
   const bool CheckFunctionCalls;
   const std::string RawAssertList;
   SmallVector AssertMacros;
+  const std::vector IgnoredFunctions;
 };
 
 } // namespace bugprone

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index cb622f9b