[clang-tools-extra] r339427 - [clang-tidy] run-clang-tidy.py - add synchronisation to the output

2018-08-10 Thread Andi-Bogdan Postelnicu via cfe-commits
Author: abpostelnicu
Date: Fri Aug 10 04:50:47 2018
New Revision: 339427

URL: http://llvm.org/viewvc/llvm-project?rev=339427&view=rev
Log:
[clang-tidy]  run-clang-tidy.py - add synchronisation to the output
Differential Revision: https://reviews.llvm.org/D49851

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

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=339427&r1=339426&r2=339427&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 Fri Aug 10 
04:50:47 2018
@@ -153,7 +153,7 @@ def apply_fixes(args, tmpdir):
   subprocess.call(invocation)
 
 
-def run_tidy(args, tmpdir, build_path, queue, failed_files):
+def run_tidy(args, tmpdir, build_path, queue, lock, failed_files):
   """Takes filenames out of queue and runs clang-tidy on them."""
   while True:
 name = queue.get()
@@ -161,10 +161,15 @@ def run_tidy(args, tmpdir, build_path, q
  tmpdir, build_path, args.header_filter,
  args.extra_arg, args.extra_arg_before,
  args.quiet, args.config)
-sys.stdout.write(' '.join(invocation) + '\n')
-return_code = subprocess.call(invocation)
-if return_code != 0:
+
+proc = subprocess.Popen(invocation, stdout=subprocess.PIPE, 
stderr=subprocess.PIPE)
+output, err = proc.communicate()
+if proc.returncode != 0:
   failed_files.append(name)
+with lock:
+  sys.stdout.write(' '.join(invocation) + '\n' + output + '\n')
+  if err > 0:
+sys.stderr.write(err + '\n')
 queue.task_done()
 
 
@@ -263,9 +268,10 @@ def main():
 task_queue = queue.Queue(max_task)
 # List of files with a non-zero return code.
 failed_files = []
+lock = threading.Lock()
 for _ in range(max_task):
   t = threading.Thread(target=run_tidy,
-   args=(args, tmpdir, build_path, task_queue, 
failed_files))
+   args=(args, tmpdir, build_path, task_queue, lock, 
failed_files))
   t.daemon = True
   t.start()
 


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


[clang-tools-extra] r357994 - ClangTidy: Avoid mixing stdout with stderror when dealing with a large number of files.

2019-04-09 Thread Andi-Bogdan Postelnicu via cfe-commits
Author: abpostelnicu
Date: Tue Apr  9 04:17:02 2019
New Revision: 357994

URL: http://llvm.org/viewvc/llvm-project?rev=357994&view=rev
Log:
ClangTidy: Avoid mixing stdout with stderror when dealing with a large number 
of files.

Summary:
At Mozilla we are using this tool in order to perform review-time 
static-analysis, since some patches contain a large number of files we've 
discovered this issue, where `stderr` gets mixed with `stdout` thus obfuscating 
our possibility to parse the output.
The patch that we are currently use can be found 
[here](https://searchfox.org/mozilla-central/source/build/build-clang/clang-tidy-8.patch).

This is just an upstream of the original patch.

Reviewers: JonasToth

Reviewed By: JonasToth

Subscribers: cfe-commits

Tags: #clang, #clang-tools-extra

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

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

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=357994&r1=357993&r2=357994&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 Tue Apr  9 
04:17:02 2019
@@ -172,6 +172,7 @@ def run_tidy(args, tmpdir, build_path, q
 with lock:
   sys.stdout.write(' '.join(invocation) + '\n' + output.decode('utf-8') + 
'\n')
   if len(err) > 0:
+sys.stdout.flush()
 sys.stderr.write(err.decode('utf-8') + '\n')
 queue.task_done()
 


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


[clang-tools-extra] r342540 - [clang-tidy] run-clang-tidy.py - fails using python 3.7

2018-09-19 Thread Andi-Bogdan Postelnicu via cfe-commits
Author: abpostelnicu
Date: Wed Sep 19 04:52:20 2018
New Revision: 342540

URL: http://llvm.org/viewvc/llvm-project?rev=342540&view=rev
Log:
[clang-tidy] run-clang-tidy.py - fails using python 3.7
Differential Revision: https://reviews.llvm.org/D51220

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

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=342540&r1=342539&r2=342540&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 Sep 19 
04:52:20 2018
@@ -167,9 +167,9 @@ def run_tidy(args, tmpdir, build_path, q
 if proc.returncode != 0:
   failed_files.append(name)
 with lock:
-  sys.stdout.write(' '.join(invocation) + '\n' + output + '\n')
-  if err > 0:
-sys.stderr.write(err + '\n')
+  sys.stdout.write(' '.join(invocation) + '\n' + output.decode('utf-8') + 
'\n')
+  if len(err) > 0:
+sys.stderr.write(err.decode('utf-8') + '\n')
 queue.task_done()
 
 


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


[clang-tools-extra] 068fa35 - [clang-tidy] For `run-clang-tidy.py` escape the paths that are used for analysis.

2020-06-16 Thread Andi-Bogdan Postelnicu via cfe-commits

Author: Andi-Bogdan Postelnicu
Date: 2020-06-16T12:21:18+03:00
New Revision: 068fa35746637fde29355a43d17d554a92b32cdf

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

LOG: [clang-tidy] For `run-clang-tidy.py` escape the paths that are used for 
analysis.
Some paths can have special chars like `file++c.cpp` in this case the regex will
fail if we don't escape it.

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py 
b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
index 4272ae0957fe..2b5e78b38f01 100755
--- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -277,6 +277,7 @@ def main():
 tmpdir = tempfile.mkdtemp()
 
   # Build up a big regexy filter from all command line arguments.
+  args.files = [re.escape(f) for f in args.files]
   file_name_re = re.compile('|'.join(args.files))
 
   return_code = 0



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


[clang-tools-extra] bbb7921 - [clang-tidy] Add option to use alpha checkers from clang-analyzer when using `run-clang-tidy.py`

2020-04-23 Thread Andi-Bogdan Postelnicu via cfe-commits

Author: Andi-Bogdan Postelnicu
Date: 2020-04-23T11:36:50+03:00
New Revision: bbb7921da97ce03d2933e185a525c4e452b146b0

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

LOG: [clang-tidy] Add option to use alpha checkers from clang-analyzer when 
using `run-clang-tidy.py`

Summary: Add option to use alpha checkers from clang-analyzer when using 
`run-clang-tidy.py`.

Reviewers: JonasToth

Subscribers: xazax.hun, baloghadamsoftware, a.sidorin, Szelethus, donat.nagy, 
dkrupp, Charusso, ASDenysPetrov, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py 
b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
index 1eb135295754..1c4f3ad59ac8 100755
--- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -78,10 +78,12 @@ def make_absolute(f, directory):
 
 
 def get_tidy_invocation(f, clang_tidy_binary, checks, tmpdir, build_path,
-header_filter, extra_arg, extra_arg_before, quiet,
-config):
+header_filter, allow_enabling_alpha_checkers,
+extra_arg, extra_arg_before, quiet, config):
   """Gets a command line for clang-tidy."""
   start = [clang_tidy_binary]
+  if allow_enabling_alpha_checkers is not None:
+start.append('-allow-enabling-analyzer-alpha-checkers')
   if header_filter is not None:
 start.append('-header-filter=' + header_filter)
   if checks:
@@ -159,6 +161,7 @@ def run_tidy(args, tmpdir, build_path, queue, lock, 
failed_files):
 name = queue.get()
 invocation = get_tidy_invocation(name, args.clang_tidy_binary, args.checks,
  tmpdir, build_path, args.header_filter,
+ args.allow_enabling_alpha_checkers,
  args.extra_arg, args.extra_arg_before,
  args.quiet, args.config)
 
@@ -179,6 +182,9 @@ def main():
'in a compilation database. Requires '
'clang-tidy and clang-apply-replacements in 
'
'$PATH.')
+  parser.add_argument('-allow-enabling-alpha-checkers',
+  action='store_true', help='allow alpha checkers from '
+'clang-analyzer.')
   parser.add_argument('-clang-tidy-binary', metavar='PATH',
   default='clang-tidy',
   help='path to clang-tidy binary')
@@ -238,6 +244,8 @@ def main():
 
   try:
 invocation = [args.clang_tidy_binary, '-list-checks']
+if args.allow_enabling_alpha_checkers:
+  invocation.append('-allow-enabling-analyzer-alpha-checkers')
 invocation.append('-p=' + build_path)
 if args.checks:
   invocation.append('-checks=' + args.checks)

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index d3c3bb0520d1..011962ea1d05 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -188,6 +188,11 @@ Renamed checks
 - The 'fuchsia-restrict-system-headers' check was renamed to 
:doc:`portability-restrict-system-includes
   `
 
+Other improvements
+^^
+
+- For 'run-clang-tidy.py' add option to use alpha checkers from clang-analyzer.
+
 Improvements to include-fixer
 -
 
@@ -210,4 +215,3 @@ The improvements are...
 
 Clang-tidy visual studio plugin
 ---
-



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


[clang-tools-extra] ba129c7 - [clang-tidy] Disable match on `if constexpr` statements in template instantiation for `readability-misleading-indentation` check.

2020-01-08 Thread Andi-Bogdan Postelnicu via cfe-commits

Author: Andi-Bogdan Postelnicu
Date: 2020-01-08T16:36:13+02:00
New Revision: ba129c7d0f5c7c32398ad708c88e14cb06a339ad

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

LOG: [clang-tidy] Disable match on `if constexpr` statements in template 
instantiation for `readability-misleading-indentation` check.

Summary: Fixes fixes `readability-misleading-identation` for `if constexpr`. 
This is very similar to D71980.

Reviewers: alexfh

Subscribers: xazax.hun, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
index 0fd5c1fc55c6..3167d159b74f 100644
--- a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
@@ -106,7 +106,11 @@ void MisleadingIndentationCheck::missingBracesCheck(const 
SourceManager &SM,
 }
 
 void MisleadingIndentationCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(ifStmt(hasElse(stmt())).bind("if"), this);
+  Finder->addMatcher(
+  ifStmt(allOf(hasElse(stmt()),
+   unless(allOf(isConstexpr(), isInTemplateInstantiation()
+  .bind("if"),
+  this);
   Finder->addMatcher(
   compoundStmt(has(stmt(anyOf(ifStmt(), forStmt(), whileStmt()
   .bind("compound"),

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
index 403994923549..7ceb0cb42cfe 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
@@ -2,6 +2,7 @@
 
 void foo1();
 void foo2();
+void foo3();
 
 #define BLOCK \
   if (cond1)  \
@@ -118,3 +119,79 @@ void g(bool x) {
   #pragma unroll
   for (int k = 0; k < 1; ++k) {}
 }
+
+template
+void mustPass() {
+  if constexpr (b) {
+foo1();
+  } else {
+foo2();
+  }
+}
+
+void mustPassNonTemplate() {
+  constexpr unsigned Value = 1;
+  if constexpr (Value == 0) {
+foo1();
+  } else if constexpr (Value == 1) {
+foo2();
+  } else {
+foo3();
+  }
+}
+
+template
+void mustFail() {
+  if constexpr (b) {
+foo1();
+  }
+else {
+  foo2();
+  // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: 
diff erent indentation for 'if' and corresponding 'else' 
[readability-misleading-indentation]
+  }
+}
+
+void mustFailNonTemplate() {
+  constexpr unsigned Value = 1;
+  if constexpr (Value == 0) {
+foo1();
+  }
+else {
+  foo2();
+  // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: 
diff erent indentation for 'if' and corresponding 'else' 
[readability-misleading-indentation]
+  }
+
+  if constexpr (Value == 0)
+foo1();
+else
+  foo2();
+  // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: 
diff erent indentation for 'if' and corresponding 'else' 
[readability-misleading-indentation]
+}
+
+template
+void mustFailNoInsta() {
+  if constexpr (b) {
+foo1();
+  }
+else {
+  foo2();
+  // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: 
diff erent indentation for 'if' and corresponding 'else' 
[readability-misleading-indentation]
+  }
+}
+
+template
+void mustPassNoInsta() {
+  if constexpr (b) {
+foo1();
+  }
+  else {
+foo2();
+  }
+}
+
+void call() {
+  mustPass();
+  mustPass();
+  mustFail();
+  mustFail();
+}



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


[clang-tools-extra] 0a01ec9 - [clang-tidy] Remove broken test on Windows for `readability-misleading-indentation`.

2020-01-08 Thread Andi-Bogdan Postelnicu via cfe-commits

Author: Andi-Bogdan Postelnicu
Date: 2020-01-08T20:37:23+02:00
New Revision: 0a01ec972d2e24c721f46e55210d42391ae52b70

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

LOG: [clang-tidy] Remove broken test on Windows for 
`readability-misleading-indentation`.
Because Windows build uses by default `fdelayed-template-parsing` we cannot 
have a test
where we don't instantiate the template. Please see D72333.

Added: 


Modified: 

clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp

Removed: 




diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
index 7ceb0cb42cfe..c3bd33d8ee7b 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
@@ -168,17 +168,6 @@ void mustFailNonTemplate() {
   // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: 
diff erent indentation for 'if' and corresponding 'else' 
[readability-misleading-indentation]
 }
 
-template
-void mustFailNoInsta() {
-  if constexpr (b) {
-foo1();
-  }
-else {
-  foo2();
-  // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: 
diff erent indentation for 'if' and corresponding 'else' 
[readability-misleading-indentation]
-  }
-}
-
 template
 void mustPassNoInsta() {
   if constexpr (b) {



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


[clang-tools-extra] 795c38e - [clang-tidy] For checker `readability-misleading-indentation` update tests.

2020-01-09 Thread Andi-Bogdan Postelnicu via cfe-commits

Author: Andi-Bogdan Postelnicu
Date: 2020-01-09T13:52:26+02:00
New Revision: 795c38eb4df636d434a9821efecbfeb41ecba843

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

LOG: [clang-tidy] For checker `readability-misleading-indentation` update tests.

Summary: In D72333 we've introduced support for `if constexpr` but the test for 
uninstantiated template was not ready to land on windows platform since this 
target uses `-fdelayed-template-parsing` by default. This patch addresses this 
by passing `-fno-delayed-template-parsing` to the test.

Reviewers: JonasToth

Subscribers: xazax.hun, cfe-commits

Tags: #clang

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

Added: 


Modified: 

clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp

Removed: 




diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
index c3bd33d8ee7b..aea0618d120d 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability-misleading-indentation.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s readability-misleading-indentation %t
+// RUN: %check_clang_tidy %s readability-misleading-indentation %t -- -- 
-fno-delayed-template-parsing
 
 void foo1();
 void foo2();
@@ -168,6 +168,17 @@ void mustFailNonTemplate() {
   // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: 
diff erent indentation for 'if' and corresponding 'else' 
[readability-misleading-indentation]
 }
 
+template
+void mustFailNoInsta() {
+  if constexpr (b) {
+foo1();
+  }
+else {
+  foo2();
+  // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: 
diff erent indentation for 'if' and corresponding 'else' 
[readability-misleading-indentation]
+  }
+}
+
 template
 void mustPassNoInsta() {
   if constexpr (b) {



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


r297148 - [clang-format] Followup of D30646 - unbreak the build

2017-03-07 Thread Andi-Bogdan Postelnicu via cfe-commits
Author: abpostelnicu
Date: Tue Mar  7 09:20:31 2017
New Revision: 297148

URL: http://llvm.org/viewvc/llvm-project?rev=297148&view=rev
Log:
[clang-format] Followup of D30646 - unbreak the build

Modified:
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=297148&r1=297147&r2=297148&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Mar  7 09:20:31 2017
@@ -5326,8 +5326,8 @@ TEST_F(FormatTest, BreaksLongDeclaration
"aaa>>\n"
"aa);");
 
-  verifyFormat("template // Templates on own line.\n"
-   "static int   // Some comment.\n"
+  verifyFormat("template  // Templates on own line.\n"
+   "static int// Some comment.\n"
"MyFunction(int a);",
getLLVMStyle());
 }


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


r297143 - [clang-format] Fixed indent issue when adding a comment at the end of a return type in named function declaration.

2017-03-07 Thread Andi-Bogdan Postelnicu via cfe-commits
Author: abpostelnicu
Date: Tue Mar  7 08:48:02 2017
New Revision: 297143

URL: http://llvm.org/viewvc/llvm-project?rev=297143&view=rev
Log:
[clang-format] Fixed indent issue when adding a comment at the end of a return 
type in named function declaration.

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

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=297143&r1=297142&r2=297143&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Mar  7 08:48:02 2017
@@ -1166,9 +1166,9 @@ private:
   return false;
 
 // Skip "const" as it does not have an influence on whether this is a name.
-FormatToken *PreviousNotConst = Tok.Previous;
+FormatToken *PreviousNotConst = Tok.getPreviousNonComment();
 while (PreviousNotConst && PreviousNotConst->is(tok::kw_const))
-  PreviousNotConst = PreviousNotConst->Previous;
+  PreviousNotConst = PreviousNotConst->getPreviousNonComment();
 
 if (!PreviousNotConst)
   return false;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=297143&r1=297142&r2=297143&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Mar  7 08:48:02 2017
@@ -5325,6 +5325,11 @@ TEST_F(FormatTest, BreaksLongDeclaration
"vector>\n"
"aa);");
+
+  verifyFormat("template // Templates on own line.\n"
+   "static int   // Some comment.\n"
+   "MyFunction(int a);",
+   getLLVMStyle());
 }
 
 TEST_F(FormatTest, FormatsArrays) {


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


r297467 - [clang-format] Add option to break before inheritance separation operator in class declaration.

2017-03-10 Thread Andi-Bogdan Postelnicu via cfe-commits
Author: abpostelnicu
Date: Fri Mar 10 09:10:37 2017
New Revision: 297467

URL: http://llvm.org/viewvc/llvm-project?rev=297467&view=rev
Log:
[clang-format] Add option to break before inheritance separation operator in 
class declaration.

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

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/FormatToken.h
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=297467&r1=297466&r2=297467&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Fri Mar 10 09:10:37 2017
@@ -528,6 +528,10 @@ the configuration (without a prefix: ``A
 
 
 
+**BreakBeforeInheritanceComma** (``bool``)
+  If ``true``, in the class inheritance expression clang-format will
+  break before ``:`` and ``,`` if there is multiple inheritance.
+
 **BreakBeforeTernaryOperators** (``bool``)
   If ``true``, ternary operators will be placed after line breaks.
 

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=297467&r1=297466&r2=297467&view=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Fri Mar 10 09:10:37 2017
@@ -422,6 +422,10 @@ struct FormatStyle {
   /// which should not be split into lines or otherwise changed.
   std::string CommentPragmas;
 
+  /// \brief If ``true``, in the class inheritance expression clang-format will
+  /// break before ``:`` and ``,`` if there is multiple inheritance.
+  bool BreakBeforeInheritanceComma;
+
   /// \brief If the constructor initializers don't fit on a line, put each
   /// initializer on its own line.
   bool ConstructorInitializerAllOnOneLineOrOnePerLine;
@@ -844,6 +848,7 @@ struct FormatStyle {
BreakAfterJavaFieldAnnotations == R.BreakAfterJavaFieldAnnotations 
&&
BreakStringLiterals == R.BreakStringLiterals &&
ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas 
&&
+   BreakBeforeInheritanceComma == R.BreakBeforeInheritanceComma &&
ConstructorInitializerAllOnOneLineOrOnePerLine ==
R.ConstructorInitializerAllOnOneLineOrOnePerLine &&
ConstructorInitializerIndentWidth ==

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=297467&r1=297466&r2=297467&view=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Fri Mar 10 09:10:37 2017
@@ -57,8 +57,10 @@ static bool startsNextParameter(const Fo
   Style.BreakConstructorInitializersBeforeComma)
 return true;
   return Previous.is(tok::comma) && !Current.isTrailingComment() &&
- (Previous.isNot(TT_CtorInitializerComma) ||
-  !Style.BreakConstructorInitializersBeforeComma);
+ ((Previous.isNot(TT_CtorInitializerComma) ||
+  !Style.BreakConstructorInitializersBeforeComma) &&
+  (Previous.isNot(TT_InheritanceComma) ||
+  !Style.BreakBeforeInheritanceComma));
 }
 
 ContinuationIndenter::ContinuationIndenter(const FormatStyle &Style,
@@ -350,6 +352,11 @@ void ContinuationIndenter::addTokenOnCur
 Whitespaces.replaceWhitespace(Current, /*Newlines=*/0, Spaces,
   State.Column + Spaces);
 
+  // If "BreakBeforeInheritanceComma" mode, don't break within the inheritance
+  // declaration unless there is multiple inheritance.
+  if (Style.BreakBeforeInheritanceComma && Current.is(TT_InheritanceColon))
+State.Stack.back().NoLineBreak = true;
+
   if (Current.is(TT_SelectorName) &&
   !State.Stack.back().ObjCSelectorNameFound) {
 unsigned MinIndent =
@@ -737,10 +744,11 @@ unsigned ContinuationIndenter::getNewLin
   if (PreviousNonComment && PreviousNonComment->is(tok::colon) &&
   PreviousNonComment->isOneOf(TT_ObjCMethodExpr, TT_DictLiteral))
 return ContinuationIndent;
-  if (NextNonComment->is(TT_CtorInitializerColon))
-return State.FirstIndent + Style.ConstructorInitializerIndentWidth;
   if (NextNonComment->is(TT_CtorInitializerComma))
 return State.Stack.back().Indent;
+  if (NextNonComment->isOneOf(TT_CtorInitializerColon, TT_InheritanceColon,
+  TT_InheritanceComma))
+return State.FirstIndent + Style.ConstructorInitializerIndentWidth;
   if (Previ

r285178 - Bug 28065 - clang-format incorrectly aligns backslash.

2016-10-26 Thread Andi-Bogdan Postelnicu via cfe-commits
Author: abpostelnicu
Date: Wed Oct 26 02:44:51 2016
New Revision: 285178

URL: http://llvm.org/viewvc/llvm-project?rev=285178&view=rev
Log:
Bug 28065 - clang-format incorrectly aligns backslash.

Modified:
cfe/trunk/lib/Format/WhitespaceManager.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/WhitespaceManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/WhitespaceManager.cpp?rev=285178&r1=285177&r2=285178&view=diff
==
--- cfe/trunk/lib/Format/WhitespaceManager.cpp (original)
+++ cfe/trunk/lib/Format/WhitespaceManager.cpp Wed Oct 26 02:44:51 2016
@@ -432,7 +432,7 @@ void WhitespaceManager::alignTrailingCom
 }
 assert(Shift >= 0);
 Changes[i].Spaces += Shift;
-if (i + 1 != End)
+if (i + 1 != Changes.size())
   Changes[i + 1].PreviousEndOfTokenColumn += Shift;
 Changes[i].StartOfTokenColumn += Shift;
   }

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=285178&r1=285177&r2=285178&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Oct 26 02:44:51 2016
@@ -11597,6 +11597,17 @@ TEST_F(ReplacementTest, SortIncludesAfte
   EXPECT_EQ(Expected, *Result);
 }
 
+TEST_F(FormatTest, AllignTrailingComments) {
+  EXPECT_EQ("#define MACRO(V)   \\\n"
+"  V(Rt2) /* one more char */   \\\n"
+"  V(Rs)  /* than here  */  \\\n"
+"/* comment 3 */\n",
+format("#define MACRO(V)\\\n"
+   "V(Rt2)  /* one more char */ \\\n"
+   "V(Rs) /* than here  */\\\n"
+   "/* comment 3 */ \\\n",
+   getLLVMStyleWithColumns(40)));
+}
 } // end namespace
 } // end namespace format
 } // end namespace clang


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


D22910 Add support for CXXOperatorCallExpr in Expr::HasSideEffects

2016-07-28 Thread Andi Bogdan Postelnicu via cfe-commits
I’m trying to get reviews for this patch that modifies Expr::HasSideEffects in 
order to have better support for CXXOperatorCallExpr and i don’t know from who 
i can ask review.

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