Re: Fwd: patch file for bug 38557

2018-08-14 Thread Jonas Toth via cfe-commits
Do you have a phabricator account? Otherwise I will create a revision
for you (ofc mentioning your name in the commit message) for review.


Am 14.08.2018 um 12:30 schrieb Owen Pan via cfe-commits:
> Hi,
>
> Attached is the patch file for Bug 38557
> (https://bugs.llvm.org/show_bug.cgi?id=38557).
>
> Thanks,
> Owen
>
>
> ___
> 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: Fwd: patch file for bug 38557

2018-08-14 Thread Jonas Toth via cfe-commits
Hi Owen,

thank you for your patch. I created a revision for it to pass review:
https://reviews.llvm.org/D50697

If you do have an phabricator account you can take over, otherwise we
can get it into trunk for you :)

All the best, Jonas


Am 14.08.2018 um 12:30 schrieb Owen Pan via cfe-commits:
> Hi,
>
> Attached is the patch file for Bug 38557
> (https://bugs.llvm.org/show_bug.cgi?id=38557).
>
> Thanks,
> Owen
>
>
> ___
> 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] r314808 - [clang-tidy] Fix bug 34747, streaming operators and hicpp-signed-bitwise

2017-10-03 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Oct  3 09:25:01 2017
New Revision: 314808

URL: http://llvm.org/viewvc/llvm-project?rev=314808&view=rev
Log:
[clang-tidy] Fix bug 34747, streaming operators and hicpp-signed-bitwise

The bug happened with stream operations, that were not recognized in all cases.
Even there were already existing test for streaming classes, they did not catch 
this bug.
Adding the isolated example to the existing tests did not trigger the bug.
Therefore i created a new isolated file that did expose the bug indeed.

Differential: https://reviews.llvm.org/D38399
reviewed by aaron.ballman

Added:
clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp?rev=314808&r1=314807&r2=314808&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp Tue Oct  3 
09:25:01 2017
@@ -27,7 +27,9 @@ void SignedBitwiseCheck::registerMatcher
   binaryOperator(allOf(anyOf(hasOperatorName("|"), hasOperatorName("&"),
  hasOperatorName("^"), hasOperatorName("<<"),
  hasOperatorName(">>")),
-   hasEitherOperand(SignedIntegerOperand)))
+   hasEitherOperand(SignedIntegerOperand),
+   hasLHS(hasType(isInteger())),
+   hasRHS(hasType(isInteger()
   .bind("binary_signed"),
   this);
 

Added: clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp?rev=314808&view=auto
==
--- clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp 
(added)
+++ clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp 
Tue Oct  3 09:25:01 2017
@@ -0,0 +1,21 @@
+// RUN: %check_clang_tidy %s hicpp-signed-bitwise %t -- -- -std=c++11 | count 0
+
+// Note: this test expects no diagnostics, but FileCheck cannot handle that,
+// hence the use of | count 0.
+
+template 
+struct OutputStream {
+  OutputStream &operator<<(C);
+};
+
+template 
+struct foo {
+  typedef OutputStream stream_type;
+  foo(stream_type &o) {
+o << 'x'; // warning occured here, fixed now
+  }
+};
+
+void bar(OutputStream &o) {
+  foo f(o);
+}


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


[clang-tools-extra] r314811 - [clang-tidy] Remove target specification hicpp-signed-bitwise

2017-10-03 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Oct  3 09:27:41 2017
New Revision: 314811

URL: http://llvm.org/viewvc/llvm-project?rev=314811&view=rev
Log:
[clang-tidy] Remove target specification hicpp-signed-bitwise

This patch removes the targetspecification of a testcase, that broke
for ARM. The underlying problem was fixed which makes it unnecessary to
specify the target architecture (problem was the signedness of `char`).

Committing without review was accepted in https://reviews.llvm.org/D38399
by aaron.ballman.

Modified:
clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise.cpp

Modified: clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise.cpp?rev=314811&r1=314810&r2=314811&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise.cpp Tue Oct  3 
09:27:41 2017
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s hicpp-signed-bitwise %t -- -- -std=c++11 -target 
x86_64-unknown-unknown
+// RUN: %check_clang_tidy %s hicpp-signed-bitwise %t -- -- -std=c++11 
 
 // These could cause false positives and should not be considered.
 struct StreamClass {


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


[clang-tools-extra] r314812 - [clang-tidy] potentially fix buildbot

2017-10-03 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Oct  3 09:53:56 2017
New Revision: 314812

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

I tried to silence lit with `| count 0`, which did not work.
Other testcases did not have `-- --` but only `--` in the RUN line.
Maybe this fixes the problem.

Modified:
clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp?rev=314812&r1=314811&r2=314812&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp 
Tue Oct  3 09:53:56 2017
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s hicpp-signed-bitwise %t -- -- -std=c++11 | count 0
+// RUN: %check_clang_tidy %s hicpp-signed-bitwise %t -- | count 0
 
 // Note: this test expects no diagnostics, but FileCheck cannot handle that,
 // hence the use of | count 0.


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


[clang-tools-extra] r314816 - [clang-tidy] fix buildbot hicpp-signed-bitwise

2017-10-03 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Oct  3 10:08:57 2017
New Revision: 314816

URL: http://llvm.org/viewvc/llvm-project?rev=314816&view=rev
Log:
[clang-tidy] fix buildbot hicpp-signed-bitwise

To finally fix the buildbot I added one single warning testcase.

Modified:
clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp?rev=314816&r1=314815&r2=314816&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp 
Tue Oct  3 10:08:57 2017
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s hicpp-signed-bitwise %t -- | count 0
+// RUN: %check_clang_tidy %s hicpp-signed-bitwise %t --
 
 // Note: this test expects no diagnostics, but FileCheck cannot handle that,
 // hence the use of | count 0.
@@ -19,3 +19,11 @@ struct foo {
 void bar(OutputStream &o) {
   foo f(o);
 }
+
+void silence_lit() {
+  int SValue = 42;
+  int SResult;
+
+  SResult = SValue & 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use of a signed integer operand 
with a binary bitwise operator
+}


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


Re: [clang-tools-extra] r314808 - [clang-tidy] Fix bug 34747, streaming operators and hicpp-signed-bitwise

2017-10-03 Thread Jonas Toth via cfe-commits
Hi Juergen,

i did already work on fixing the issue I introduced with the commits. I
am currently waiting for the buildbot to catch up with the committed fix.

As far as i can see, the newer commits did actually fix (at least
chapunis buildbot did go green again), but i have my eye on it.

Cheers, Jonas


Am 03.10.2017 um 19:53 schrieb Juergen Ributzka:
> Hi Jonas,
>
> this new test is failing on Green Dragon:
> http://lab.llvm.org:8080/green/job/clang-stage1-configure-RA/39223/consoleFull#11207350448254eaf0-7326-4999-85b0-388101f2d404
>
> Could you please take a look?
>
> Thanks
>
> Cheers,
> Juergen
>
> On Tue, Oct 3, 2017 at 9:25 AM, Jonas Toth via cfe-commits
> mailto:cfe-commits@lists.llvm.org>> wrote:
>
> Author: jonastoth
> Date: Tue Oct  3 09:25:01 2017
> New Revision: 314808
>
> URL: http://llvm.org/viewvc/llvm-project?rev=314808&view=rev
> <http://llvm.org/viewvc/llvm-project?rev=314808&view=rev>
> Log:
> [clang-tidy] Fix bug 34747, streaming operators and
> hicpp-signed-bitwise
>
> The bug happened with stream operations, that were not recognized
> in all cases.
> Even there were already existing test for streaming classes, they
> did not catch this bug.
> Adding the isolated example to the existing tests did not trigger
> the bug.
> Therefore i created a new isolated file that did expose the bug
> indeed.
>
> Differential: https://reviews.llvm.org/D38399
> <https://reviews.llvm.org/D38399>
> reviewed by aaron.ballman
>
> Added:
>    
> clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp
> Modified:
>     clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp
>
> Modified:
> clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp
> URL:
> 
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp?rev=314808&r1=314807&r2=314808&view=diff
> 
> <http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp?rev=314808&r1=314807&r2=314808&view=diff>
> 
> ==
> ---
> clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp
> (original)
> +++
> clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp
> Tue Oct  3 09:25:01 2017
> @@ -27,7 +27,9 @@ void SignedBitwiseCheck::registerMatcher
>        binaryOperator(allOf(anyOf(hasOperatorName("|"),
> hasOperatorName("&"),
>                                   hasOperatorName("^"),
> hasOperatorName("<<"),
>                                   hasOperatorName(">>")),
> -                           hasEitherOperand(SignedIntegerOperand)))
> +                           hasEitherOperand(SignedIntegerOperand),
> +                           hasLHS(hasType(isInteger())),
> +                           hasRHS(hasType(isInteger()
>            .bind("binary_signed"),
>        this);
>
>
> Added:
> clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp
> URL:
> 
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp?rev=314808&view=auto
> 
> <http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp?rev=314808&view=auto>
> 
> ==
> ---
> clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp
> (added)
> +++
> clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp
> Tue Oct  3 09:25:01 2017
> @@ -0,0 +1,21 @@
> +// RUN: %check_clang_tidy %s hicpp-signed-bitwise %t -- --
> -std=c++11 | count 0
> +
> +// Note: this test expects no diagnostics, but FileCheck cannot
> handle that,
> +// hence the use of | count 0.
> +
> +template 
> +struct OutputStream {
> +  OutputStream &operator<<(C);
> +};
> +
> +template 
> +struct foo {
> +  typedef OutputStream stream_type;
> +  foo(stream_type &o) {
> +    o << 'x'; // warning occured here, fixed now
> +  }
> +};
> +
> +void bar(OutputStream &o) {
> +  foo f(o);
> +}
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org <mailto:cfe-commits@lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
> <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] r314913 - [clang-tidy] Emit note for variable declaration that are later deleted

2017-10-04 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Oct  4 09:49:20 2017
New Revision: 314913

URL: http://llvm.org/viewvc/llvm-project?rev=314913&view=rev
Log:
[clang-tidy] Emit note for variable declaration that are later deleted

This patch introduces a note for variable declaration that are later deleted.
Adds FIXME notes for possible automatic type-rewriting positions as well.

Reviewed by aaron.ballman
Differential: https://reviews.llvm.org/D38411

Modified:
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp?rev=314913&r1=314912&r2=314913&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp 
Wed Oct  4 09:49:20 2017
@@ -156,6 +156,13 @@ bool OwningMemoryCheck::handleDeletion(c
  "not marked 'gsl::owner<>'; consider using a "
  "smart pointer instead")
 << DeletedVariable->getSourceRange();
+
+// FIXME: The declaration of the variable that was deleted can be
+// rewritten.
+const ValueDecl *Decl = DeletedVariable->getDecl();
+diag(Decl->getLocStart(), "variable declared here", DiagnosticIDs::Note)
+<< Decl->getSourceRange();
+
 return true;
   }
   return false;
@@ -244,7 +251,9 @@ bool OwningMemoryCheck::handleAssignment
  "initializing non-owner %0 with a newly created 'gsl::owner<>'")
 << BadOwnerInitialization->getType()
 << BadOwnerInitialization->getSourceRange();
-// FIXME: FixitHint to rewrite the type if possible.
+
+// FIXME: FixitHint to rewrite the type of the initialized variable
+// as 'gsl::owner'
 
 // If the type of the variable was deduced, the wrapping owner typedef is
 // eliminated, therefore the check emits a special note for that case.
@@ -277,14 +286,15 @@ bool OwningMemoryCheck::handleReturnValu
 
   // Function return values, that should be owners but aren't.
   if (BadReturnType) {
-// The returned value is of type owner, but not the declared return type.
+// The returned value is a resource or variable that was not annotated with
+// owner<> and the function return type is not owner<>.
 diag(BadReturnType->getLocStart(),
  "returning a newly created resource of "
  "type %0 or 'gsl::owner<>' from a "
  "function whose return type is not 'gsl::owner<>'")
 << Function->getReturnType() << BadReturnType->getSourceRange();
-// The returned value is a resource that was not annotated with owner<> and
-// the function return type is not owner<>.
+
+// FIXME: Rewrite the return type as 'gsl::owner'
 return true;
   }
   return false;

Modified: 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory.cpp?rev=314913&r1=314912&r2=314913&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory.cpp 
Wed Oct  4 09:49:20 2017
@@ -142,11 +142,13 @@ void test_deletion() {
   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'int *' 
with a newly created 'gsl::owner<>'
   delete unowned_int1; // BAD, since no owner
   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: deleting a pointer through a type 
that is not marked 'gsl::owner<>'; consider using a smart pointer instead
+  // CHECK-MESSAGES: [[@LINE-4]]:3: note: variable declared here
 
   int *unowned_int2 = new int[42]; // BAD, since new creates and owner
   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'int *' 
with a newly created 'gsl::owner<>'
   delete[] unowned_int2; // BAD since no owner
   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: deleting a pointer through a type 
that is not marked 'gsl::owner<>'; consider using a smart pointer instead
+  // CHECK-MESSAGES: [[@LINE-4]]:3: note: variable declared here
 
   delete new int(42);   // Technically ok, but stupid
   delete[] new int[42]; // Technically ok, but stupid


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


Re: [clang-tools-extra] r315060 - Renaming a test to start with the name of the check based on post-commit review feedback; NFC.

2017-10-12 Thread Jonas Toth via cfe-commits

Hi,

I am not sure if could follow correctly, but the test for nested 
namespaces comments does not work correctly and is therefore currently 
disabled by fileextension?


When running the check from trunk i get the following issues:

$ clang-check google-readability-namespace-comments-cxx17.cpp -- -std=c++17
> error: invalid value 'c++17' in '-std=c++17'

In the clang-tidy check '-std=c++17' is used. I don't know if the c++17 
- flag is introduced in clang yet, but maybe this would be one issue.


Running clang-tidy from command line does not produce output (added 
fileextension for now):


$ clang-tidy -checks=-*,google-readability-namespace-comments 
google-readability-namespace-comments-cxx17.cpp -- -std=c++1z
$ clang-tidy -checks=-*,google-readability-namespace-comments 
google-readability-namespace-comments-cxx17.cpp -- -- -std=c++1z
> Error while processing 
/home/jonas/opt/llvm/tools/clang/tools/extra/test/clang-tidy/google-readability-namespace-comments-cxx17.cpp.


Adding a 'std::cout << "Test if run" << std::endl' at the beginning of 
the `check` - Method works and generates output:


$ clang-tidy -checks=-*,google-readability-namespace-comments 
google-readability-namespace-comments-cxx17.cpp -- -std=c++1z

Test if run
Test if run
Test if run

So I think there is a regression in the Testingcode not catching the 
nested namespaces. Did it work before and what could have changed?
If it did work and the clang-tidy code is the same this could be a 
regression somewhere else.


All the Best, Jonas

Am 11.10.2017 um 21:36 schrieb Aaron Ballman:

On Wed, Oct 11, 2017 at 3:29 PM, Alexander Kornienko  wrote:

On Fri, Oct 6, 2017 at 3:27 PM, Aaron Ballman via cfe-commits
 wrote:

Author: aaronballman
Date: Fri Oct  6 06:27:59 2017
New Revision: 315060

URL: http://llvm.org/viewvc/llvm-project?rev=315060&view=rev
Log:
Renaming a test to start with the name of the check based on post-commit
review feedback; NFC.

Added:

clang-tools-extra/trunk/test/clang-tidy/google-readability-namespace-comments-cxx17


Sorry for not being clear. I didn't mean the `.cpp` extension should be
removed. This effectively disables the test, since lit only runs tests in
files with certain extensions (under clang-tools-extra/test these are '.c',
'.cpp', '.hpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s', '.modularize',
'.module-map-checker', '.test').

That's entirely my fault -- I should have recognized that. Sorry for
the trouble!


I've just renamed the file to *.cpp and the test fails for me:

[0/1] Running the Clang extra tools' regression tests
FAIL: Clang Tools ::
clang-tidy/google-readability-namespace-comments-cxx17.cpp (102 of 674)
 TEST 'Clang Tools ::
clang-tidy/google-readability-namespace-comments-cxx17.cpp' FAILED

Script:
--
/usr/bin/python2.7
/src/tools/clang/tools/extra/test/../test/clang-tidy/check_clang_tidy.py
/src/tools/clang/tools/extra/test/clang-tidy/google-readability-namespace-comments-cxx17.cpp
google-readability-namespace-comments
/build/tools/clang/tools/extra/test/clang-tidy/Output/google-readability-namespace-comments-cxx17.cpp.tmp
-- -- -std=c++17
--
Exit Code: 1

Command Output (stdout):
--
Running ['clang-tidy',
'/build/tools/clang/tools/extra/test/clang-tidy/Output/google-readability-namespace-comments-cxx17.cpp.tmp.cpp',
'-fix', '--checks=-*,google-readability-namespace-comments', '--',
'-std=c++17', '-nostdinc++']...
 clang-tidy output ---

--
-- Fixes -

--
FileCheck failed:
/src/tools/clang/tools/extra/test/clang-tidy/google-readability-namespace-comments-cxx17.cpp:13:17:
error: expected string not found in input
// CHECK-FIXES: }  // namespace n3
 ^
/build/tools/clang/tools/extra/test/clang-tidy/Output/google-readability-namespace-comments-cxx17.cpp.tmp.cpp:1:1:
note: scanning from here
// RUN: %check_clang_tidy %s google-readability-namespace-comments %t -- --
-std=c++17
^
/build/tools/clang/tools/extra/test/clang-tidy/Output/google-readability-namespace-comments-cxx17.cpp.tmp.cpp:5:7:
note: possible intended match here
   // So that namespace is not empty.
   ^


--
Command Output (stderr):
--
Traceback (most recent call last):
   File
"/src/tools/clang/tools/extra/test/../test/clang-tidy/check_clang_tidy.py",
line 140, in 
 main()
   File
"/src/tools/clang/tools/extra/test/../test/clang-tidy/check_clang_tidy.py",
line 121, in main
 stderr=subprocess.STDOUT)
   File "/usr/lib/python2.7/subprocess.py", line 573, in check_output
 raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['FileCheck',
'-input-file=/build/tools/clang/tools/extra/test/clang-tidy/Output/google-readability-namespace-comments-cxx17.cpp.tmp.cpp',
'/src/tools/clang/tools/extra/test/clan

Re: [clang-tools-extra] r315060 - Renaming a test to start with the name of the check based on post-commit review feedback; NFC.

2017-10-12 Thread Jonas Toth via cfe-commits

Ok.

I subscribe to r315057. I can look at debugging the change as well if 
you guys want. Should have time today evening and tomorrow.



Am 12.10.2017 um 12:46 schrieb Alexander Kornienko:
On Thu, Oct 12, 2017 at 11:12 AM, Jonas Toth > wrote:


Hi,

I am not sure if could follow correctly, but the test for nested
namespaces comments does not work correctly and is therefore
currently disabled by fileextension?


No, the removal of the file extension was unintentional (likely 
misunderstanding of my post-commit review comment).



When running the check from trunk i get the following issues:

$ clang-check google-readability-namespace-comments-cxx17.cpp --
-std=c++17
> error: invalid value 'c++17' in '-std=c++17'


I suppose, your clang-check is just old. Clang supports -std=c++17 
these days.



In the clang-tidy check '-std=c++17' is used. I don't know if the
c++17 - flag is introduced in clang yet, but maybe this would be
one issue.

Running clang-tidy from command line does not produce output
(added fileextension for now):

$ clang-tidy -checks=-*,google-readability-namespace-comments
google-readability-namespace-comments-cxx17.cpp -- -std=c++1z
$ clang-tidy -checks=-*,google-readability-namespace-comments
google-readability-namespace-comments-cxx17.cpp -- -- -std=c++1z
> Error while processing

/home/jonas/opt/llvm/tools/clang/tools/extra/test/clang-tidy/google-readability-namespace-comments-cxx17.cpp.

Adding a 'std::cout << "Test if run" << std::endl' at the
beginning of the `check` - Method works and generates output:

$ clang-tidy -checks=-*,google-readability-namespace-comments
google-readability-namespace-comments-cxx17.cpp -- -std=c++1z
Test if run
Test if run
Test if run

So I think there is a regression in the Testingcode not catching
the nested namespaces. Did it work before and what could have changed?
If it did work and the clang-tidy code is the same this could be a
regression somewhere else.


The problem was that the namespace was shorter than the default 
ShortNamespaceLines option value, so the check didn't trigger. Fixed 
in r315574 (but would be nice, if this kind of stuff was detected 
before commit).


However, this is not the end of problems with this check. It started 
causing assertion failures on some of our code after the recent 
changes (r315057). I'll post an update on that revision once I have 
more details.



All the Best, Jonas


Am 11.10.2017 um 21:36 schrieb Aaron Ballman:

On Wed, Oct 11, 2017 at 3:29 PM, Alexander Kornienko
mailto:ale...@google.com>> wrote:

On Fri, Oct 6, 2017 at 3:27 PM, Aaron Ballman via cfe-commits
mailto:cfe-commits@lists.llvm.org>> wrote:

Author: aaronballman
Date: Fri Oct  6 06:27:59 2017
New Revision: 315060

URL:
http://llvm.org/viewvc/llvm-project?rev=315060&view=rev

Log:
Renaming a test to start with the name of the check
based on post-commit
review feedback; NFC.

Added:


clang-tools-extra/trunk/test/clang-tidy/google-readability-namespace-comments-cxx17


Sorry for not being clear. I didn't mean the `.cpp`
extension should be
removed. This effectively disables the test, since lit
only runs tests in
files with certain extensions (under
clang-tools-extra/test these are '.c',
'.cpp', '.hpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s',
'.modularize',
'.module-map-checker', '.test').

That's entirely my fault -- I should have recognized that.
Sorry for
the trouble!

I've just renamed the file to *.cpp and the test fails for me:

[0/1] Running the Clang extra tools' regression tests
FAIL: Clang Tools ::
clang-tidy/google-readability-namespace-comments-cxx17.cpp
(102 of 674)
 TEST 'Clang Tools ::
clang-tidy/google-readability-namespace-comments-cxx17.cpp'
FAILED

Script:
--
/usr/bin/python2.7

/src/tools/clang/tools/extra/test/../test/clang-tidy/check_clang_tidy.py

/src/tools/clang/tools/extra/test/clang-tidy/google-readability-namespace-comments-cxx17.cpp
google-readability-namespace-comments

/build/tools/clang/tools/extra/test/clang-tidy/Output/google-readability-namespace-comments-cxx17.cpp.tmp
-- -- -std=c++17
--
Exit Code: 1

Command Output (stdout):
--
Running ['clang-ti

[clang-tools-extra] r316092 - [clang-tidy] introduce legacy resource functions to 'cppcoreguidelines-owning-memory'

2017-10-18 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Oct 18 09:14:15 2017
New Revision: 316092

URL: http://llvm.org/viewvc/llvm-project?rev=316092&view=rev
Log:
[clang-tidy] introduce legacy resource functions to 
'cppcoreguidelines-owning-memory'

Summary:
This patch introduces support for legacy C-style resource functions that must 
obey
the 'owner<>' semantics.

- added legacy creators like malloc,fopen,...
- added legacy consumers like free,fclose,...

This helps codes that mostly benefit from owner:
Legacy, C-Style code that isn't feasable to port directly to RAII but needs a 
step in between
to identify actual resource management and just using the resources.

Reviewers: aaron.ballman, alexfh, hokein

Reviewed By: aaron.ballman

Subscribers: nemanjai, JDevlieghere, xazax.hun, kbarton

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


Added:

clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-containers.cpp

clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-legacy-functions.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/OwningMemoryCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-owning-memory.rst

Modified: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp?rev=316092&r1=316091&r2=316092&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp 
Wed Oct 18 09:14:15 2017
@@ -22,6 +22,21 @@ namespace clang {
 namespace tidy {
 namespace cppcoreguidelines {
 
+// FIXME: Copied from 'NoMallocCheck.cpp'. Has to be refactored into 'util' or
+// something like that.
+namespace {
+Matcher hasAnyListedName(const std::string &FunctionNames) {
+  const std::vector NameList =
+  utils::options::parseStringList(FunctionNames);
+  return hasAnyName(std::vector(NameList.begin(), NameList.end()));
+}
+} // namespace
+
+void OwningMemoryCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "LegacyResourceProducers", LegacyResourceProducers);
+  Options.store(Opts, "LegacyResourceConsumers", LegacyResourceConsumers);
+}
+
 /// Match common cases, where the owner semantic is relevant, like function
 /// calls, delete expressions and others.
 void OwningMemoryCheck::registerMatchers(MatchFinder *Finder) {
@@ -30,10 +45,31 @@ void OwningMemoryCheck::registerMatchers
 
   const auto OwnerDecl = typeAliasTemplateDecl(hasName("::gsl::owner"));
   const auto IsOwnerType = hasType(OwnerDecl);
+
+  const auto LegacyCreatorFunctions = 
hasAnyListedName(LegacyResourceProducers);
+  const auto LegacyConsumerFunctions =
+  hasAnyListedName(LegacyResourceConsumers);
+
+  // Legacy functions that are use for resource management but cannot be
+  // updated to use `gsl::owner<>`, like standard C memory management.
+  const auto CreatesLegacyOwner =
+  callExpr(callee(functionDecl(LegacyCreatorFunctions)));
+  // C-style functions like `::malloc()` sometimes create owners as void*
+  // which is expected to be cast to the correct type in C++. This case
+  // must be catched explicitly.
+  const auto LegacyOwnerCast =
+  castExpr(hasSourceExpression(CreatesLegacyOwner));
+  // Functions that do manual resource management but cannot be updated to use
+  // owner. Best example is `::free()`.
+  const auto LegacyOwnerConsumers = functionDecl(LegacyConsumerFunctions);
+
   const auto CreatesOwner =
-  anyOf(cxxNewExpr(), callExpr(callee(functionDecl(
-  returns(qualType(hasDeclaration(OwnerDecl)));
-  const auto ConsideredOwner = anyOf(IsOwnerType, CreatesOwner);
+  anyOf(cxxNewExpr(),
+callExpr(callee(
+functionDecl(returns(qualType(hasDeclaration(OwnerDecl)),
+CreatesLegacyOwner, LegacyOwnerCast);
+
+  const auto ConsideredOwner = eachOf(IsOwnerType, CreatesOwner);
 
   // Find delete expressions that delete non-owners.
   Finder->addMatcher(
@@ -43,6 +79,21 @@ void OwningMemoryCheck::registerMatchers
   .bind("delete_expr"),
   this);
 
+  // Ignoring the implicit casts is vital because the legacy owners do not work
+  // with the 'owner<>' annotation and therefore always implicitly cast to the
+  // legacy type (even 'void *').
+  //
+  // Furthermore, legacy owner functions are assumed to use raw pointers for
+  // resources. This check assumes that all pointer arguments of a legacy
+  // functions shall be 'gsl::owner<>'.
+  Finder->addMatcher(
+  callExpr(
+  allOf(callee(LegacyOwnerConsumers),
+hasAnyArgument(allOf(unless(ignoringImpCasts(ConsideredOwner)),
+

[clang-tools-extra] r316093 - [clang-tidy] Fix buildbot for msvc

2017-10-18 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Oct 18 09:28:06 2017
New Revision: 316093

URL: http://llvm.org/viewvc/llvm-project?rev=316093&view=rev
Log:
[clang-tidy] Fix buildbot for msvc

The testcase defined `FILE` as `unsigned long`, but MSVC expect `unsigned long 
long`.

Modified:

clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-legacy-functions.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-legacy-functions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-legacy-functions.cpp?rev=316093&r1=316092&r2=316093&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-legacy-functions.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-legacy-functions.cpp
 Wed Oct 18 09:28:06 2017
@@ -10,7 +10,7 @@ using owner = T;
 } // namespace gsl
 
 extern "C" {
-using size_t = unsigned long;
+using size_t = unsigned long long;
 using FILE = int;
 
 void *malloc(size_t ByteCount);


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


[clang-tools-extra] r316094 - [clang-tidy] Fix 32bit platform MSVC

2017-10-18 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Oct 18 09:40:19 2017
New Revision: 316094

URL: http://llvm.org/viewvc/llvm-project?rev=316094&view=rev
Log:
[clang-tidy] Fix 32bit platform MSVC

The previous fix only worked for 64bit MSVC, this one should fix all different
architectures.

Modified:

clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-legacy-functions.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-legacy-functions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-legacy-functions.cpp?rev=316094&r1=316093&r2=316094&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-legacy-functions.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-legacy-functions.cpp
 Wed Oct 18 09:40:19 2017
@@ -10,7 +10,7 @@ using owner = T;
 } // namespace gsl
 
 extern "C" {
-using size_t = unsigned long long;
+using size_t = decltype(sizeof(void*));
 using FILE = int;
 
 void *malloc(size_t ByteCount);


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


r340623 - [clang-format] fix PR38525 - Extraneous continuation indent spaces with BreakBeforeBinaryOperators set to All

2018-08-24 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Fri Aug 24 10:14:31 2018
New Revision: 340623

URL: http://llvm.org/viewvc/llvm-project?rev=340623&view=rev
Log:
[clang-format] fix PR38525 - Extraneous continuation indent spaces with 
BreakBeforeBinaryOperators set to All

Summary: See bug report https://bugs.llvm.org/show_bug.cgi?id=38525 for more 
details.

Reviewers: djasper, klimek, krasimir, sammccall

Reviewed By: sammccall

Subscribers: hiraditya, JonasToth, cfe-commits

Tags: #clang

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

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

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=340623&r1=340622&r2=340623&view=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Fri Aug 24 10:14:31 2018
@@ -700,7 +700,8 @@ void ContinuationIndenter::addTokenOnCur
 // Indent relative to the RHS of the expression unless this is a simple
 // assignment without binary expression on the RHS. Also indent relative to
 // unary operators and the colons of constructor initializers.
-State.Stack.back().LastSpace = State.Column;
+if (Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None)
+  State.Stack.back().LastSpace = State.Column;
   } else if (Previous.is(TT_InheritanceColon)) {
 State.Stack.back().Indent = State.Column;
 State.Stack.back().LastSpace = State.Column;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=340623&r1=340622&r2=340623&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Aug 24 10:14:31 2018
@@ -3375,6 +3375,18 @@ TEST_F(FormatTest, ExpressionIndentation
"= b\n"
"  >> (aa);",
Style);
+
+  Style.ColumnLimit = 80;
+  Style.IndentWidth = 4;
+  Style.TabWidth = 4;
+  Style.UseTab = FormatStyle::UT_Always;
+  Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign;
+  Style.AlignOperands = false;
+  EXPECT_EQ("return someVeryVeryLongConditionThatBarelyFitsOnALine\n"
+"\t&& (someOtherLongishConditionPart1\n"
+"\t\t|| someOtherEvenLongerNestedConditionPart2);",
+format("return someVeryVeryLongConditionThatBarelyFitsOnALine && 
(someOtherLongishConditionPart1 || someOtherEvenLongerNestedConditionPart2);",
+   Style));
 }
 
 TEST_F(FormatTest, EnforcedOperatorWraps) {


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


r340624 - [clang-format] fix PR38557 - comments between "default" and ':' causes the case label to be treated as an identifier

2018-08-24 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Fri Aug 24 10:25:06 2018
New Revision: 340624

URL: http://llvm.org/viewvc/llvm-project?rev=340624&view=rev
Log:
[clang-format] fix PR38557 - comments between "default" and ':' causes the case 
label to be treated as an identifier

Summary:
The Bug was reported and fixed by Owen Pan. See the original bug report here: 
https://bugs.llvm.org/show_bug.cgi?id=38557

Patch by Owen Pan!

Reviewers: krasimir, djasper, klimek

Reviewed By: klimek

Subscribers: JonasToth, cfe-commits

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

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

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=340624&r1=340623&r2=340624&view=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Fri Aug 24 10:25:06 2018
@@ -350,7 +350,10 @@ void UnwrappedLineParser::parseLevel(boo
   break;
 case tok::kw_default: {
   unsigned StoredPosition = Tokens->getPosition();
-  FormatToken *Next = Tokens->getNextToken();
+  FormatToken *Next;
+  do {
+Next = Tokens->getNextToken();
+  } while (Next && Next->is(tok::comment));
   FormatTok = Tokens->setPosition(StoredPosition);
   if (Next && Next->isNot(tok::colon)) {
 // default not followed by ':' is not a case label; treat it like

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=340624&r1=340623&r2=340624&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Aug 24 10:25:06 2018
@@ -1145,6 +1145,22 @@ TEST_F(FormatTest, ShortCaseLabels) {
"  break;\n"
"}",
Style);
+  Style.ColumnLimit = 80;
+  Style.AllowShortCaseLabelsOnASingleLine = false;
+  Style.IndentCaseLabels = true;
+  EXPECT_EQ("switch (n) {\n"
+"  default /*comments*/:\n"
+"return true;\n"
+"  case 0:\n"
+"return false;\n"
+"}",
+format("switch (n) {\n"
+   "default/*comments*/:\n"
+   "  return true;\n"
+   "case 0:\n"
+   "  return false;\n"
+   "}",
+   Style));
 }
 
 TEST_F(FormatTest, FormatsLabels) {


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


[clang-tools-extra] r340928 - [clang-tidy] Add abseil-no-internal-dependencies check

2018-08-29 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Aug 29 07:23:15 2018
New Revision: 340928

URL: http://llvm.org/viewvc/llvm-project?rev=340928&view=rev
Log:
[clang-tidy] Add abseil-no-internal-dependencies check

Finds instances where the user depends on internal details and warns them 
against doing so.
Should not be run on internal Abseil files or Abseil source code.

Patch by hugoeg!

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

Added:
clang-tools-extra/trunk/clang-tidy/abseil/NoInternalDependenciesCheck.cpp
clang-tools-extra/trunk/clang-tidy/abseil/NoInternalDependenciesCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-no-internal-dependencies.rst
clang-tools-extra/trunk/test/clang-tidy/abseil-no-internal-dependencies.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/external-file.h
clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/strings/internal-file.h

Modified: clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp?rev=340928&r1=340927&r2=340928&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp Wed Aug 29 
07:23:15 2018
@@ -12,6 +12,7 @@
 #include "../ClangTidyModuleRegistry.h"
 #include "DurationDivisionCheck.h"
 #include "FasterStrsplitDelimiterCheck.h"
+#include "NoInternalDependenciesCheck.h"
 #include "NoNamespaceCheck.h"
 #include "RedundantStrcatCallsCheck.h"
 #include "StringFindStartswithCheck.h"
@@ -28,6 +29,8 @@ public:
 "abseil-duration-division");
 CheckFactories.registerCheck(
 "abseil-faster-strsplit-delimiter");
+CheckFactories.registerCheck(
+"abseil-no-internal-dependencies");
 CheckFactories.registerCheck("abseil-no-namespace");
 CheckFactories.registerCheck(
 "abseil-redundant-strcat-calls");

Modified: clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt?rev=340928&r1=340927&r2=340928&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt Wed Aug 29 
07:23:15 2018
@@ -4,6 +4,7 @@ add_clang_library(clangTidyAbseilModule
   AbseilTidyModule.cpp
   DurationDivisionCheck.cpp
   FasterStrsplitDelimiterCheck.cpp
+  NoInternalDependenciesCheck.cpp
   NoNamespaceCheck.cpp
   RedundantStrcatCallsCheck.cpp
   StringFindStartswithCheck.cpp

Added: clang-tools-extra/trunk/clang-tidy/abseil/NoInternalDependenciesCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/NoInternalDependenciesCheck.cpp?rev=340928&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/abseil/NoInternalDependenciesCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/abseil/NoInternalDependenciesCheck.cpp 
Wed Aug 29 07:23:15 2018
@@ -0,0 +1,48 @@
+//===--- NoInternalDependenciesCheck.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 "NoInternalDependenciesCheck.h"
+#include "AbseilMatcher.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace abseil {
+
+void NoInternalDependenciesCheck::registerMatchers(MatchFinder *Finder) {
+  if (!getLangOpts().CPlusPlus)
+return;
+
+  // TODO: refactor matcher to be configurable or just match on any internal
+  // access from outside the enclosing namespace.
+
+  Finder->addMatcher(
+  nestedNameSpecifierLoc(loc(specifiesNamespace(namespaceDecl(
+ matchesName("internal"),
+ hasParent(namespaceDecl(hasName("absl")),
+ unless(isInAbseilFile()))
+  .bind("InternalDep"),
+  this);
+}
+
+void NoInternalDependenciesCheck::check(const MatchFinder::MatchResult 
&Result) {
+  const auto *InternalDependency =
+  Result.Nodes.getNodeAs("InternalDep");
+
+  diag(InternalDependency->getBeginLoc(),
+   "do not reference any 'internal' namespaces; those implementation "
+   "detail

[clang-tools-extra] r341039 - [clang-tidy] fix check_clang_tidy to forbid mixing of CHECK-NOTES and CHECK-MESSAGES

2018-08-30 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Thu Aug 30 01:44:27 2018
New Revision: 341039

URL: http://llvm.org/viewvc/llvm-project?rev=341039&view=rev
Log:
[clang-tidy] fix check_clang_tidy to forbid mixing of CHECK-NOTES and 
CHECK-MESSAGES

Summary:
The check_clang_tidy.py script would allow mixing of `CHECK-NOTES` and 
`CHECK-MESSAGES` but running `FileCheck` for that would implicitly fail, 
because `CHECK-NOTES` bails out if there is a warning.

That means a clang-tidy test can not mix these constructs to check warnings 
with `CHECK-MESSAGES` and notes with `CHECK-NOTES`. The script gives now a 
clear error if that happens.

Reviewers: alexfh, aaron.ballman, lebedev.ri, hokein

Reviewed By: lebedev.ri

Subscribers: xazax.hun, cfe-commits

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

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=341039&r1=341038&r2=341039&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 Thu Aug 30 
01:44:27 2018
@@ -98,6 +98,9 @@ def main():
 sys.exit('%s, %s or %s not found in the input' % (check_fixes_prefix,
  check_messages_prefix, check_notes_prefix) )
 
+  if has_check_notes and has_check_messages:
+sys.exit('Please use either CHECK-NOTES or CHECK-MESSAGES but not both')
+
   # 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


r341284 - Fix Bug 38713: clang-format mishandles a short block after "default:" in a switch statement

2018-09-02 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Sun Sep  2 02:04:51 2018
New Revision: 341284

URL: http://llvm.org/viewvc/llvm-project?rev=341284&view=rev
Log:
Fix Bug 38713: clang-format mishandles a short block after "default:" in a 
switch statement

Summary:
See https://bugs.llvm.org/show_bug.cgi?id=38713

Patch by Owen Pan!

Reviewers: djasper, klimek, sammccall

Reviewed By: sammccall

Subscribers: cfe-commits

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

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

Modified: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp?rev=341284&r1=341283&r2=341284&view=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp Sun Sep  2 02:04:51 2018
@@ -483,6 +483,12 @@ private:
 if (Line.First->isOneOf(tok::kw_else, tok::kw_case) ||
 (Line.First->Next && Line.First->Next->is(tok::kw_else)))
   return 0;
+// default: in switch statement
+if (Line.First->is(tok::kw_default)) {
+  const FormatToken *Tok = Line.First->getNextNonComment();
+  if (Tok && Tok->is(tok::colon))
+return 0;
+}
 if (Line.First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_do, tok::kw_try,
 tok::kw___try, tok::kw_catch, tok::kw___finally,
 tok::kw_for, tok::r_brace, Keywords.kw___except)) {

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=341284&r1=341283&r2=341284&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sun Sep  2 02:04:51 2018
@@ -999,6 +999,24 @@ TEST_F(FormatTest, FormatsSwitchStatemen
"  }\n"
"});",
getLLVMStyle()));
+  EXPECT_EQ("switch (n) {\n"
+"case 0: {\n"
+"  return false;\n"
+"}\n"
+"default: {\n"
+"  return true;\n"
+"}\n"
+"}",
+format("switch (n)\n"
+   "{\n"
+   "case 0: {\n"
+   "  return false;\n"
+   "}\n"
+   "default: {\n"
+   "  return true;\n"
+   "}\n"
+   "}",
+   getLLVMStyle()));
   verifyFormat("switch (a) {\n"
"case (b):\n"
"  return;\n"


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


[clang-tools-extra] r341933 - [NFC][clangd] fix warning for extra semicolon

2018-09-11 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Sep 11 06:01:49 2018
New Revision: 341933

URL: http://llvm.org/viewvc/llvm-project?rev=341933&view=rev
Log:
[NFC][clangd] fix warning for extra semicolon

Modified:
clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp

Modified: clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp?rev=341933&r1=341932&r2=341933&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp Tue Sep 11 06:01:49 
2018
@@ -1210,7 +1210,7 @@ TEST(FindReferences, NeedsIndex) {
   TU.Code = ("\n\n" + Main.code()).str();
   EXPECT_THAT(findReferences(AST, Main.point(), TU.index().get()),
   ElementsAre(RangeIs(Main.range(;
-};
+}
 
 TEST(FindReferences, NoQueryForLocalSymbols) {
   struct RecordingIndex : public MemIndex {
@@ -1244,7 +1244,7 @@ TEST(FindReferences, NoQueryForLocalSymb
 else
   EXPECT_EQ(Rec.RefIDs, llvm::None) << T.AnnotatedCode;
   }
-};
+}
 
 } // namespace
 } // namespace clangd


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


r341958 - [ASTMatchers] add three matchers for dependent expressions

2018-09-11 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Sep 11 09:09:19 2018
New Revision: 341958

URL: http://llvm.org/viewvc/llvm-project?rev=341958&view=rev
Log:
[ASTMatchers] add three matchers for dependent expressions

Summary:
The new matchers can be used to check if an expression is type-, value- or 
instantiation-dependent
in a templated context.
These matchers are used in a clang-tidy check and generally useful as the
problem of unresolved templates occurs more often in clang-tidy and they
provide an easy way to check for this issue.

Reviewers: aaron.ballman, alexfh, klimek

Reviewed By: aaron.ballman

Subscribers: cfe-commits

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

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=341958&r1=341957&r2=341958&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Tue Sep 11 09:09:19 2018
@@ -2758,6 +2758,46 @@ enum class Y {};
 
 
 
+MatcherExpr>isInstantiationDependent
+Matches 
expressions that are instantiation-dependent even if it is
+neither type- nor value-dependent.
+
+In the following example, the expression sizeof(sizeof(T() + T()))
+is instantiation-dependent (since it involves a template parameter T),
+but is neither type- nor value-dependent, since the type of the inner
+sizeof is known (std::size_t) and therefore the size of the outer
+sizeof is known.
+  template
+  void f(T x, T y) { sizeof(sizeof(T() + T()); }
+expr(isInstantiationDependent()) matches sizeof(sizeof(T() + T())
+
+
+
+MatcherExpr>isTypeDependent
+Matches expressions 
that are type-dependent because the template type
+is not yet instantiated.
+
+For example, the expressions "x" and "x + y" are type-dependent in
+the following code, but "y" is not type-dependent:
+  template
+  void add(T x, int y) {
+x + y;
+  }
+expr(isTypeDependent()) matches x + y
+
+
+
+MatcherExpr>isValueDependent
+Matches expression 
that are value-dependent because they contain a
+non-type template parameter.
+
+For example, the array bound of "Chars" in the following example is
+value-dependent.
+  template int f() { return Size; }
+expr(isValueDependent()) matches return Size
+
+
+
 MatcherFieldDecl>hasBitWidthunsigned Width
 Matches non-static data 
members that are bit-fields of the specified
 bit width.

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=341958&r1=341957&r2=341958&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Tue Sep 11 09:09:19 2018
@@ -816,6 +816,48 @@ AST_MATCHER_P(QualType, ignoringParens,
   return InnerMatcher.matches(Node.IgnoreParens(), Finder, Builder);
 }
 
+/// Matches expressions that are instantiation-dependent even if it is
+/// neither type- nor value-dependent.
+///
+/// In the following example, the expression sizeof(sizeof(T() + T()))
+/// is instantiation-dependent (since it involves a template parameter T),
+/// but is neither type- nor value-dependent, since the type of the inner
+/// sizeof is known (std::size_t) and therefore the size of the outer
+/// sizeof is known.
+/// \code
+///   template
+///   void f(T x, T y) { sizeof(sizeof(T() + T()); }
+/// \endcode
+/// expr(isInstantiationDependent()) matches sizeof(sizeof(T() + T())
+AST_MATCHER(Expr, isInstantiationDependent) {
+  return Node.isInstantiationDependent();
+}
+
+/// Matches expressions that are type-dependent because the template type
+/// is not yet instantiated.
+///
+/// For example, the expressions "x" and "x + y" are type-dependent in
+/// the following code, but "y" is not type-dependent:
+/// \code
+///   template
+///   void add(T x, int y) {
+/// x + y;
+///   }
+/// \endcode
+/// expr(isTypeDependent()) matches x + y
+AST_MATCHER(Expr, isTypeDependent) { return Node.isTypeDependent(); }
+
+/// Matches expression that are value-dependent because they contain a
+/// non-type template parameter.
+///
+/// For example, the array bound of "Chars" in the following example is
+/// value-dependent.
+/// \code
+///   template int f() { return Size; }
+/// \endcode
+/// expr(isValueDependent()) matches return Size
+AST_MATCHER

[clang-tools-extra] r342267 - [NFC][clangd] silence pedantic extra '; ' warning

2018-09-14 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Fri Sep 14 12:42:37 2018
New Revision: 342267

URL: http://llvm.org/viewvc/llvm-project?rev=342267&view=rev
Log:
[NFC][clangd] silence pedantic extra ';' warning

Modified:
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=342267&r1=342266&r2=342267&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Fri Sep 14 
12:42:37 2018
@@ -671,7 +671,7 @@ TEST(CompletionTest, CompletionInPreambl
 )cpp")
  .Completions;
   EXPECT_THAT(Results, ElementsAre(Named("ifndef")));
-};
+}
 
 TEST(CompletionTest, DynamicIndexMultiFile) {
   MockFSProvider FS;


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


r337703 - [ASTMatchers] add matcher for decltypeType and its underlyingType

2018-07-23 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Mon Jul 23 08:59:27 2018
New Revision: 337703

URL: http://llvm.org/viewvc/llvm-project?rev=337703&view=rev
Log:
[ASTMatchers] add matcher for decltypeType and its underlyingType

Summary:
This patch introduces a new matcher for `DecltypeType` and its underlying type
in order to fix a bug in clang-tidy, see https://reviews.llvm.org/D48717 for 
more.

Reviewers: aaron.ballman, alexfh, NoQ, dcoughlin

Reviewed By: aaron.ballman

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=337703&r1=337702&r2=337703&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Mon Jul 23 08:59:27 2018
@@ -5111,6 +5111,18 @@ AST_TYPELOC_TRAVERSE_MATCHER_DECL(hasVal
 ///   matches "auto n" and "auto i"
 extern const AstTypeMatcher autoType;
 
+/// Matches types nodes representing C++11 decltype() types.
+///
+/// Given:
+/// \code
+///   short i = 1;
+///   int j = 42;
+///   decltype(i + j) result = i + j;
+/// \endcode
+/// decltypeType() 
+///   matches "decltype(i + j)"
+extern const AstTypeMatcher decltypeType;
+
 /// Matches \c AutoType nodes where the deduced type is a specific type.
 ///
 /// Note: There is no \c TypeLoc for the deduced type and thus no
@@ -5128,6 +5140,20 @@ extern const AstTypeMatcher au
 AST_TYPE_TRAVERSE_MATCHER(hasDeducedType, getDeducedType,
   AST_POLYMORPHIC_SUPPORTED_TYPES(AutoType));
 
+/// Matches \c DecltypeType nodes to find out the underlying type.
+///
+/// Given
+/// \code
+///   decltype(1) a = 1;
+///   decltype(2.0) b = 2.0;
+/// \endcode
+/// decltypeType(hasUnderlyingType(isInteger()))
+///   matches "auto a"
+///
+/// Usable as: Matcher
+AST_TYPE_TRAVERSE_MATCHER(hasUnderlyingType, getUnderlyingType,
+  AST_POLYMORPHIC_SUPPORTED_TYPES(DecltypeType));
+
 /// Matches \c FunctionType nodes.
 ///
 /// Given

Modified: cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp?rev=337703&r1=337702&r2=337703&view=diff
==
--- cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp Mon Jul 23 08:59:27 2018
@@ -800,6 +800,7 @@ const AstTypeMatcher variableArrayType;
 const AstTypeMatcher atomicType;
 const AstTypeMatcher autoType;
+const AstTypeMatcher decltypeType;
 const AstTypeMatcher functionType;
 const AstTypeMatcher functionProtoType;
 const AstTypeMatcher parenType;

Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=337703&r1=337702&r2=337703&view=diff
==
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Mon Jul 23 08:59:27 2018
@@ -188,6 +188,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(decayedType);
   REGISTER_MATCHER(decl);
   REGISTER_MATCHER(declaratorDecl);
+  REGISTER_MATCHER(decltypeType);
   REGISTER_MATCHER(declCountIs);
   REGISTER_MATCHER(declRefExpr);
   REGISTER_MATCHER(declStmt);

Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp?rev=337703&r1=337702&r2=337703&view=diff
==
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp Mon Jul 23 08:59:27 
2018
@@ -1206,6 +1206,12 @@ TEST(TypeMatching, MatchesAutoTypes) {
   //   autoType(hasDeducedType(isInteger();
 }
 
+TEST(TypeMatching, MatchesDeclTypes) {
+  EXPECT_TRUE(matches("decltype(1 + 1) sum = 1 + 1;", decltypeType()));
+  EXPECT_TRUE(matches("decltype(1 + 1) sum = 1 + 1;",
+  decltypeType(hasUnderlyingType(isInteger();
+}
+
 TEST(TypeMatching, MatchesFunctionTypes) {
   EXPECT_TRUE(matches("int (*f)(int);", functionType()));
   EXPECT_TRUE(matches("void f(int i) {}", functionType()));


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


[clang-tools-extra] r337707 - [clang-tidy] remove private decltypeType in TrailingReturnType

2018-07-23 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Mon Jul 23 09:30:13 2018
New Revision: 337707

URL: http://llvm.org/viewvc/llvm-project?rev=337707&view=rev
Log:
[clang-tidy] remove private decltypeType in TrailingReturnType

Summary:
This patch removes a private matcher in fuchsia/TrailingReturnType check because
the matcher is now in ASTMatchers

Reviewers: aaron.ballman, alexfh, hokein

Reviewed By: aaron.ballman

Subscribers: xazax.hun, cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.cpp?rev=337707&r1=337706&r2=337707&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.cpp Mon Jul 
23 09:30:13 2018
@@ -19,8 +19,6 @@ namespace tidy {
 namespace fuchsia {
 
 namespace {
-const internal::VariadicDynCastAllOfMatcher decltypeType;
-
 AST_MATCHER(FunctionDecl, hasTrailingReturn) {
   return Node.getType()->castAs()->hasTrailingReturn();
 }


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


[clang-tools-extra] r337710 - [clang-tidy] fix PR36489 - respect deduced pointer types from auto as well

2018-07-23 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Mon Jul 23 10:13:06 2018
New Revision: 337710

URL: http://llvm.org/viewvc/llvm-project?rev=337710&view=rev
Log:
[clang-tidy] fix PR36489 - respect deduced pointer types from auto as well

Summary:
The cppcoreguidelines-pro-bounds-pointer-arithmetic warns on all occassion where
pointer arithmetic is used, but does not check values where the pointer types
is deduced via ``auto``. This patch adjusts this behaviour and solved
PR36489.

Reviewers: alexfh, aaron.ballman, hokein, ilya-biryukov

Reviewed By: alexfh, aaron.ballman

Subscribers: nemanjai, xazax.hun, kbarton, cfe-commits

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

Modified:

clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp?rev=337710&r1=337709&r2=337710&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp
 Mon Jul 23 10:13:06 2018
@@ -85,5 +85,32 @@ void okay() {
 
   auto diff = p - q; // OK, result is arithmetic
 
-  for(int ii : a) ; // OK, pointer arithmetic generated by compiler
+  for (int ii : a)
+; // OK, pointer arithmetic generated by compiler
+}
+
+// Fix PR36207
+namespace std {
+template 
+struct char_traits {};
+
+template 
+struct allocator {};
+
+template ,
+  typename Allocator = allocator>
+class basic_string {};
+
+template 
+basic_string operator+(const basic_string &lhs,
+ const CharT *rhs) {}
+
+using string = basic_string;
+} // namespace std
+
+std::string str_generated() {}
+
+void problematic_addition() {
+  std::string status = str_generated() + " is not found";
 }


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


[clang-tools-extra] r337712 - Revert "[clang-tidy] fix PR36489 - respect deduced pointer types from auto as well"

2018-07-23 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Mon Jul 23 10:34:25 2018
New Revision: 337712

URL: http://llvm.org/viewvc/llvm-project?rev=337712&view=rev
Log:
Revert "[clang-tidy] fix PR36489 - respect deduced pointer types from auto as 
well"

I applied the wrong patch.

Modified:

clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp?rev=337712&r1=337711&r2=337712&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp
 Mon Jul 23 10:34:25 2018
@@ -85,32 +85,5 @@ void okay() {
 
   auto diff = p - q; // OK, result is arithmetic
 
-  for (int ii : a)
-; // OK, pointer arithmetic generated by compiler
-}
-
-// Fix PR36207
-namespace std {
-template 
-struct char_traits {};
-
-template 
-struct allocator {};
-
-template ,
-  typename Allocator = allocator>
-class basic_string {};
-
-template 
-basic_string operator+(const basic_string &lhs,
- const CharT *rhs) {}
-
-using string = basic_string;
-} // namespace std
-
-std::string str_generated() {}
-
-void problematic_addition() {
-  std::string status = str_generated() + " is not found";
+  for(int ii : a) ; // OK, pointer arithmetic generated by compiler
 }


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


[clang-tools-extra] r337716 - [clang-tidy] fix PR36489 - respect deduced pointer types from auto as well

2018-07-23 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Mon Jul 23 10:46:17 2018
New Revision: 337716

URL: http://llvm.org/viewvc/llvm-project?rev=337716&view=rev
Log:
[clang-tidy] fix PR36489 - respect deduced pointer types from auto as well

Summary:
The cppcoreguidelines-pro-bounds-pointer-arithmetic warns on all occassion where
pointer arithmetic is used, but does not check values where the pointer types
is deduced via `auto`. This patch adjusts this behaviour and solved
PR36489.
I accidentally commited a wrong patch, this Differential is meant to have a
correct revision description and code attached to it.
Because the patch was accepted by aaron.ballman already, i will just commit
it.
See https://reviews.llvm.org/D48717 for the old differntial (contains wrong
code from the mixup)

Subscribers: nemanjai, xazax.hun, kbarton, cfe-commits

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

Added:

clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic-pr36489.cpp
Modified:

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp?rev=337716&r1=337715&r2=337716&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp
 Mon Jul 23 10:46:17 2018
@@ -21,12 +21,16 @@ void ProBoundsPointerArithmeticCheck::re
   if (!getLangOpts().CPlusPlus)
 return;
 
+  const auto AllPointerTypes = anyOf(
+  hasType(pointerType()), hasType(autoType(hasDeducedType(pointerType(,
+  hasType(decltypeType(hasUnderlyingType(pointerType();
+
   // Flag all operators +, -, +=, -=, ++, -- that result in a pointer
   Finder->addMatcher(
   binaryOperator(
   anyOf(hasOperatorName("+"), hasOperatorName("-"),
 hasOperatorName("+="), hasOperatorName("-=")),
-  hasType(pointerType()),
+  AllPointerTypes,
   unless(hasLHS(ignoringImpCasts(declRefExpr(to(isImplicit()))
   .bind("expr"),
   this);
@@ -41,7 +45,7 @@ void ProBoundsPointerArithmeticCheck::re
   Finder->addMatcher(
   arraySubscriptExpr(
   hasBase(ignoringImpCasts(
-  anyOf(hasType(pointerType()),
+  anyOf(AllPointerTypes,
 hasType(decayedType(hasDecayedType(pointerType(
   .bind("expr"),
   this);

Added: 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic-pr36489.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic-pr36489.cpp?rev=337716&view=auto
==
--- 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic-pr36489.cpp
 (added)
+++ 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic-pr36489.cpp
 Mon Jul 23 10:46:17 2018
@@ -0,0 +1,53 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-pro-bounds-pointer-arithmetic 
%t -- -- -std=c++14
+
+// Fix PR36489 and detect auto-deduced value correctly.
+char *getPtr();
+auto getPtrAuto() { return getPtr(); }
+decltype(getPtr()) getPtrDeclType();
+decltype(auto) getPtrDeclTypeAuto() { return getPtr(); }
+auto getPtrWithTrailingReturnType() -> char *;
+
+void auto_deduction_binary() {
+  auto p1 = getPtr() + 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: do not use pointer arithmetic
+  auto p2 = getPtrAuto() + 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: do not use pointer arithmetic
+  auto p3 = getPtrWithTrailingReturnType() + 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: do not use pointer arithmetic
+  auto p4 = getPtr();
+  auto *p5 = getPtr();
+  p4 = p4 + 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not use pointer arithmetic
+  p5 = p5 + 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not use pointer arithmetic
+  auto p6 = getPtrDeclType() + 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: do not use pointer arithmetic
+  auto p7 = getPtrDeclTypeAuto() + 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: do not use pointer arithmetic
+  auto *p8 = getPtrDeclType() + 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: do not use pointer arithmetic
+  auto *p9 = getPtrDeclTypeAuto() + 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: do not use pointer arithmetic
+}
+
+void auto_deduction_subscript() {
+  char p1 = getPtr()[2];
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic
+  auto p2 = getPtr()[3];
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do

r338022 - [ASTMatchers] fix the missing documentation for new decltypeType matcher

2018-07-26 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Thu Jul 26 06:02:05 2018
New Revision: 338022

URL: http://llvm.org/viewvc/llvm-project?rev=338022&view=rev
Log:
[ASTMatchers] fix the missing documentation for new decltypeType matcher

Summary: Regenerate the Matchers documentation, forgotten in the original patch.

Reviewers: alexfh, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: cfe-commits

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

Modified:
cfe/trunk/docs/LibASTMatchersReference.html

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=338022&r1=338021&r2=338022&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Thu Jul 26 06:02:05 2018
@@ -1577,6 +1577,18 @@ Example matches i[1].
 
 
 
+MatcherType>decltypeTypeMatcherDecltypeType>...
+Matches types nodes 
representing C++11 decltype() types.
+
+Given:
+  short i = 1;
+  int j = 42;
+  decltype(i + j) result = i + j;
+decltypeType() 
+  matches "decltype(i + j)"
+
+
+
 MatcherType>dependentSizedArrayTypeMatcherDependentSizedArrayType>...
 Matches C++ 
arrays whose size is a value-dependent expression.
 
@@ -5156,6 +5168,19 @@ declaration of class D.
 
 
 
+MatcherDecltypeType>hasUnderlyingTypeMatcherType>
+Matches 
DecltypeType nodes to find out the underlying type.
+
+Given
+  decltype(1) a = 1;
+  decltype(2.0) b = 2.0;
+decltypeType(hasUnderlyingType(isInteger()))
+  matches "auto a"
+
+Usable as: MatcherDecltypeType>
+
+
+
 MatcherDoStmt>hasBodyMatcherStmt> 
InnerMatcher
 Matches a 'for', 'while', 
'do while' statement or a function
 definition that has a given body.


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


[clang-tools-extra] r338393 - [clang-tidy] add all clang-tidy modules to plugin

2018-07-31 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Jul 31 08:23:49 2018
New Revision: 338393

URL: http://llvm.org/viewvc/llvm-project?rev=338393&view=rev
Log:
[clang-tidy] add all clang-tidy modules to plugin

Summary:
This patch addresses PR38359 and adds all existing clang-tidy
modules to the plugin that can be used together with libclang.

Reviewers: alexfh, aaron.ballman, hokein, ilya-biryukov

Reviewed By: alexfh

Subscribers: srhines, mgorny, xazax.hun, cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp

Modified: clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt?rev=338393&r1=338392&r2=338393&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt Tue Jul 31 
08:23:49 2018
@@ -8,12 +8,15 @@ add_clang_library(clangTidyPlugin
   clangFrontend
   clangSema
   clangTidy
-  clangTidyAndroidModule
   clangTidyAbseilModule
+  clangTidyAndroidModule
   clangTidyBoostModule
+  clangTidyBugproneModule
   clangTidyCERTModule
   clangTidyCppCoreGuidelinesModule
+  clangTidyFuchsiaModule
   clangTidyGoogleModule
+  clangTidyHICPPModule
   clangTidyLLVMModule
   clangTidyMiscModule
   clangTidyModernizeModule
@@ -22,5 +25,6 @@ add_clang_library(clangTidyPlugin
   clangTidyPerformanceModule
   clangTidyPortabilityModule
   clangTidyReadabilityModule
+  clangTidyZirconModule
   clangTooling
   )

Modified: clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp?rev=338393&r1=338392&r2=338393&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp Tue Jul 31 
08:23:49 2018
@@ -78,26 +78,51 @@ static clang::FrontendPluginRegistry::Ad
 namespace clang {
 namespace tidy {
 
+// This anchor is used to force the linker to link the AbseilModule.
+extern volatile int AbseilModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED AbseilModuleAnchorDestination =
+AbseilModuleAnchorSource;
+
+// This anchor is used to force the linker to link the AndroidModule.
+extern volatile int AndroidModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED AndroidModuleAnchorDestination =
+AndroidModuleAnchorSource;
+
+// This anchor is used to force the linker to link the BoostModule.
+extern volatile int BoostModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED BoostModuleAnchorDestination =
+BoostModuleAnchorSource;
+
 // This anchor is used to force the linker to link the CERTModule.
 extern volatile int CERTModuleAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED CERTModuleAnchorDestination =
 CERTModuleAnchorSource;
 
-// This anchor is used to force the linker to link the LLVMModule.
-extern volatile int LLVMModuleAnchorSource;
-static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination =
-LLVMModuleAnchorSource;
-
 // This anchor is used to force the linker to link the CppCoreGuidelinesModule.
 extern volatile int CppCoreGuidelinesModuleAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED CppCoreGuidelinesModuleAnchorDestination =
 CppCoreGuidelinesModuleAnchorSource;
 
+// This anchor is used to force the linker to link the FuchsiaModule.
+extern volatile int FuchsiaModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED FuchsiaModuleAnchorDestination =
+FuchsiaModuleAnchorSource;
+
 // This anchor is used to force the linker to link the GoogleModule.
 extern volatile int GoogleModuleAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED GoogleModuleAnchorDestination =
 GoogleModuleAnchorSource;
 
+// This anchor is used to force the linker to link the HICPPModule.
+extern volatile int HICPPModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED HICPPModuleAnchorDestination =
+HICPPModuleAnchorSource;
+
+// This anchor is used to force the linker to link the LLVMModule.
+extern volatile int LLVMModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination =
+LLVMModuleAnchorSource;
+
 // This anchor is used to force the linker to link the MiscModule.
 extern volatile int MiscModuleAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
@@ -111,7 +136,12 @@ static int LLVM_ATTRIBUTE_UNUSED Moderni
 // This anchor is used to force the linker to link the MPIModule.
 extern volatile int MPIModuleAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED MPIModuleAnchorDestination =
-  MPIModuleAnchorSource;
+MPIModuleAnchorSource;
+
+// This anchor is used to force the linker to link the ObjCModule.
+ex

r338996 - [clang-rename] make clang-rename.py vim integration python3 compatible

2018-08-06 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Mon Aug  6 02:08:06 2018
New Revision: 338996

URL: http://llvm.org/viewvc/llvm-project?rev=338996&view=rev
Log:
[clang-rename] make clang-rename.py vim integration python3 compatible

Summary:
This patch makes the clang-rename.py script useable for vim with only python3
support. It uses the print-function and adjust the doc slightly to mention
the correct python3 command for the letter mapping in vim.

Reviewers: arphaman, klimek, aaron.ballman, hokein

Reviewed By: hokein

Subscribers: cfe-commits

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

Modified:
cfe/trunk/tools/clang-rename/clang-rename.py

Modified: cfe/trunk/tools/clang-rename/clang-rename.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-rename/clang-rename.py?rev=338996&r1=338995&r2=338996&view=diff
==
--- cfe/trunk/tools/clang-rename/clang-rename.py (original)
+++ cfe/trunk/tools/clang-rename/clang-rename.py Mon Aug  6 02:08:06 2018
@@ -7,10 +7,14 @@ Before installing make sure one of the f
 * `g:clang_rename_path` in ~/.vimrc points to valid clang-rename executable
 * `binary` in clang-rename.py points to valid to clang-rename executable
 
-To install, simply put this into your ~/.vimrc
+To install, simply put this into your ~/.vimrc for python2 support
 
 noremap cr :pyf /clang-rename.py
 
+For python3 use the following command (note the change from :pyf to :py3f)
+
+noremap cr :py3f /clang-rename.py
+
 IMPORTANT NOTE: Before running the tool, make sure you saved the file.
 
 All you have to do now is to place a cursor on a variable/function/class which
@@ -18,6 +22,7 @@ you would like to rename and press '> sys.stderr, '''Couldn\'t determine cursor position.
-Is your file empty?'''
+print('Couldn\'t determine cursor position. Is your file empty?',
+  file=sys.stderr)
 return
 filename = vim.current.buffer.name
 
@@ -51,7 +56,7 @@ def main():
 stdout, stderr = p.communicate()
 
 if stderr:
-print stderr
+print(stderr)
 
 # Reload all buffers in Vim.
 vim.command("checktime")


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


Re: [PATCH] D45679: [clang-tidy] Add ExprMutationAnalyzer, that analyzes whether an expression is mutated within a statement.

2018-06-06 Thread Jonas Toth via cfe-commits
Hmm. SVN does not want  me to commit anything :/

I will retry later today, but maybe i cant commit.


Best, Jonas


Am 06.06.2018 um 10:47 schrieb Aaron Ballman:
> On Wed, Jun 6, 2018 at 4:40 AM Jonas Toth via Phabricator
>  wrote:
>> JonasToth added a comment.
>>
>> @shuaiwang I can commit it in 2 hours for you if you want, after my lecture.
> That's sooner than my "I can commit next week." :-D
>
> ~Aaron
>
>>
>> Repository:
>>   rCTE Clang Tools Extra
>>
>> https://reviews.llvm.org/D45679
>>
>>
>>

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


[clang-tools-extra] r344044 - [clangd] fix miscompiling lower_bound call

2018-10-09 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Oct  9 06:24:50 2018
New Revision: 344044

URL: http://llvm.org/viewvc/llvm-project?rev=344044&view=rev
Log:
[clangd] fix miscompiling lower_bound call

Modified:
clang-tools-extra/trunk/clangd/index/Index.cpp

Modified: clang-tools-extra/trunk/clangd/index/Index.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.cpp?rev=344044&r1=344043&r2=344044&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Index.cpp Tue Oct  9 06:24:50 2018
@@ -84,8 +84,9 @@ float quality(const Symbol &S) {
 }
 
 SymbolSlab::const_iterator SymbolSlab::find(const SymbolID &ID) const {
-  auto It = llvm::lower_bound(
-  Symbols, ID, [](const Symbol &S, const SymbolID &I) { return S.ID < I; 
});
+  auto It = std::lower_bound(
+  Symbols.begin(), Symbols.end(), ID,
+  [](const Symbol &S, const SymbolID &I) { return S.ID < I; });
   if (It != Symbols.end() && It->ID == ID)
 return It;
   return Symbols.end();


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


[clang-tools-extra] r344046 - [clang-tidy] NFC fix warnings from missing braces

2018-10-09 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Oct  9 06:29:31 2018
New Revision: 344046

URL: http://llvm.org/viewvc/llvm-project?rev=344046&view=rev
Log:
[clang-tidy] NFC fix warnings from missing braces

The std::array create multiple StringRef but did not wrap
them in braces. Some compilers warned for that. Adding the
braces is not possible and result in a compilation error.
This commit changes the array to vector which works without warning.

Modified:

clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp?rev=344046&r1=344045&r2=344046&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp 
Tue Oct  9 06:29:31 2018
@@ -17,11 +17,12 @@ namespace clang {
 namespace tidy {
 namespace modernize {
 
-static const std::array DeprecatedTypes = {
-"::std::ios_base::io_state",  "::std::ios_base::open_mode",
-"::std::ios_base::seek_dir",  "::std::ios_base::streamoff",
-"::std::ios_base::streampos",
-};
+static const llvm::SmallVector DeprecatedTypes = {
+{"::std::ios_base::io_state"},
+{"::std::ios_base::open_mode"},
+{"::std::ios_base::seek_dir"},
+{"::std::ios_base::streamoff"},
+{"::std::ios_base::streampos"}};
 
 static const llvm::StringMap ReplacementTypes = {
 {"io_state", "iostate"},


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


[clang-tools-extra] r344374 - [clang-tidy] New checker for not null-terminated result caused by strlen(), size() or equal length

2018-10-12 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Fri Oct 12 10:22:36 2018
New Revision: 344374

URL: http://llvm.org/viewvc/llvm-project?rev=344374&view=rev
Log:
[clang-tidy] New checker for not null-terminated result caused by strlen(), 
size() or equal length

New checker called bugprone-not-null-terminated-result. This check finds 
function calls where it is possible to cause a not null-terminated result. 
Usually the proper length of a string is strlen(src) + 1 or equal length of 
this expression, because the null terminator needs an extra space. Without the 
null terminator it can result in undefined behaviour when the string is read.

The following function calls are checked:
memcpy, wmemcpy, memcpy_s, wmemcpy_s, memchr, wmemchr, memmove, wmemmove, 
memmove_s, wmemmove_s, memset, wmemset, strerror_s, strncmp, wcsncmp, strxfrm, 
wcsxfrm

The following is a real-world example where the programmer forgot to increase 
the passed third argument, which is size_t length. That is why the length of 
the allocated memory is problematic too.

static char *StringCpy(const std::string &str) {
  char *result = reinterpret_cast(malloc(str.size()));
  memcpy(result, str.data(), str.size());
  return result;
}

After running the tool fix-it rewrites all the necessary code according to the 
given options. If it is necessary, the buffer size will be increased to hold 
the null terminator.

static char *StringCpy(const std::string &str) {
  char *result = reinterpret_cast(malloc(str.size() + 1));
  strcpy(result, str.data());
  return result;
}

Patch by Charusso.

Differential ID: https://reviews.llvm.org/D45050

Added:
clang-tools-extra/trunk/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/NotNullTerminatedResultCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-not-null-terminated-result.rst

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-in-initialization-strlen.c

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-memcpy-before-safe.c

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-memcpy-safe-cxx.cpp

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-memcpy-safe-other.c

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-memcpy-safe.c

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-strlen.c

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-wcslen.cpp

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-wmemcpy-safe-cxx.cpp
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=344374&r1=344373&r2=344374&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Fri Oct 
12 10:22:36 2018
@@ -30,6 +30,7 @@
 #include "MisplacedWideningCastCheck.h"
 #include "MoveForwardingReferenceCheck.h"
 #include "MultipleStatementMacroCheck.h"
+#include "NotNullTerminatedResultCheck.h"
 #include "ParentVirtualCallCheck.h"
 #include "SizeofContainerCheck.h"
 #include "SizeofExpressionCheck.h"
@@ -98,6 +99,8 @@ public:
 "bugprone-multiple-statement-macro");
 CheckFactories.registerCheck(
 "bugprone-narrowing-conversions");
+CheckFactories.registerCheck(
+"bugprone-not-null-terminated-result");
 CheckFactories.registerCheck(
 "bugprone-parent-virtual-call");
 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=344374&r1=344373&r2=344374&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt Fri Oct 12 
10:22:36 2018
@@ -21,6 +21,7 @@ add_clang_library(clangTidyBugproneModul
   MisplacedWideningCastCheck.cpp
   MoveForwardingReferenceCheck.cpp
   MultipleStatementMacroCheck.cpp
+  NotNullTerminatedResultCheck.cpp
   ParentVirtualCallCheck.cpp
   SizeofContainerCheck.cpp
   SizeofExpressionCheck.cpp

Added: 
clang-tools-extra/trunk/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp?rev=344374&view=

[clang-tools-extra] r344379 - [doc] fix markup in clang-tidy bugprone-not-null-terminated-result

2018-10-12 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Fri Oct 12 10:36:04 2018
New Revision: 344379

URL: http://llvm.org/viewvc/llvm-project?rev=344379&view=rev
Log:
[doc] fix markup in clang-tidy bugprone-not-null-terminated-result

Modified:

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-not-null-terminated-result.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-not-null-terminated-result.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-not-null-terminated-result.rst?rev=344379&r1=344378&r2=344379&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-not-null-terminated-result.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-not-null-terminated-result.rst
 Fri Oct 12 10:36:04 2018
@@ -55,11 +55,11 @@ Rewrite to a string handler function is
 
 Rewrite based on the destination array:
 
-- If copy to the destination array cannot *overflow then the new function 
should
+- If copy to the destination array cannot overflow then the new function should
   be the older copy function (ending with ``cpy``), because it is more
   efficient than the safe version.
 
-- If copy to the destination array can *overflow and
+- If copy to the destination array can overflow and
   ``AreSafeFunctionsAvailable`` is set to ``Yes``, ``y`` or non-zero and it is
   possible to obtain the capacity of the destination array then the new 
function
   could be the safe version (ending with ``cpy_s``).
@@ -67,7 +67,7 @@ Rewrite based on the destination array:
 - If the new function is could be safe version and C++ files are analysed then
   the length of the destination array can be omitted.
 
-- *It is possible to overflow:
+- It is possible to overflow:
   - Unknown the capacity of the destination array.
   - If the given length is equal to the destination capacity.
 
@@ -95,17 +95,21 @@ Memory handler functions
 :ref:`Transformation rules of 'memcpy()'` section.
 
 - ``memchr``:
+
   - Usually there is a C-style cast, and it is needed to be removed, because 
the
 new function ``strchr``'s return type is correct.
   - Also the given length is not needed in the new function.
 
 - ``memmove``:
+
   - If safe functions are available the new function is ``memmove_s``, it has
 four arguments:
+
 - destination array,
 - length of the destination array,
 - source string,
 - length of the source string which is incremented by one.
+
   - If safe functions are not available the given length is incremented by one.
 
 - ``memmove_s``: given length is incremented by one.


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


r344382 - [Doc] fix BB, add code-block type

2018-10-12 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Fri Oct 12 10:44:01 2018
New Revision: 344382

URL: http://llvm.org/viewvc/llvm-project?rev=344382&view=rev
Log:
[Doc] fix BB, add code-block type

Modified:
cfe/trunk/docs/UsersManual.rst

Modified: cfe/trunk/docs/UsersManual.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UsersManual.rst?rev=344382&r1=344381&r2=344382&view=diff
==
--- cfe/trunk/docs/UsersManual.rst (original)
+++ cfe/trunk/docs/UsersManual.rst Fri Oct 12 10:44:01 2018
@@ -1825,7 +1825,7 @@ program.
 
 The profile remapping file is a text file containing lines of the form
 
-.. code-block::
+.. code-block:: text
 
   fragmentkind fragment1 fragment2
 


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


[clang-tools-extra] r344384 - [clangd] NFC fix semicolon warning

2018-10-12 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Fri Oct 12 10:47:43 2018
New Revision: 344384

URL: http://llvm.org/viewvc/llvm-project?rev=344384&view=rev
Log:
[clangd] NFC fix semicolon warning

Modified:
clang-tools-extra/trunk/clangd/index/IndexAction.cpp

Modified: clang-tools-extra/trunk/clangd/index/IndexAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/IndexAction.cpp?rev=344384&r1=344383&r2=344384&view=diff
==
--- clang-tools-extra/trunk/clangd/index/IndexAction.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/IndexAction.cpp Fri Oct 12 10:47:43 
2018
@@ -74,7 +74,7 @@ createStaticIndexingAction(SymbolCollect
   return llvm::make_unique(
   std::make_shared(std::move(Opts)), std::move(Includes),
   IndexOpts, SymbolsCallback, RefsCallback);
-};
+}
 
 } // namespace clangd
 } // namespace clang


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


r344388 - [Doc] fix second error in UsersManual

2018-10-12 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Fri Oct 12 10:57:18 2018
New Revision: 344388

URL: http://llvm.org/viewvc/llvm-project?rev=344388&view=rev
Log:
[Doc] fix second error in UsersManual

Modified:
cfe/trunk/docs/UsersManual.rst

Modified: cfe/trunk/docs/UsersManual.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UsersManual.rst?rev=344388&r1=344387&r2=344388&view=diff
==
--- cfe/trunk/docs/UsersManual.rst (original)
+++ cfe/trunk/docs/UsersManual.rst Fri Oct 12 10:57:18 2018
@@ -1844,7 +1844,7 @@ For example, to specify that ``absl::str
 should be treated as equivalent when matching profile data, the following
 remapping file could be used:
 
-.. code-block::
+.. code-block:: text
 
   # absl::string_view is considered equivalent to std::string_view
   type N4absl11string_viewE St17basic_string_viewIcSt11char_traitsIcEE


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


[clang-tools-extra] r344441 - Revert "[doc] fix markup in clang-tidy bugprone-not-null-terminated-result"

2018-10-13 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Sat Oct 13 02:30:46 2018
New Revision: 31

URL: http://llvm.org/viewvc/llvm-project?rev=31&view=rev
Log:
Revert "[doc] fix markup in clang-tidy bugprone-not-null-terminated-result"

This reverts commit r344379.

Modified:

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-not-null-terminated-result.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-not-null-terminated-result.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-not-null-terminated-result.rst?rev=31&r1=30&r2=31&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-not-null-terminated-result.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-not-null-terminated-result.rst
 Sat Oct 13 02:30:46 2018
@@ -55,11 +55,11 @@ Rewrite to a string handler function is
 
 Rewrite based on the destination array:
 
-- If copy to the destination array cannot overflow then the new function should
+- If copy to the destination array cannot *overflow then the new function 
should
   be the older copy function (ending with ``cpy``), because it is more
   efficient than the safe version.
 
-- If copy to the destination array can overflow and
+- If copy to the destination array can *overflow and
   ``AreSafeFunctionsAvailable`` is set to ``Yes``, ``y`` or non-zero and it is
   possible to obtain the capacity of the destination array then the new 
function
   could be the safe version (ending with ``cpy_s``).
@@ -67,7 +67,7 @@ Rewrite based on the destination array:
 - If the new function is could be safe version and C++ files are analysed then
   the length of the destination array can be omitted.
 
-- It is possible to overflow:
+- *It is possible to overflow:
   - Unknown the capacity of the destination array.
   - If the given length is equal to the destination capacity.
 
@@ -95,21 +95,17 @@ Memory handler functions
 :ref:`Transformation rules of 'memcpy()'` section.
 
 - ``memchr``:
-
   - Usually there is a C-style cast, and it is needed to be removed, because 
the
 new function ``strchr``'s return type is correct.
   - Also the given length is not needed in the new function.
 
 - ``memmove``:
-
   - If safe functions are available the new function is ``memmove_s``, it has
 four arguments:
-
 - destination array,
 - length of the destination array,
 - source string,
 - length of the source string which is incremented by one.
-
   - If safe functions are not available the given length is incremented by one.
 
 - ``memmove_s``: given length is incremented by one.


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


[clang-tools-extra] r344442 - Revert "[clang-tidy] New checker for not null-terminated result caused by strlen(), size() or equal length"

2018-10-13 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Sat Oct 13 02:30:58 2018
New Revision: 32

URL: http://llvm.org/viewvc/llvm-project?rev=32&view=rev
Log:
Revert "[clang-tidy] New checker for not null-terminated result caused by 
strlen(), size() or equal length"

This reverts commit r344374.

Removed:
clang-tools-extra/trunk/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/NotNullTerminatedResultCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-not-null-terminated-result.rst

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-in-initialization-strlen.c

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-memcpy-before-safe.c

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-memcpy-safe-cxx.cpp

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-memcpy-safe-other.c

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-memcpy-safe.c

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-strlen.c

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-wcslen.cpp

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-wmemcpy-safe-cxx.cpp
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=32&r1=31&r2=32&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Sat Oct 
13 02:30:58 2018
@@ -30,7 +30,6 @@
 #include "MisplacedWideningCastCheck.h"
 #include "MoveForwardingReferenceCheck.h"
 #include "MultipleStatementMacroCheck.h"
-#include "NotNullTerminatedResultCheck.h"
 #include "ParentVirtualCallCheck.h"
 #include "SizeofContainerCheck.h"
 #include "SizeofExpressionCheck.h"
@@ -99,8 +98,6 @@ public:
 "bugprone-multiple-statement-macro");
 CheckFactories.registerCheck(
 "bugprone-narrowing-conversions");
-CheckFactories.registerCheck(
-"bugprone-not-null-terminated-result");
 CheckFactories.registerCheck(
 "bugprone-parent-virtual-call");
 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=32&r1=31&r2=32&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt Sat Oct 13 
02:30:58 2018
@@ -21,7 +21,6 @@ add_clang_library(clangTidyBugproneModul
   MisplacedWideningCastCheck.cpp
   MoveForwardingReferenceCheck.cpp
   MultipleStatementMacroCheck.cpp
-  NotNullTerminatedResultCheck.cpp
   ParentVirtualCallCheck.cpp
   SizeofContainerCheck.cpp
   SizeofExpressionCheck.cpp

Removed: 
clang-tools-extra/trunk/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp?rev=31&view=auto
==
--- 
clang-tools-extra/trunk/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp 
(removed)
@@ -1,1024 +0,0 @@
-//===--- NotNullTerminatedResultCheck.cpp - clang-tidy --*- C++ 
-*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===--===//
-
-#include "NotNullTerminatedResultCheck.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Frontend/CompilerInstance.h"
-#include "clang/Lex/Lexer.h"
-#include "clang/Lex/PPCallbacks.h"
-
-using namespace clang::ast_matchers;
-
-namespace clang {
-namespace tidy {
-namespace bugprone {
-
-static const char *const FuncExprName = "entire-called-function-expr";
-static const char *const CastExprName = "cast-expr";
-static const char *const UnknownDestName = "destination-length-is-unknown";
-static const char *const NotJustCharTyName = "unsigned-or-signed-char";
-static const char *const DestArrayTyName = "destination-is-arra

[clang-tools-extra] r344940 - [clang-tidy] implement cppcoreguidelines macro rules

2018-10-22 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Mon Oct 22 12:20:01 2018
New Revision: 344940

URL: http://llvm.org/viewvc/llvm-project?rev=344940&view=rev
Log:
[clang-tidy] implement cppcoreguidelines macro rules

Summary:
In short macros are discouraged by multiple rules (and sometimes reference 
randomly). [Enum.1], [ES.30], [ES.31]
This check allows only headerguards and empty macros for annotation.

Reviewers: aaron.ballman, hokein

Reviewed By: aaron.ballman

Subscribers: jbcoe, Eugene.Zelenko, klimek, nemanjai, mgorny, xazax.hun, 
kbarton, cfe-commits

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

Added:
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/MacroUsageCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst

clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-macro-usage-caps-only.cpp

clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-macro-usage.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt?rev=344940&r1=344939&r2=344940&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt 
(original)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt Mon Oct 
22 12:20:01 2018
@@ -4,6 +4,7 @@ add_clang_library(clangTidyCppCoreGuidel
   AvoidGotoCheck.cpp
   CppCoreGuidelinesTidyModule.cpp
   InterfacesGlobalInitCheck.cpp
+  MacroUsageCheck.cpp
   NarrowingConversionsCheck.cpp
   NoMallocCheck.cpp
   OwningMemoryCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp?rev=344940&r1=344939&r2=344940&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 Mon Oct 22 12:20:01 2018
@@ -15,6 +15,7 @@
 #include "../readability/MagicNumbersCheck.h"
 #include "AvoidGotoCheck.h"
 #include "InterfacesGlobalInitCheck.h"
+#include "MacroUsageCheck.h"
 #include "NarrowingConversionsCheck.h"
 #include "NoMallocCheck.h"
 #include "OwningMemoryCheck.h"
@@ -45,6 +46,8 @@ public:
 "cppcoreguidelines-avoid-magic-numbers");
 CheckFactories.registerCheck(
 "cppcoreguidelines-interfaces-global-init");
+CheckFactories.registerCheck(
+"cppcoreguidelines-macro-usage");
 CheckFactories.registerCheck(
 "cppcoreguidelines-narrowing-conversions");
 CheckFactories.registerCheck("cppcoreguidelines-no-malloc");

Added: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp?rev=344940&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp 
Mon Oct 22 12:20:01 2018
@@ -0,0 +1,95 @@
+//===--- MacroUsageCheck.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 "MacroUsageCheck.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/PPCallbacks.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/Regex.h"
+#include 
+
+namespace clang {
+namespace tidy {
+namespace cppcoreguidelines {
+
+namespace {
+
+bool isCapsOnly(StringRef Name) {
+  return std::all_of(Name.begin(), Name.end(), [](const char c) {
+if (std::isupper(c) || std::isdigit(c) || c == '_')
+  return true;
+return false;
+  });
+}
+
+class MacroUsageCallbacks : public PPCallbacks {
+public:
+  MacroUsageCallbacks(MacroUsageCheck *Check, StringRef RegExp, bool CapsOnly)
+  : Check(Check), RegExp(RegExp), CheckCapsOnly(CapsOnly) {}
+  void MacroDefined(const Token &MacroNameTok,
+const MacroDirective *MD) override {
+i

[clang-tools-extra] r344947 - [clang-tidy] tryfix windows build

2018-10-22 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Mon Oct 22 13:29:15 2018
New Revision: 344947

URL: http://llvm.org/viewvc/llvm-project?rev=344947&view=rev
Log:
[clang-tidy] tryfix windows build

Modified:
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp?rev=344947&r1=344946&r2=344947&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp 
Mon Oct 22 13:29:15 2018
@@ -13,6 +13,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Regex.h"
 #include 
+#include 
 
 namespace clang {
 namespace tidy {


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


[clang-tools-extra] r345167 - [clang-tidy] Add the abseil-duration-factory-float check

2018-10-24 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Oct 24 10:40:50 2018
New Revision: 345167

URL: http://llvm.org/viewvc/llvm-project?rev=345167&view=rev
Log:
[clang-tidy] Add the abseil-duration-factory-float check

Summary:
This check finds cases where calls to an absl::Duration factory could use the 
more efficient integer overload.

For example:
// Original - Providing a floating-point literal.
absl::Duration d = absl::Seconds(10.0);

// Suggested - Use an integer instead.
absl::Duration d = absl::Seconds(10);

Patch by hwright.

Reviewers: alexfh, hokein, aaron.ballman, JonasToth

Reviewed By: hokein, JonasToth

Subscribers: zturner, xazax.hun, Eugene.Zelenko, mgorny, cfe-commits

Tags: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/clang-tidy/abseil/DurationFactoryFloatCheck.cpp
clang-tools-extra/trunk/clang-tidy/abseil/DurationFactoryFloatCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-duration-factory-float.rst
clang-tools-extra/trunk/test/clang-tidy/abseil-duration-factory-float.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/abseil/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/abseil/AbseilTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp?rev=345167&r1=345166&r2=345167&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp Wed Oct 24 
10:40:50 2018
@@ -11,6 +11,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 #include "DurationDivisionCheck.h"
+#include "DurationFactoryFloatCheck.h"
 #include "FasterStrsplitDelimiterCheck.h"
 #include "NoInternalDependenciesCheck.h"
 #include "NoNamespaceCheck.h"
@@ -27,6 +28,8 @@ public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
 CheckFactories.registerCheck(
 "abseil-duration-division");
+CheckFactories.registerCheck(
+"abseil-duration-factory-float");
 CheckFactories.registerCheck(
 "abseil-faster-strsplit-delimiter");
 CheckFactories.registerCheck(

Modified: clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt?rev=345167&r1=345166&r2=345167&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt Wed Oct 24 
10:40:50 2018
@@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS support)
 add_clang_library(clangTidyAbseilModule
   AbseilTidyModule.cpp
   DurationDivisionCheck.cpp
+  DurationFactoryFloatCheck.cpp
   FasterStrsplitDelimiterCheck.cpp
   NoInternalDependenciesCheck.cpp
   NoNamespaceCheck.cpp

Added: clang-tools-extra/trunk/clang-tidy/abseil/DurationFactoryFloatCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/DurationFactoryFloatCheck.cpp?rev=345167&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/abseil/DurationFactoryFloatCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/abseil/DurationFactoryFloatCheck.cpp Wed 
Oct 24 10:40:50 2018
@@ -0,0 +1,106 @@
+//===--- DurationFactoryFloatCheck.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 "DurationFactoryFloatCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Tooling/FixIt.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace abseil {
+
+// Returns an integer if the fractional part of a `FloatingLiteral` is `0`.
+static llvm::Optional
+truncateIfIntegral(const FloatingLiteral &FloatLiteral) {
+  double Value = FloatLiteral.getValueAsApproximateDouble();
+  if (std::fmod(Value, 1) == 0) {
+if (Value >= static_cast(1u << 31))
+  return llvm::None;
+
+return llvm::APSInt::get(static_cast(Value));
+  }
+  return llvm::None;
+}
+
+// Returns `true` if `Range` is inside a macro definition.
+static bool InsideMacroDefinition(const MatchFinder::MatchResult &Result,
+  SourceRange Range) {
+  return !clang::Lexer::makeFileCharRange(
+  clang::CharSourceRange::getCharRange(Range),
+  *Resul

[clang-tools-extra] r351569 - [clang-tidy] add reproducer for PR39949 into test-suite

2019-01-18 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Fri Jan 18 10:03:11 2019
New Revision: 351569

URL: http://llvm.org/viewvc/llvm-project?rev=351569&view=rev
Log:
[clang-tidy] add reproducer for PR39949 into test-suite

Summary:
The underlying issue is fixed in https://reviews.llvm.org/D56444
and this test ensures the issue does not creep back into our
code-base.

Reviewers: alexfh, aaron.ballman, hokein, hwright

Reviewed By: aaron.ballman

Subscribers: xazax.hun, cfe-commits

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

Modified:

clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp?rev=351569&r1=351568&r2=351569&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp 
Fri Jan 18 10:03:11 2019
@@ -430,3 +430,36 @@ void factoryInMacros() {
   factoryTemplateAndMacro>();
   TemplateFactoryInMacro(ConvertibleTo());
 }
+
+// This is a reduced test-case for PR39949 and manifested in this check.
+namespace std {
+template 
+_Tp declval();
+
+template 
+struct __res {
+  template 
+  static decltype(declval<_Functor>()(_Args()...)) _S_test(int);
+
+  template 
+  static void _S_test(...);
+
+  typedef decltype(_S_test<_ArgTypes...>(0)) type;
+};
+
+template 
+struct function;
+
+template 
+struct function {
+  template ::type>
+  function(_Functor) {}
+};
+} // namespace std
+
+typedef std::function F;
+
+F foo() {
+  return F([] {});
+}


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


r351743 - [clang] add tests to ExprMutAnalyzer that reproduced a crash in ASTMatchers

2019-01-21 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Mon Jan 21 05:26:18 2019
New Revision: 351743

URL: http://llvm.org/viewvc/llvm-project?rev=351743&view=rev
Log:
[clang] add tests to ExprMutAnalyzer that reproduced a crash in ASTMatchers

Summary:
This patch adds two unit-tests that are the result of reducing a crashing TU
when running ExprMutAnalyzer over it. They are added only to ensure the 
regression
that has been fixed with https://reviews.llvm.org/D56444 don't creep back.

Reviewers: aaron.ballman, sammccall, rsmith, george.karpenkov

Reviewed By: sammccall

Subscribers: baloghadamsoftware, a.sidorin, Szelethus, donat.nagy, dkrupp, 
cfe-commits

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

Modified:
cfe/trunk/unittests/Analysis/ExprMutationAnalyzerTest.cpp

Modified: cfe/trunk/unittests/Analysis/ExprMutationAnalyzerTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Analysis/ExprMutationAnalyzerTest.cpp?rev=351743&r1=351742&r2=351743&view=diff
==
--- cfe/trunk/unittests/Analysis/ExprMutationAnalyzerTest.cpp (original)
+++ cfe/trunk/unittests/Analysis/ExprMutationAnalyzerTest.cpp Mon Jan 21 
05:26:18 2019
@@ -1108,4 +1108,23 @@ TEST(ExprMutationAnalyzerTest, UniquePtr
   EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x->mf()"));
 }
 
+TEST(ExprMutationAnalyzerTest, ReproduceFailureMinimal) {
+  const std::string Reproducer =
+  "namespace std {"
+  "template  T forward(T & A) { return static_cast(A); }"
+  "template  struct __bind {"
+  "  T f;"
+  "  template  __bind(T v, V &&) : f(forward(v)) {}"
+  "};"
+  "}"
+  "void f() {"
+  "  int x = 42;"
+  "  auto Lambda = [] {};"
+  "  std::__bind(Lambda, x);"
+  "}";
+  auto AST11 = buildASTFromCodeWithArgs(Reproducer, {"-std=c++11"});
+  auto Results11 =
+  match(withEnclosingCompound(declRefTo("x")), AST11->getASTContext());
+  EXPECT_FALSE(isMutated(Results11, AST11.get()));
+}
 } // namespace clang


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


[clang-tools-extra] r352231 - [clang-tidy] fix unit tests for dropped _Float16 support in X86

2019-01-25 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Fri Jan 25 11:05:12 2019
New Revision: 352231

URL: http://llvm.org/viewvc/llvm-project?rev=352231&view=rev
Log:
[clang-tidy] fix unit tests for dropped _Float16 support in X86

Summary:
Because _Float16 was disabled for X86 targets the unit-tests started failing.
Extract the pieces for _Float16 and run theses tests under AArch64.

Reviewers: aaron.ballman, erichkeane, lebedev.ri

Reviewed By: erichkeane

Subscribers: javed.absar, xazax.hun, kristof.beyls, cfe-commits

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

Added:

clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-float16.cpp
Modified:

clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-floating-point.cpp

clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-hexadecimal-floating-point.cpp

Added: 
clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-float16.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-float16.cpp?rev=352231&view=auto
==
--- 
clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-float16.cpp
 (added)
+++ 
clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-float16.cpp
 Fri Jan 25 11:05:12 2019
@@ -0,0 +1,51 @@
+// RUN: %check_clang_tidy %s readability-uppercase-literal-suffix %t -- -- 
-target aarch64-linux-gnu -I %S
+
+#include "readability-uppercase-literal-suffix.h"
+
+void float16_normal_literals() {
+  // _Float16
+
+  static constexpr auto v14 = 1.f16;
+  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has 
suffix 'f16', which is not uppercase
+  // CHECK-MESSAGES-NEXT: static constexpr auto v14 = 1.f16;
+  // CHECK-MESSAGES-NEXT: ^ ~
+  // CHECK-MESSAGES-NEXT: {{^ *}}F16{{$}}
+  // CHECK-FIXES: static constexpr auto v14 = 1.F16;
+  static_assert(is_same::value, "");
+  static_assert(v14 == 1.F16, "");
+
+  static constexpr auto v15 = 1.e0f16;
+  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has 
suffix 'f16', which is not uppercase
+  // CHECK-MESSAGES-NEXT: static constexpr auto v15 = 1.e0f16;
+  // CHECK-MESSAGES-NEXT: ^ ~
+  // CHECK-MESSAGES-NEXT: {{^ *}}F16{{$}}
+  // CHECK-FIXES: static constexpr auto v15 = 1.e0F16;
+  static_assert(is_same::value, "");
+  static_assert(v15 == 1.F16, "");
+
+  static constexpr auto v16 = 1.F16; // OK.
+  static_assert(is_same::value, "");
+  static_assert(v16 == 1.F16, "");
+
+  static constexpr auto v17 = 1.e0F16; // OK.
+  static_assert(is_same::value, "");
+  static_assert(v17 == 1.F16, "");
+}
+
+void float16_hexadecimal_literals() {
+// _Float16
+
+  static constexpr auto v13 = 0xfp0f16;
+  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has 
suffix 'f16', which is not uppercase
+  // CHECK-MESSAGES-NEXT: static constexpr auto v13 = 0xfp0f16;
+  // CHECK-MESSAGES-NEXT: ^~
+  // CHECK-MESSAGES-NEXT: {{^ *}}F16{{$}}
+  // CHECK-FIXES: static constexpr auto v13 = 0xfp0F16;
+  static_assert(is_same::value, "");
+  static_assert(v13 == 0xfp0F16, "");
+
+  static constexpr auto v14 = 0xfp0F16; // OK.
+  static_assert(is_same::value, "");
+  static_assert(v14 == 0xfp0F16, "");
+
+}

Modified: 
clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-floating-point.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-floating-point.cpp?rev=352231&r1=352230&r2=352231&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-floating-point.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/readability-uppercase-literal-suffix-floating-point.cpp
 Fri Jan 25 11:05:12 2019
@@ -3,8 +3,6 @@
 // RUN: clang-tidy %t.cpp -checks='-*,readability-uppercase-literal-suffix' 
-fix -- -target x86_64-pc-linux-gnu -I %S
 // RUN: clang-tidy %t.cpp -checks='-*,readability-uppercase-literal-suffix' 
-warnings-as-errors='-*,readability-uppercase-literal-suffix' -- -target 
x86_64-pc-linux-gnu -I %S
 
-// REQUIRES: disabled
-
 #include "readability-uppercase-literal-suffix.h"
 
 void floating_point_suffix() {
@@ -99,34 +97,6 @@ void floating_point_suffix() {
   static constexpr auto v13 = 1.e0Q; // OK.
   static_assert(is_same::value, "");
   static_assert(v13 == 1., "");
-
-  // _Float16
-
-  static constexpr auto v14 = 1.f16;
-  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has 
suffix 'f16', which is not uppercase
-  // CHECK-MESSAGES-NEXT: static constexpr auto v14 = 1.f16;
-  // CHECK-MESSAGES-NEXT: ^ ~
-  // CHECK-MESSAGES-NEXT: {{^ *}}F16{{$}}
-  // CHECK-FIXES: static constexpr auto v14 = 1.F16;
-  static_assert(is_same::value, "");
-  static_assert(v14 == 1.F16, "");
-

[clang-tools-extra] r352741 - [clang-tidy] refactor bugprone-exception-escape analysis into class

2019-01-31 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Thu Jan 31 02:46:37 2019
New Revision: 352741

URL: http://llvm.org/viewvc/llvm-project?rev=352741&view=rev
Log:
[clang-tidy] refactor bugprone-exception-escape analysis into class

Summary:
The check `bugprone-exception-escape` does an AST-based analysis to determine
if a function might throw an exception and warns based on that information.
The analysis part is refactored into a standalone class similiar to
`ExprMutAnalyzer` that is generally useful.
I intent to use that class in a new check to automatically introduce `noexcept`
if possible.

Reviewers: aaron.ballman, alexfh, hokein, baloghadamsoftware, lebedev.ri

Reviewed By: baloghadamsoftware, lebedev.ri

Subscribers: lebedev.ri, mgorny, xazax.hun, rnkovacs, cfe-commits

Tags: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/clang-tidy/utils/ExceptionAnalyzer.cpp
  - copied, changed from r352624, 
clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
clang-tools-extra/trunk/clang-tidy/utils/ExceptionAnalyzer.h
Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.h
clang-tools-extra/trunk/clang-tidy/utils/CMakeLists.txt

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.cpp?rev=352741&r1=352740&r2=352741&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.cpp Thu 
Jan 31 02:46:37 2019
@@ -1,4 +1,4 @@
-//===--- ExceptionEscapeCheck.cpp - 
clang-tidy-===//
+//===--- ExceptionEscapeCheck.cpp - clang-tidy 
===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -10,158 +10,21 @@
 
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
-
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringSet.h"
 
 using namespace clang::ast_matchers;
 
-namespace {
-typedef llvm::SmallVector TypeVec;
-} // namespace
-
 namespace clang {
-
-static bool isBaseOf(const Type *DerivedType, const Type *BaseType) {
-  const auto *DerivedClass = DerivedType->getAsCXXRecordDecl();
-  const auto *BaseClass = BaseType->getAsCXXRecordDecl();
-  if (!DerivedClass || !BaseClass)
-return false;
-
-  return !DerivedClass->forallBases(
-  [BaseClass](const CXXRecordDecl *Cur) { return Cur != BaseClass; });
-}
-
-static const TypeVec
-throwsException(const Stmt *St, const TypeVec &Caught,
-llvm::SmallSet &CallStack);
-
-static const TypeVec
-throwsException(const FunctionDecl *Func,
-llvm::SmallSet &CallStack) {
-  if (CallStack.count(Func))
-return TypeVec();
-
-  if (const Stmt *Body = Func->getBody()) {
-CallStack.insert(Func);
-const TypeVec Result = throwsException(Body, TypeVec(), CallStack);
-CallStack.erase(Func);
-return Result;
-  }
-
-  TypeVec Result;
-  if (const auto *FPT = Func->getType()->getAs()) {
-for (const QualType Ex : FPT->exceptions()) {
-  Result.push_back(Ex.getTypePtr());
-}
-  }
-  return Result;
-}
-
-static const TypeVec
-throwsException(const Stmt *St, const TypeVec &Caught,
-llvm::SmallSet &CallStack) {
-  TypeVec Results;
-
-  if (!St)
-return Results;
-
-  if (const auto *Throw = dyn_cast(St)) {
-if (const auto *ThrownExpr = Throw->getSubExpr()) {
-  const auto *ThrownType =
-  ThrownExpr->getType()->getUnqualifiedDesugaredType();
-  if (ThrownType->isReferenceType()) {
-ThrownType = ThrownType->castAs()
- ->getPointeeType()
- ->getUnqualifiedDesugaredType();
-  }
-  if (const auto *TD = ThrownType->getAsTagDecl()) {
-if (TD->getDeclName().isIdentifier() && TD->getName() == "bad_alloc"
-&& TD->isInStdNamespace())
-  return Results;
-  }
-  Results.push_back(ThrownExpr->getType()->getUnqualifiedDesugaredType());
-} else {
-  Results.append(Caught.begin(), Caught.end());
-}
-  } else if (const auto *Try = dyn_cast(St)) {
-TypeVec Uncaught = throwsException(Try->getTryBlock(), Caught, CallStack);
-for (unsigned i = 0; i < Try->getNumHandlers(); ++i) {
-  const CXXCatchStmt *Catch = Try->getHandler(i);
-  if (!Catch->getExceptionDecl()) {
-const TypeVec Rethrown =
-throwsException(Catch->getHandlerBlock(), Uncaught, CallStack);
-Results.append(Rethrown.begin(), Rethrown.end());
-Uncaught.clear();
-  } else {
-const auto *CaughtType =
-Catch->getCaugh

[clang-tools-extra] r345735 - [clang-tidy] new check 'readability-isolate-declaration'

2018-10-31 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Oct 31 09:50:44 2018
New Revision: 345735

URL: http://llvm.org/viewvc/llvm-project?rev=345735&view=rev
Log:
[clang-tidy] new check 'readability-isolate-declaration'

Summary:
This patch introduces a new clang-tidy check that matches on all `declStmt` 
that declare more then one variable
and transform them into one statement per declaration if possible.

It currently only focusses on variable declarations but should be extended to 
cover more kinds of declarations in the future.
It is related to https://reviews.llvm.org/D27621 and does use it's extensive 
test-suite. Thank you to firolino for his work!

Reviewers: rsmith, aaron.ballman, alexfh, hokein, kbobyrev

Reviewed By: aaron.ballman

Subscribers: ZaMaZaN4iK, mgehre, nemanjai, kbarton, lebedev.ri, Eugene.Zelenko, 
mgorny, xazax.hun, cfe-commits

Tags: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/clang-tidy/readability/IsolateDeclarationCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/IsolateDeclarationCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/readability-isolate-declaration.rst

clang-tools-extra/trunk/test/clang-tidy/readability-isolate-declaration-cxx17.cpp

clang-tools-extra/trunk/test/clang-tidy/readability-isolate-declaration-fixing.cpp
clang-tools-extra/trunk/test/clang-tidy/readability-isolate-declaration.c
clang-tools-extra/trunk/test/clang-tidy/readability-isolate-declaration.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/utils/LexerUtils.cpp
clang-tools-extra/trunk/clang-tidy/utils/LexerUtils.h
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt?rev=345735&r1=345734&r2=345735&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt Wed Oct 31 
09:50:44 2018
@@ -11,6 +11,7 @@ add_clang_library(clangTidyReadabilityMo
   IdentifierNamingCheck.cpp
   ImplicitBoolConversionCheck.cpp
   InconsistentDeclarationParameterNameCheck.cpp
+  IsolateDeclarationCheck.cpp
   MagicNumbersCheck.cpp
   MisleadingIndentationCheck.cpp
   MisplacedArrayIndexCheck.cpp

Added: 
clang-tools-extra/trunk/clang-tidy/readability/IsolateDeclarationCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/IsolateDeclarationCheck.cpp?rev=345735&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/readability/IsolateDeclarationCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/readability/IsolateDeclarationCheck.cpp 
Wed Oct 31 09:50:44 2018
@@ -0,0 +1,279 @@
+//===--- IsolateDeclarationCheck.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 "IsolateDeclarationCheck.h"
+#include "../utils/LexerUtils.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+using namespace clang::tidy::utils::lexer;
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+namespace {
+AST_MATCHER(DeclStmt, isSingleDecl) { return Node.isSingleDecl(); }
+AST_MATCHER(DeclStmt, onlyDeclaresVariables) {
+  return llvm::all_of(Node.decls(), [](Decl *D) { return isa(D); });
+}
+} // namespace
+
+void IsolateDeclarationCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  declStmt(allOf(onlyDeclaresVariables(), unless(isSingleDecl()),
+ hasParent(compoundStmt(
+  .bind("decl_stmt"),
+  this);
+}
+
+static SourceLocation findStartOfIndirection(SourceLocation Start,
+ int Indirections,
+ const SourceManager &SM,
+ const LangOptions &LangOpts) {
+  assert(Indirections >= 0 && "Indirections must be non-negative");
+  if (Indirections == 0)
+return Start;
+
+  // Note that the post-fix decrement is necessary to perform the correct
+  // number of transformations.
+  while (Indirections-- != 0) {
+Start = findPreviousAnyTokenKind(Start, SM, LangOpts, tok::star, tok::amp);
+if (Start.isInvalid() || Start.isMacroID())
+  return SourceLocation();
+  }
+  return Start;
+}
+
+static

[clang-tools-extra] r345736 - [clang-tools-extra] fix broken link in release notes

2018-10-31 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Oct 31 09:59:41 2018
New Revision: 345736

URL: http://llvm.org/viewvc/llvm-project?rev=345736&view=rev
Log:
[clang-tools-extra] fix broken link in release notes

Modified:
clang-tools-extra/trunk/docs/ReleaseNotes.rst

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=345736&r1=345735&r2=345736&view=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Wed Oct 31 09:59:41 2018
@@ -137,7 +137,7 @@ Improvements to clang-tidy
   those that have a non-deprecated equivalent.
 
 - New :doc:`readability-isolate-decl
-  ` check.
+  ` check.
 
   Detects local variable declarations declaring more than one variable and
   tries to refactor the code to one statement per declaration.


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


r345737 - [clang] try-fix broken documentation builder

2018-10-31 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Oct 31 10:00:50 2018
New Revision: 345737

URL: http://llvm.org/viewvc/llvm-project?rev=345737&view=rev
Log:
[clang] try-fix broken documentation builder

Modified:
cfe/trunk/docs/ReleaseNotes.rst

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=345737&r1=345736&r2=345737&view=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Wed Oct 31 10:00:50 2018
@@ -142,6 +142,7 @@ ABI Changes in Clang
 
 - `_Alignof` and `alignof` now return the ABI alignment of a type, as opposed
   to the preferred alignment.
+
   - This is more in keeping with the language of the standards, as well as
 being compatible with gcc
   - `__alignof` and `__alignof__` still return the preferred alignment of


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


[clang-tools-extra] r345738 - [clang-tidy] add -fexceptions to failing unit-test, unbreak buildbot

2018-10-31 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Oct 31 10:08:09 2018
New Revision: 345738

URL: http://llvm.org/viewvc/llvm-project?rev=345738&view=rev
Log:
[clang-tidy] add -fexceptions to failing unit-test, unbreak buildbot

Modified:
clang-tools-extra/trunk/test/clang-tidy/readability-isolate-declaration.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/readability-isolate-declaration.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-isolate-declaration.cpp?rev=345738&r1=345737&r2=345738&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/readability-isolate-declaration.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-isolate-declaration.cpp 
Wed Oct 31 10:08:09 2018
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s readability-isolate-declaration %t
+// RUN: %check_clang_tidy %s readability-isolate-declaration %t -- -fexceptions
 
 void f() {
   int i;


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


[clang-tools-extra] r345742 - [clang-tidy] add missing '--' in RUN-line, unbreak buildbot

2018-10-31 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Oct 31 10:26:10 2018
New Revision: 345742

URL: http://llvm.org/viewvc/llvm-project?rev=345742&view=rev
Log:
[clang-tidy] add missing '--' in RUN-line, unbreak buildbot

Modified:
clang-tools-extra/trunk/test/clang-tidy/readability-isolate-declaration.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/readability-isolate-declaration.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-isolate-declaration.cpp?rev=345742&r1=345741&r2=345742&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/readability-isolate-declaration.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-isolate-declaration.cpp 
Wed Oct 31 10:26:10 2018
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s readability-isolate-declaration %t -- -fexceptions
+// RUN: %check_clang_tidy %s readability-isolate-declaration %t -- -- 
-fexceptions
 
 void f() {
   int i;


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


[clang-tools-extra] r345995 - [fix][clang-tidy] fix for r345961 that introduced a test failure on Windows builds

2018-11-02 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Fri Nov  2 09:36:21 2018
New Revision: 345995

URL: http://llvm.org/viewvc/llvm-project?rev=345995&view=rev
Log:
[fix][clang-tidy] fix for r345961 that introduced a test failure on Windows 
builds

r345961 introduced a path check in
.\tools\clang\tools\extra\test\clang-tidy\clang-tidy-run-with-database.cpp.

r345961 added a check line for a path that only handled / on unix
machines and not \ on windows machines.

This patch handles both cases.

Patch by TWeaver.

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

Modified:
clang-tools-extra/trunk/test/clang-tidy/clang-tidy-run-with-database.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/clang-tidy-run-with-database.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/clang-tidy-run-with-database.cpp?rev=345995&r1=345994&r2=345995&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/clang-tidy-run-with-database.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/clang-tidy-run-with-database.cpp 
Fri Nov  2 09:36:21 2018
@@ -11,7 +11,7 @@
 
 // Regression test: shouldn't crash.
 // RUN: not clang-tidy --checks=-*,modernize-use-nullptr -p %T 
%T/compilation-database-test/b/not-exist -header-filter=.* 2>&1 | FileCheck %s 
-check-prefix=CHECK-NOT-EXIST
-// CHECK-NOT-EXIST: Error while processing {{.*}}/not-exist.
+// CHECK-NOT-EXIST: Error while processing {{.*[/\\]}}not-exist.
 // CHECK-NOT-EXIST: unable to handle compilation
 // CHECK-NOT-EXIST: Found compiler error
 


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


[clang-tools-extra] r346173 - [clang-tidy] doc removew hitespace in front of code-block-line

2018-11-05 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Mon Nov  5 14:21:27 2018
New Revision: 346173

URL: http://llvm.org/viewvc/llvm-project?rev=346173&view=rev
Log:
[clang-tidy] doc removew hitespace in front of code-block-line

Modified:
clang-tools-extra/trunk/docs/clang-tidy/checks/boost-use-to-string.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-forwarding-reference-overload.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-move-forwarding-reference.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-suspicious-semicolon.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-use-after-move.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-special-member-functions.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/google-build-using-namespace.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-pass-by-value.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-replace-auto-ptr.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-transparent-functors.rst

Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/boost-use-to-string.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/boost-use-to-string.rst?rev=346173&r1=346172&r2=346173&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/boost-use-to-string.rst 
(original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/boost-use-to-string.rst Mon 
Nov  5 14:21:27 2018
@@ -11,7 +11,7 @@ It doesn't replace conversion from float
 overloads, because it would change the behaviour.
 
 
-  .. code-block:: c++
+.. code-block:: c++
 
 auto str = boost::lexical_cast(42);
 auto wstr = boost::lexical_cast(2137LL);

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-forwarding-reference-overload.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-forwarding-reference-overload.rst?rev=346173&r1=346172&r2=346173&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-forwarding-reference-overload.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-forwarding-reference-overload.rst
 Mon Nov  5 14:21:27 2018
@@ -13,7 +13,7 @@ Item 26.
 
 Consider the following example:
 
-  .. code-block:: c++
+.. code-block:: c++
 
 class Person {
 public:

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-move-forwarding-reference.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-move-forwarding-reference.rst?rev=346173&r1=346172&r2=346173&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-move-forwarding-reference.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-move-forwarding-reference.rst
 Mon Nov  5 14:21:27 2018
@@ -5,7 +5,7 @@ bugprone-move-forwarding-reference
 
 Warns if ``std::move`` is called on a forwarding reference, for example:
 
-  .. code-block:: c++
+.. code-block:: c++
 
 template 
 void foo(T&& t) {
@@ -22,7 +22,7 @@ function template argument.)
 
 In this example, the suggested fix would be
 
-  .. code-block:: c++
+.. code-block:: c++
 
 bar(std::forward(t));
 
@@ -34,7 +34,7 @@ Code like the example above is sometimes
 deduced for ``T``, and that it is therefore not possible to pass an lvalue to
 ``foo()``. However, this is not true. Consider this example:
 
-  .. code-block:: c++
+.. code-block:: c++
 
 std::string s = "Hello, world";
 foo(s);

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-suspicious-semicolon.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-suspicious-semicolon.rst?rev=346173&r1=346172&r2=346173&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-suspicious-semicolon.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-suspicious-semicolon.rst
 Mon Nov  5 14:21:27 2018
@@ -9,7 +9,7 @@ the code. More specifically, it looks fo
 context of the code (e.g. indentation) in an attempt to determine whether that
 is intentional.
 
-  .. code-block:: c++
+.. code-block:: c++
 
 if (x < y);
 {
@@ -20,7 +20,7 @@ Here the body of the ``if`` statement co
 of the first line, and `x` will be incremented regardless of the condition.
 
 
-  .. code-block:: c++
+.. code-block:: c++
 
 while ((line = readLine(file)) != NULL);
   processLine(line);
@@ -30,7 +30,7 @@ As a result of this code, `processLine()
 the code indicates the intention of

[clang-tools-extra] r346176 - [clang-tidy] fix example code-blocks indendation

2018-11-05 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Mon Nov  5 14:30:17 2018
New Revision: 346176

URL: http://llvm.org/viewvc/llvm-project?rev=346176&view=rev
Log:
[clang-tidy] fix example code-blocks indendation

Modified:

clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-special-member-functions.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-special-member-functions.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-special-member-functions.rst?rev=346176&r1=346175&r2=346176&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-special-member-functions.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-special-member-functions.rst
 Mon Nov  5 14:30:17 2018
@@ -28,7 +28,7 @@ Options
When set to `1` (default is `0`), this check doesn't flag classes with a 
sole, explicitly
defaulted destructor. An example for such a class is:

-.. code-block:: c++
+   .. code-block:: c++

  struct A {
virtual ~A() = default;
@@ -40,7 +40,7 @@ Options
operations at all. It still flags classes which define only one of either
move constructor or move assignment operator. With this option enabled, the 
following class won't be flagged:

-.. code-block:: c++
+   .. code-block:: c++

  struct A {
A(const A&);

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst?rev=346176&r1=346175&r2=346176&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst 
(original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst 
Mon Nov  5 14:30:17 2018
@@ -107,7 +107,7 @@ Options
 When non-zero, the check will ignore implicitly constructed arguments of
 ``push_back``, e.g.
 
-.. code-block:: c++
+.. code-block:: c++
 
 std::vector v;
 v.push_back("a"); // Ignored when IgnoreImplicitConstructors is ``1``.


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


r346554 - [ASTMatchers] overload ignoringParens for Expr

2018-11-09 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Fri Nov  9 12:54:06 2018
New Revision: 346554

URL: http://llvm.org/viewvc/llvm-project?rev=346554&view=rev
Log:
[ASTMatchers] overload ignoringParens for Expr

Summary: This patch allows fixing PR39583.

Reviewers: aaron.ballman, sbenza, klimek

Reviewed By: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=346554&r1=346553&r2=346554&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Fri Nov  9 12:54:06 2018
@@ -5552,6 +5552,17 @@ would only match the declaration for a.
 
 
 
+MatcherExpr>ignoringParensMatcherExpr> 
InnerMatcher
+Overload 
ignoringParens for Expr.
+
+Given
+  const char* str = ("my-string");
+The matcher
+  implicitCastExpr(hasSourceExpression(ignoringParens(stringLiteral(
+would match the implicit cast resulting from the assignment.
+
+
+
 MatcherFieldDecl>hasInClassInitializerMatcherExpr> 
InnerMatcher
 Matches 
non-static data members that have an in-class initializer.
 

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=346554&r1=346553&r2=346554&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Fri Nov  9 12:54:06 2018
@@ -811,11 +811,28 @@ AST_MATCHER_P(Expr, ignoringParenImpCast
 ///   varDecl(hasType(pointerType(pointee(ignoringParens(functionType())
 /// \endcode
 /// would match the declaration for fp.
-AST_MATCHER_P(QualType, ignoringParens,
-  internal::Matcher, InnerMatcher) {
+AST_MATCHER_P_OVERLOAD(QualType, ignoringParens, internal::Matcher,
+   InnerMatcher, 0) {
   return InnerMatcher.matches(Node.IgnoreParens(), Finder, Builder);
 }
 
+/// Overload \c ignoringParens for \c Expr.
+///
+/// Given
+/// \code
+///   const char* str = ("my-string");
+/// \endcode
+/// The matcher
+/// \code
+///   implicitCastExpr(hasSourceExpression(ignoringParens(stringLiteral(
+/// \endcode
+/// would match the implicit cast resulting from the assignment.
+AST_MATCHER_P_OVERLOAD(Expr, ignoringParens, internal::Matcher,
+   InnerMatcher, 1) {
+  const Expr *E = Node.IgnoreParens();
+  return InnerMatcher.matches(*E, Finder, Builder);
+}
+
 /// Matches expressions that are instantiation-dependent even if it is
 /// neither type- nor value-dependent.
 ///

Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=346554&r1=346553&r2=346554&view=diff
==
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Fri Nov  9 12:54:06 2018
@@ -106,6 +106,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_OVERLOADED_2(callee);
   REGISTER_OVERLOADED_2(hasPrefix);
   REGISTER_OVERLOADED_2(hasType);
+  REGISTER_OVERLOADED_2(ignoringParens);
   REGISTER_OVERLOADED_2(isDerivedFrom);
   REGISTER_OVERLOADED_2(isSameOrDerivedFrom);
   REGISTER_OVERLOADED_2(loc);
@@ -318,7 +319,6 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(ignoringImplicit);
   REGISTER_MATCHER(ignoringParenCasts);
   REGISTER_MATCHER(ignoringParenImpCasts);
-  REGISTER_MATCHER(ignoringParens);
   REGISTER_MATCHER(imaginaryLiteral);
   REGISTER_MATCHER(implicitCastExpr);
   REGISTER_MATCHER(implicitValueInitExpr);

Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp?rev=346554&r1=346553&r2=346554&view=diff
==
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp Fri Nov  9 12:54:06 
2018
@@ -1147,6 +1147,14 @@ TEST(ParenExpression, SimpleCases) {
  parenExpr()));
 }
 
+TEST(ParenExpression, IgnoringParens) {
+  EXPECT_FALSE(matches("const char* str = (\"my-string\");",
+

[clang-tools-extra] r346555 - [clang-tidy] fix PR39583 - ignoring ParenCast for string-literals in pro-bounds-array-to-pointer-decay

2018-11-09 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Fri Nov  9 12:57:28 2018
New Revision: 346555

URL: http://llvm.org/viewvc/llvm-project?rev=346555&view=rev
Log:
[clang-tidy] fix PR39583 - ignoring ParenCast for string-literals in 
pro-bounds-array-to-pointer-decay

Summary:
The fix to the issue that `const char* p = ("foo")` is diagnosed as decay
is to ignored the ParenCast.
Resolves PR39583

Reviewers: aaron.ballman, alexfh, hokein

Reviewed By: aaron.ballman

Subscribers: nemanjai, xazax.hun, kbarton, cfe-commits

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

Modified:

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp

clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp?rev=346555&r1=346554&r2=346555&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
 Fri Nov  9 12:57:28 2018
@@ -58,10 +58,11 @@ void ProBoundsArrayToPointerDecayCheck::
   // 2) inside a range-for over an array
   // 3) if it converts a string literal to a pointer
   Finder->addMatcher(
-  implicitCastExpr(unless(hasParent(arraySubscriptExpr())),
-   unless(hasParentIgnoringImpCasts(explicitCastExpr())),
-   unless(isInsideOfRangeBeginEndStmt()),
-   unless(hasSourceExpression(stringLiteral(
+  implicitCastExpr(
+  unless(hasParent(arraySubscriptExpr())),
+  unless(hasParentIgnoringImpCasts(explicitCastExpr())),
+  unless(isInsideOfRangeBeginEndStmt()),
+  unless(hasSourceExpression(ignoringParens(stringLiteral()
   .bind("cast"),
   this);
 }

Modified: 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp?rev=346555&r1=346554&r2=346555&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp
 Fri Nov  9 12:57:28 2018
@@ -30,6 +30,7 @@ void f() {
   arrayviewfun(av); // OK
 
   int i = a[0];  // OK
+  int j = a[(1 + 2)];// OK
   pointerfun(&a[0]); // OK
 
   for (auto &e : a) // OK, iteration internally decays array to pointer
@@ -39,6 +40,9 @@ void f() {
 const char *g() {
   return "clang"; // OK, decay string literal to pointer
 }
+const char *g2() {
+return ("clang"); // OK, ParenExpr hides the literal-pointer decay
+}
 
 void f2(void *const *);
 void bug25362() {


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


[clang-tools-extra] r346665 - [clang-tidy] new check: bugprone-too-small-loop-variable

2018-11-12 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Mon Nov 12 08:01:39 2018
New Revision: 346665

URL: http://llvm.org/viewvc/llvm-project?rev=346665&view=rev
Log:
[clang-tidy] new check: bugprone-too-small-loop-variable

The new checker searches for those for loops which has a loop variable with a 
"too small" type which means this type can't represent all values which are 
part of the iteration range.

For example:

```
int main() {
  long size = 30;
  for( short int i = 0; i < size; ++i) {}
}
```

The short type leads to infinite loop here because it can't store all values in 
the `[0..size]` interval. In a real use case, size means a container's size 
which depends on the user input. Which means for small amount of objects the 
algorithm works, but with a larger user input the software will freeze.

The idea of the checker comes from the LibreOffice project, where the same 
check was implemented as a clang compiler plugin, called `LoopVarTooSmall` 
(LLVM licensed).
The idea is the same behind this check, but the code is different because of 
the different framework.

Patch by ztamas.

Reviewers: alexfh, hokein, aaron.ballman, JonasToth, xazax.hun, whisperity

Reviewed By: JonasToth, whisperity

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

Added:
clang-tools-extra/trunk/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/TooSmallLoopVariableCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-too-small-loop-variable.rst
clang-tools-extra/trunk/test/clang-tidy/bugprone-too-small-loop-variable.cpp
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=346665&r1=346664&r2=346665&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Mon Nov 
12 08:01:39 2018
@@ -44,6 +44,7 @@
 #include "SwappedArgumentsCheck.h"
 #include "TerminatingContinueCheck.h"
 #include "ThrowKeywordMissingCheck.h"
+#include "TooSmallLoopVariableCheck.h"
 #include "UndefinedMemoryManipulationCheck.h"
 #include "UndelegatedConstructorCheck.h"
 #include "UnusedRaiiCheck.h"
@@ -96,6 +97,8 @@ public:
 "bugprone-move-forwarding-reference");
 CheckFactories.registerCheck(
 "bugprone-multiple-statement-macro");
+CheckFactories.registerCheck(
+"bugprone-too-small-loop-variable");
 CheckFactories.registerCheck(
 "bugprone-narrowing-conversions");
 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=346665&r1=346664&r2=346665&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt Mon Nov 12 
08:01:39 2018
@@ -35,6 +35,7 @@ add_clang_library(clangTidyBugproneModul
   SwappedArgumentsCheck.cpp
   TerminatingContinueCheck.cpp
   ThrowKeywordMissingCheck.cpp
+  TooSmallLoopVariableCheck.cpp
   UndefinedMemoryManipulationCheck.cpp
   UndelegatedConstructorCheck.cpp
   UnusedRaiiCheck.cpp

Added: clang-tools-extra/trunk/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp?rev=346665&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp 
Mon Nov 12 08:01:39 2018
@@ -0,0 +1,168 @@
+//===--- TooSmallLoopVariableCheck.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 "TooSmallLoopVariableCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace bugprone {
+
+static constexpr llvm::StringLiteral LoopName =
+llvm::StringLiteral("forLoopName");
+static constexpr llvm::StringLiteral LoopVarName =
+llvm::StringLiteral("loopVar");
+static constexpr llvm::StringLite

[clang-tools-extra] r346676 - [clang-tidy] fix ARM tests, because int and long have same width

2018-11-12 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Mon Nov 12 09:02:05 2018
New Revision: 346676

URL: http://llvm.org/viewvc/llvm-project?rev=346676&view=rev
Log:
[clang-tidy] fix ARM tests, because int and long have same width

Modified:
clang-tools-extra/trunk/test/clang-tidy/bugprone-too-small-loop-variable.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/bugprone-too-small-loop-variable.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-too-small-loop-variable.cpp?rev=346676&r1=346675&r2=346676&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/bugprone-too-small-loop-variable.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/bugprone-too-small-loop-variable.cpp 
Mon Nov 12 09:02:05 2018
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s bugprone-too-small-loop-variable %t
+// RUN: %check_clang_tidy %s bugprone-too-small-loop-variable %t -- -- 
--target=x86_64-linux
 
 long size() { return 294967296l; }
 


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


[clang-tools-extra] r346678 - Revert "Add a test checking clang-tidy can find libc++ on Mac"

2018-11-12 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Mon Nov 12 09:22:36 2018
New Revision: 346678

URL: http://llvm.org/viewvc/llvm-project?rev=346678&view=rev
Log:
Revert "Add a test checking clang-tidy can find libc++ on Mac"

This reverts commit r346653.

Removed:

clang-tools-extra/trunk/test/clang-tidy/Inputs/mock-libcxx/include/c++/v1/mock_vector
clang-tools-extra/trunk/test/clang-tidy/clang-tidy-mac-libcxx.cpp

Removed: 
clang-tools-extra/trunk/test/clang-tidy/Inputs/mock-libcxx/include/c++/v1/mock_vector
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/Inputs/mock-libcxx/include/c%2B%2B/v1/mock_vector?rev=346677&view=auto
==
--- 
clang-tools-extra/trunk/test/clang-tidy/Inputs/mock-libcxx/include/c++/v1/mock_vector
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/Inputs/mock-libcxx/include/c++/v1/mock_vector
 (removed)
@@ -1,2 +0,0 @@
-class vector {};
-typedef vector* vector_ptr;

Removed: clang-tools-extra/trunk/test/clang-tidy/clang-tidy-mac-libcxx.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/clang-tidy-mac-libcxx.cpp?rev=346677&view=auto
==
--- clang-tools-extra/trunk/test/clang-tidy/clang-tidy-mac-libcxx.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/clang-tidy-mac-libcxx.cpp (removed)
@@ -1,17 +0,0 @@
-// Clang on MacOS can find libc++ living beside the installed compiler.
-// This test makes sure clang-tidy emulates this properly.
-//
-// RUN: rm -rf %t
-// RUN: mkdir %t
-//
-// Install the mock libc++ (simulates the libc++ directory structure).
-// RUN: cp -r %S/Inputs/mock-libcxx %t/
-//
-// Pretend clang is installed beside the mock library that we provided.
-// RUN: echo '[{"directory":"%t","command":"%t/mock-libcxx/bin/clang++ 
-stdlib=libc++ -target x86_64-apple-darwin -c test.cpp","file":"test.cpp"}]' | 
sed -e 's/\\/\//g' > %t/compile_commands.json
-// RUN: cp "%s" "%t/test.cpp"
-// RUN: clang-tidy -header-filter='.*' -system-headers 
-checks='-*,modernize-use-using'  "%t/test.cpp" | FileCheck %s
-// CHECK: mock_vector:{{[0-9]+}}:{{[0-9]+}}: warning: use 'using' instead of 
'typedef'
-
-#include 
-typedef vector* vec_ptr;


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


r347676 - Revert "[clang] - Simplify tools::SplitDebugName."

2018-11-27 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Nov 27 09:28:38 2018
New Revision: 347676

URL: http://llvm.org/viewvc/llvm-project?rev=347676&view=rev
Log:
Revert "[clang] - Simplify tools::SplitDebugName."

This reverts commit r347035 as it introduced assertion failures under
certain conditions. More information can be found here:
https://reviews.llvm.org/rL347035

Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
cfe/trunk/lib/Driver/ToolChains/CommonArgs.h
cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
cfe/trunk/lib/Driver/ToolChains/MinGW.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=347676&r1=347675&r2=347676&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Tue Nov 27 09:28:38 2018
@@ -3966,7 +3966,7 @@ void Clang::ConstructJob(Compilation &C,
   const char *SplitDWARFOut;
   if (SplitDWARF) {
 CmdArgs.push_back("-split-dwarf-file");
-SplitDWARFOut = SplitDebugName(Args, Output);
+SplitDWARFOut = SplitDebugName(Args, Input, Output);
 CmdArgs.push_back(SplitDWARFOut);
   }
 
@@ -5933,7 +5933,7 @@ void ClangAs::ConstructJob(Compilation &
   if ((getDebugFissionKind(D, Args, A) == DwarfFissionKind::Split) &&
   (T.isOSLinux() || T.isOSFuchsia())) {
 CmdArgs.push_back("-split-dwarf-file");
-CmdArgs.push_back(SplitDebugName(Args, Output));
+CmdArgs.push_back(SplitDebugName(Args, Input, Output));
   }
 
   assert(Input.isFilename() && "Invalid input.");

Modified: cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp?rev=347676&r1=347675&r2=347676&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp Tue Nov 27 09:28:38 2018
@@ -808,15 +808,26 @@ bool tools::areOptimizationsEnabled(cons
   return false;
 }
 
-const char *tools::SplitDebugName(const ArgList &Args,
+const char *tools::SplitDebugName(const ArgList &Args, const InputInfo &Input,
   const InputInfo &Output) {
   if (Arg *A = Args.getLastArg(options::OPT_gsplit_dwarf_EQ))
 if (StringRef(A->getValue()) == "single")
   return Args.MakeArgString(Output.getFilename());
 
-  SmallString<128> T(Output.getFilename());
-  llvm::sys::path::replace_extension(T, "dwo");
-  return Args.MakeArgString(T);
+  Arg *FinalOutput = Args.getLastArg(options::OPT_o);
+  if (FinalOutput && Args.hasArg(options::OPT_c)) {
+SmallString<128> T(FinalOutput->getValue());
+llvm::sys::path::replace_extension(T, "dwo");
+return Args.MakeArgString(T);
+  } else {
+// Use the compilation dir.
+SmallString<128> T(
+Args.getLastArgValue(options::OPT_fdebug_compilation_dir));
+SmallString<128> F(llvm::sys::path::stem(Input.getBaseInput()));
+llvm::sys::path::replace_extension(F, "dwo");
+T += F;
+return Args.MakeArgString(F);
+  }
 }
 
 void tools::SplitDebugInfo(const ToolChain &TC, Compilation &C, const Tool &T,

Modified: cfe/trunk/lib/Driver/ToolChains/CommonArgs.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/CommonArgs.h?rev=347676&r1=347675&r2=347676&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/CommonArgs.h (original)
+++ cfe/trunk/lib/Driver/ToolChains/CommonArgs.h Tue Nov 27 09:28:38 2018
@@ -63,7 +63,7 @@ void AddHIPLinkerScript(const ToolChain
 const Tool &T);
 
 const char *SplitDebugName(const llvm::opt::ArgList &Args,
-   const InputInfo &Output);
+   const InputInfo &Input, const InputInfo &Output);
 
 void SplitDebugInfo(const ToolChain &TC, Compilation &C, const Tool &T,
 const JobAction &JA, const llvm::opt::ArgList &Args,

Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=347676&r1=347675&r2=347676&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Tue Nov 27 09:28:38 2018
@@ -817,7 +817,7 @@ void tools::gnutools::Assembler::Constru
   if (Args.hasArg(options::OPT_gsplit_dwarf) &&
   getToolChain().getTriple().isOSLinux())
 SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output,
-   SplitDebugName(Args, Output));
+   SplitDebugName(Args, Inputs[0], Output));
 }
 
 namespace {

Modified: cfe/trunk/lib/Driver/ToolChains/MinGW.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Drive

[clang-tools-extra] r348161 - [clang-tidy] Add the abseil-duration-comparison check

2018-12-03 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Mon Dec  3 10:35:56 2018
New Revision: 348161

URL: http://llvm.org/viewvc/llvm-project?rev=348161&view=rev
Log:
[clang-tidy] Add the abseil-duration-comparison check

Summary:
This check finds instances where Duration values are being converted to a 
numeric value in a comparison expression, and suggests that the conversion 
happen on the other side of the expression to a Duration.  See documentation 
for examples.

This also shuffles some code around so that the new check may perform in sone 
step simplifications also caught by other checks.

Patch by hwright.

Reviewers: aaron.ballman, JonasToth, alexfh, hokein

Reviewed By: JonasToth

Subscribers: sammccall, Eugene.Zelenko, xazax.hun, cfe-commits, mgorny

Tags: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp
clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.h
clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.cpp
clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.h

clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-duration-comparison.rst
clang-tools-extra/trunk/test/clang-tidy/abseil-duration-comparison.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/abseil/DurationFactoryFloatCheck.cpp
clang-tools-extra/trunk/clang-tidy/abseil/DurationFactoryScaleCheck.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp?rev=348161&r1=348160&r2=348161&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp Mon Dec  3 
10:35:56 2018
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "DurationComparisonCheck.h"
 #include "DurationDivisionCheck.h"
 #include "DurationFactoryFloatCheck.h"
 #include "DurationFactoryScaleCheck.h"
@@ -27,6 +28,8 @@ namespace abseil {
 class AbseilModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"abseil-duration-comparison");
 CheckFactories.registerCheck(
 "abseil-duration-division");
 CheckFactories.registerCheck(

Modified: clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt?rev=348161&r1=348160&r2=348161&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt Mon Dec  3 
10:35:56 2018
@@ -2,9 +2,11 @@ set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyAbseilModule
   AbseilTidyModule.cpp
+  DurationComparisonCheck.cpp
   DurationDivisionCheck.cpp
   DurationFactoryFloatCheck.cpp
   DurationFactoryScaleCheck.cpp
+  DurationRewriter.cpp
   FasterStrsplitDelimiterCheck.cpp
   NoInternalDependenciesCheck.cpp
   NoNamespaceCheck.cpp

Added: clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp?rev=348161&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp Mon 
Dec  3 10:35:56 2018
@@ -0,0 +1,164 @@
+//===--- DurationComparisonCheck.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 "DurationComparisonCheck.h"
+#include "DurationRewriter.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Tooling/FixIt.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace abseil {
+
+/// Given the name of an inverse Duration function (e.g., `ToDoubleSeconds`),
+/// return its `DurationScale`, or `None` if a match is not found.
+static llvm::Optional getScaleForInverse(llvm::StringRef Name) {
+  static const llvm::DenseMap ScaleMap(
+  {{"ToDoubleHours", DurationScale::H

[clang-tools-extra] r348165 - Revert "[clang-tidy] Add the abseil-duration-comparison check"

2018-12-03 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Mon Dec  3 10:59:27 2018
New Revision: 348165

URL: http://llvm.org/viewvc/llvm-project?rev=348165&view=rev
Log:
Revert "[clang-tidy] Add the abseil-duration-comparison check"

This commit broke buildbots and needs adjustments.

Removed:
clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp
clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.h
clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.cpp
clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.h

clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-duration-comparison.rst
clang-tools-extra/trunk/test/clang-tidy/abseil-duration-comparison.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/abseil/DurationFactoryFloatCheck.cpp
clang-tools-extra/trunk/clang-tidy/abseil/DurationFactoryScaleCheck.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp?rev=348165&r1=348164&r2=348165&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp Mon Dec  3 
10:59:27 2018
@@ -10,7 +10,6 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
-#include "DurationComparisonCheck.h"
 #include "DurationDivisionCheck.h"
 #include "DurationFactoryFloatCheck.h"
 #include "DurationFactoryScaleCheck.h"
@@ -28,8 +27,6 @@ namespace abseil {
 class AbseilModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
-CheckFactories.registerCheck(
-"abseil-duration-comparison");
 CheckFactories.registerCheck(
 "abseil-duration-division");
 CheckFactories.registerCheck(

Modified: clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt?rev=348165&r1=348164&r2=348165&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt Mon Dec  3 
10:59:27 2018
@@ -2,11 +2,9 @@ set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyAbseilModule
   AbseilTidyModule.cpp
-  DurationComparisonCheck.cpp
   DurationDivisionCheck.cpp
   DurationFactoryFloatCheck.cpp
   DurationFactoryScaleCheck.cpp
-  DurationRewriter.cpp
   FasterStrsplitDelimiterCheck.cpp
   NoInternalDependenciesCheck.cpp
   NoNamespaceCheck.cpp

Removed: clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp?rev=348164&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp 
(removed)
@@ -1,164 +0,0 @@
-//===--- DurationComparisonCheck.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 "DurationComparisonCheck.h"
-#include "DurationRewriter.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Tooling/FixIt.h"
-
-using namespace clang::ast_matchers;
-
-namespace clang {
-namespace tidy {
-namespace abseil {
-
-/// Given the name of an inverse Duration function (e.g., `ToDoubleSeconds`),
-/// return its `DurationScale`, or `None` if a match is not found.
-static llvm::Optional getScaleForInverse(llvm::StringRef Name) {
-  static const llvm::DenseMap ScaleMap(
-  {{"ToDoubleHours", DurationScale::Hours},
-   {"ToInt64Hours", DurationScale::Hours},
-   {"ToDoubleMinutes", DurationScale::Minutes},
-   {"ToInt64Minutes", DurationScale::Minutes},
-   {"ToDoubleSeconds", DurationScale::Seconds},
-   {"ToInt64Seconds", DurationScale::Seconds},
-   {"ToDoubleMilliseconds", DurationScale::Milliseconds},
-   {"ToInt64Milliseconds", DurationScale::Milliseconds},
-   {"ToDoubleMicroseconds", DurationScale::Microseconds},
-   {"ToInt64Microseconds", DurationScale::Microseconds},
-   {"ToDoubleNanoseconds", DurationScale::Nanoseconds},
-   

[clang-tools-extra] r348169 - [clang-tidy] Recommit: Add the abseil-duration-comparison check

2018-12-03 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Mon Dec  3 11:22:08 2018
New Revision: 348169

URL: http://llvm.org/viewvc/llvm-project?rev=348169&view=rev
Log:
[clang-tidy] Recommit: Add the abseil-duration-comparison check

Summary:
This check finds instances where Duration values are being converted to a 
numeric value in a comparison expression, and suggests that the conversion 
happen on the other side of the expression to a Duration.  See documentation 
for examples.

This also shuffles some code around so that the new check may perform in sone 
step simplifications also caught by other checks.
Compilation is unbroken, because the hash-function is now directly
specified for std::unordered_map, as 'enum class' does not compile as
key (seamingly only on some compilers).

Patch by hwright.

Reviewers: aaron.ballman, JonasToth, alexfh, hokein

Reviewed By: JonasToth

Subscribers: sammccall, Eugene.Zelenko, xazax.hun, cfe-commits, mgorny

Tags: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp
clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.h
clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.cpp
clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.h

clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-duration-comparison.rst
clang-tools-extra/trunk/test/clang-tidy/abseil-duration-comparison.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/abseil/DurationFactoryFloatCheck.cpp
clang-tools-extra/trunk/clang-tidy/abseil/DurationFactoryScaleCheck.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp?rev=348169&r1=348168&r2=348169&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp Mon Dec  3 
11:22:08 2018
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "DurationComparisonCheck.h"
 #include "DurationDivisionCheck.h"
 #include "DurationFactoryFloatCheck.h"
 #include "DurationFactoryScaleCheck.h"
@@ -27,6 +28,8 @@ namespace abseil {
 class AbseilModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"abseil-duration-comparison");
 CheckFactories.registerCheck(
 "abseil-duration-division");
 CheckFactories.registerCheck(

Modified: clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt?rev=348169&r1=348168&r2=348169&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt Mon Dec  3 
11:22:08 2018
@@ -2,9 +2,11 @@ set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyAbseilModule
   AbseilTidyModule.cpp
+  DurationComparisonCheck.cpp
   DurationDivisionCheck.cpp
   DurationFactoryFloatCheck.cpp
   DurationFactoryScaleCheck.cpp
+  DurationRewriter.cpp
   FasterStrsplitDelimiterCheck.cpp
   NoInternalDependenciesCheck.cpp
   NoNamespaceCheck.cpp

Added: clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp?rev=348169&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp Mon 
Dec  3 11:22:08 2018
@@ -0,0 +1,165 @@
+//===--- DurationComparisonCheck.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 "DurationComparisonCheck.h"
+#include "DurationRewriter.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Tooling/FixIt.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace abseil {
+
+/// Given the name of an inverse Duration function (e.g., `ToDoubleSeconds`),
+/// return its `DurationScale

[clang-tools-extra] r348172 - [clang-tidy] Fix unordered_map failure with specializing std::hash<> and remove previous wrong attempt at doing so

2018-12-03 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Mon Dec  3 11:41:04 2018
New Revision: 348172

URL: http://llvm.org/viewvc/llvm-project?rev=348172&view=rev
Log:
[clang-tidy] Fix unordered_map failure with specializing std::hash<> and remove 
previous wrong attempt at doing so

Modified:
clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp
clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.h

Modified: clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp?rev=348172&r1=348171&r2=348172&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp Mon 
Dec  3 11:41:04 2018
@@ -47,8 +47,7 @@ static llvm::Optional get
 static const std::pair &
 getInverseForScale(DurationScale Scale) {
   static const std::unordered_map,
-  std::hash>
+  std::pair>
   InverseMap(
   {{DurationScale::Hours,
 std::make_pair("::absl::ToDoubleHours", "::absl::ToInt64Hours")},

Modified: clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.h?rev=348172&r1=348171&r2=348172&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.h (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.h Mon Dec  3 
11:41:04 2018
@@ -27,7 +27,26 @@ enum class DurationScale : std::int8_t {
   Microseconds,
   Nanoseconds,
 };
+} // namespace abseil
+} // namespace tidy
+} // namespace clang
 
+namespace std {
+template <> struct hash<::clang::tidy::abseil::DurationScale> {
+  using argument_type = ::clang::tidy::abseil::DurationScale;
+  using underlying_type = std::underlying_type::type;
+  using result_type = std::hash::result_type;
+
+  result_type operator()(const argument_type &arg) const {
+std::hash hasher;
+return hasher(static_cast(arg));
+  }
+};
+} // namespace std
+
+namespace clang {
+namespace tidy {
+namespace abseil {
 /// Given a `Scale`, return the appropriate factory function call for
 /// constructing a `Duration` for that scale.
 llvm::StringRef getFactoryForScale(DurationScale Scale);


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


[clang-tools-extra] r348341 - Fix a false positive in misplaced-widening-cast

2018-12-05 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Dec  5 00:29:56 2018
New Revision: 348341

URL: http://llvm.org/viewvc/llvm-project?rev=348341&view=rev
Log:
Fix a false positive in misplaced-widening-cast

Summary:
bugprone-misplaced-widening-cast check
used to give a false warning to the
following example.

 enum DaysEnum{
MON = 0,
TUE = 1
};

 day = (DaysEnum)(day + 1);
 //warning: either cast from 'int' to 'DaysEnum' is ineffective...

But i think int to enum cast is not widening neither ineffective.

Patch by dkrupp.

Reviewers: JonasToth, alexfh

Reviewed By: alexfh

Subscribers: rnkovacs, Szelethus, gamesh411, cfe-commits

Tags: #clang-tools-extra

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

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

clang-tools-extra/trunk/test/clang-tidy/bugprone-misplaced-widening-cast-explicit-only.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp?rev=348341&r1=348340&r2=348341&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp 
Wed Dec  5 00:29:56 2018
@@ -213,8 +213,9 @@ void MisplacedWideningCastCheck::check(c
 dyn_cast(CastType->getUnqualifiedDesugaredType());
 const auto *CalcBuiltinType =
 dyn_cast(CalcType->getUnqualifiedDesugaredType());
-if (CastBuiltinType && CalcBuiltinType &&
-!isFirstWider(CastBuiltinType->getKind(), CalcBuiltinType->getKind()))
+if (!CastBuiltinType || !CalcBuiltinType)
+  return;
+if (!isFirstWider(CastBuiltinType->getKind(), CalcBuiltinType->getKind()))
   return;
   }
 

Modified: 
clang-tools-extra/trunk/test/clang-tidy/bugprone-misplaced-widening-cast-explicit-only.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-misplaced-widening-cast-explicit-only.cpp?rev=348341&r1=348340&r2=348341&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/bugprone-misplaced-widening-cast-explicit-only.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/bugprone-misplaced-widening-cast-explicit-only.cpp
 Wed Dec  5 00:29:56 2018
@@ -62,3 +62,21 @@ template  class A {
   enum Type {};
   static char *m_fn1() { char p = (Type)(&p - m_fn1()); }
 };
+
+enum DaysEnum {
+  MON,
+  TUE,
+  WED,
+  THR,
+  FRI,
+  SAT,
+  SUN
+};
+
+// Do not warn for int to enum casts.
+void nextDay(DaysEnum day) {
+  if (day < SUN)
+day = (DaysEnum)(day + 1);
+  if (day < SUN)
+day = static_cast(day + 1);
+}


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


[clang-tools-extra] r348343 - [clang-tidy] new check: bugprone-branch-clone

2018-12-05 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Dec  5 01:16:25 2018
New Revision: 348343

URL: http://llvm.org/viewvc/llvm-project?rev=348343&view=rev
Log:
[clang-tidy] new check: bugprone-branch-clone

Summary:
Implement a check for detecting if/else if/else chains where two or more
branches are Type I clones of each other (that is, they contain identical code)
and for detecting switch statements where two or more consecutive branches are
Type I clones of each other.

Patch by donat.nagy.

Reviewers: alexfh, hokein, aaron.ballman, JonasToth

Reviewed By: JonasToth

Subscribers: MTC, lebedev.ri, whisperity, xazax.hun, Eugene.Zelenko, mgorny, 
rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/clang-tidy/bugprone/BranchCloneCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/BranchCloneCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-branch-clone.rst
clang-tools-extra/trunk/test/clang-tidy/bugprone-branch-clone.cpp
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

Added: clang-tools-extra/trunk/clang-tidy/bugprone/BranchCloneCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BranchCloneCheck.cpp?rev=348343&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/BranchCloneCheck.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BranchCloneCheck.cpp Wed Dec  5 
01:16:25 2018
@@ -0,0 +1,215 @@
+//===--- BranchCloneCheck.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 "BranchCloneCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Analysis/CloneDetection.h"
+#include "llvm/Support/Casting.h"
+
+using namespace clang;
+using namespace clang::ast_matchers;
+
+/// Returns true when the statements are Type I clones of each other.
+static bool areStatementsIdentical(const Stmt *LHS, const Stmt *RHS,
+   const ASTContext &Context) {
+  llvm::FoldingSetNodeID DataLHS, DataRHS;
+  LHS->Profile(DataLHS, Context, false);
+  RHS->Profile(DataRHS, Context, false);
+  return (DataLHS == DataRHS);
+}
+
+namespace {
+/// A branch in a switch may consist of several statements; while a branch in
+/// an if/else if/else chain is one statement (which may be a CompoundStmt).
+using SwitchBranch = llvm::SmallVector;
+} // anonymous namespace
+
+/// Determines if the bodies of two branches in a switch statements are Type I
+/// clones of each other. This function only examines the body of the branch
+/// and ignores the `case X:` or `default:` at the start of the branch.
+static bool areSwitchBranchesIdentical(const SwitchBranch LHS,
+   const SwitchBranch RHS,
+   const ASTContext &Context) {
+  if (LHS.size() != RHS.size())
+return false;
+
+  for (size_t i = 0, Size = LHS.size(); i < Size; i++) {
+// NOTE: We strip goto labels and annotations in addition to stripping
+// the `case X:` or `default:` labels, but it is very unlikely that this
+// would casue false positives in real-world code.
+if (!areStatementsIdentical(LHS[i]->stripLabelLikeStatements(),
+RHS[i]->stripLabelLikeStatements(), Context)) {
+  return false;
+}
+  }
+
+  return true;
+}
+
+namespace clang {
+namespace tidy {
+namespace bugprone {
+
+void BranchCloneCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  ifStmt(stmt().bind("if"),
+ hasParent(stmt(unless(ifStmt(hasElse(equalsBoundNode("if")),
+ hasElse(stmt().bind("else"))),
+  this);
+  Finder->addMatcher(switchStmt().bind("switch"), this);
+  Finder->addMatcher(conditionalOperator().bind("condOp"), this);
+}
+
+void BranchCloneCheck::check(const MatchFinder::MatchResult &Result) {
+  const ASTContext &Context = *Result.Context;
+
+  if (const auto *IS = Result.Nodes.getNodeAs("if")) {
+const Stmt *Then = IS->getThen();
+assert(Then && "An IfStmt must have a `then` branch!");
+
+const Stmt *Else = Result.Nodes.getNodeAs("else");
+assert(Else && "We only look for `if` statements with an `else` branch!");
+
+if (!isa(Else)) {
+  // Just a simple if with no `else if` branch.
+  if (areStatementsIdentical(Then->IgnoreContainers(),
+ Else-

[clang-tools-extra] r348344 - Revert "[clang-tidy] new check: bugprone-branch-clone"

2018-12-05 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Dec  5 01:34:18 2018
New Revision: 348344

URL: http://llvm.org/viewvc/llvm-project?rev=348344&view=rev
Log:
Revert "[clang-tidy] new check: bugprone-branch-clone"

The patch broke on buildbot with assertion-failure. Revert until this
is figured out.

Removed:
clang-tools-extra/trunk/clang-tidy/bugprone/BranchCloneCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/BranchCloneCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-branch-clone.rst
clang-tools-extra/trunk/test/clang-tidy/bugprone-branch-clone.cpp
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

Removed: clang-tools-extra/trunk/clang-tidy/bugprone/BranchCloneCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BranchCloneCheck.cpp?rev=348343&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/BranchCloneCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BranchCloneCheck.cpp (removed)
@@ -1,215 +0,0 @@
-//===--- BranchCloneCheck.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 "BranchCloneCheck.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Analysis/CloneDetection.h"
-#include "llvm/Support/Casting.h"
-
-using namespace clang;
-using namespace clang::ast_matchers;
-
-/// Returns true when the statements are Type I clones of each other.
-static bool areStatementsIdentical(const Stmt *LHS, const Stmt *RHS,
-   const ASTContext &Context) {
-  llvm::FoldingSetNodeID DataLHS, DataRHS;
-  LHS->Profile(DataLHS, Context, false);
-  RHS->Profile(DataRHS, Context, false);
-  return (DataLHS == DataRHS);
-}
-
-namespace {
-/// A branch in a switch may consist of several statements; while a branch in
-/// an if/else if/else chain is one statement (which may be a CompoundStmt).
-using SwitchBranch = llvm::SmallVector;
-} // anonymous namespace
-
-/// Determines if the bodies of two branches in a switch statements are Type I
-/// clones of each other. This function only examines the body of the branch
-/// and ignores the `case X:` or `default:` at the start of the branch.
-static bool areSwitchBranchesIdentical(const SwitchBranch LHS,
-   const SwitchBranch RHS,
-   const ASTContext &Context) {
-  if (LHS.size() != RHS.size())
-return false;
-
-  for (size_t i = 0, Size = LHS.size(); i < Size; i++) {
-// NOTE: We strip goto labels and annotations in addition to stripping
-// the `case X:` or `default:` labels, but it is very unlikely that this
-// would casue false positives in real-world code.
-if (!areStatementsIdentical(LHS[i]->stripLabelLikeStatements(),
-RHS[i]->stripLabelLikeStatements(), Context)) {
-  return false;
-}
-  }
-
-  return true;
-}
-
-namespace clang {
-namespace tidy {
-namespace bugprone {
-
-void BranchCloneCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(
-  ifStmt(stmt().bind("if"),
- hasParent(stmt(unless(ifStmt(hasElse(equalsBoundNode("if")),
- hasElse(stmt().bind("else"))),
-  this);
-  Finder->addMatcher(switchStmt().bind("switch"), this);
-  Finder->addMatcher(conditionalOperator().bind("condOp"), this);
-}
-
-void BranchCloneCheck::check(const MatchFinder::MatchResult &Result) {
-  const ASTContext &Context = *Result.Context;
-
-  if (const auto *IS = Result.Nodes.getNodeAs("if")) {
-const Stmt *Then = IS->getThen();
-assert(Then && "An IfStmt must have a `then` branch!");
-
-const Stmt *Else = Result.Nodes.getNodeAs("else");
-assert(Else && "We only look for `if` statements with an `else` branch!");
-
-if (!isa(Else)) {
-  // Just a simple if with no `else if` branch.
-  if (areStatementsIdentical(Then->IgnoreContainers(),
- Else->IgnoreContainers(), Context)) {
-diag(IS->getBeginLoc(), "if with identical then and else branches");
-diag(IS->getElseLoc(), "else branch starts here", DiagnosticIDs::Note);
-  }
-  return;
-}
-
-// This is the complicated case when we start an if/else if/else chain.
-// To find all the duplicates, we collect all the branches into a vector.
-llvm::SmallVector Branches;
-const IfStmt *Cur = IS;
-while (true) {
-  // Store the `then` branch

[clang-tools-extra] r348793 - [clang-tidy] insert release notes for new checkers alphabetically

2018-12-10 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Mon Dec 10 11:41:53 2018
New Revision: 348793

URL: http://llvm.org/viewvc/llvm-project?rev=348793&view=rev
Log:
[clang-tidy]  insert release notes for new checkers alphabetically

Summary:
Almost all code review comments on new checkers {D55433} {D48866} {D54349} seem 
to ask for the release notes to be added alphabetically, plus I've seen commits 
by @Eugene.Zelenko reordering the lists

Make add_new_check.py add those release notes alphabetically based on checker 
name

If include-fixer section is seen add it at the end

Minor change in the message format to prevent double newlines added before the 
checker.

Do the tools themselves have unit tests? (sorry new to this game)

- Tested adding new checker at the beginning
- Tested on adding new checker in the middle
- Tested on empty ReleasesNotes.rst (as we would see after RC)

Patch by MyDeveloperDay.

Reviewers: alexfh, JonasToth, curdeius, aaron.ballman, benhamilton, hokein

Reviewed By: JonasToth

Subscribers: cfe-commits, xazax.hun, Eugene.Zelenko

Tags: #clang-tools-extra

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

Modified:
clang-tools-extra/trunk/clang-tidy/add_new_check.py

Modified: clang-tools-extra/trunk/clang-tidy/add_new_check.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/add_new_check.py?rev=348793&r1=348792&r2=348793&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/add_new_check.py (original)
+++ clang-tools-extra/trunk/clang-tidy/add_new_check.py Mon Dec 10 11:41:53 2018
@@ -200,23 +200,47 @@ def add_release_notes(module_path, modul
   with open(filename, 'r') as f:
 lines = f.readlines()
 
+  lineMatcher = re.compile('Improvements to clang-tidy')
+  nextSectionMatcher = re.compile('Improvements to include-fixer')
+  checkerMatcher = re.compile('- New :doc:`(.*)')
+
   print('Updating %s...' % filename)
   with open(filename, 'w') as f:
 note_added = False
 header_found = False
+next_header_found = False
+add_note_here = False
 
 for line in lines:
   if not note_added:
-match = re.search('Improvements to clang-tidy', line)
+match = lineMatcher.match(line)
+match_next = nextSectionMatcher.match(line)
+match_checker = checkerMatcher.match(line)
+if match_checker:
+  last_checker = match_checker.group(1)
+  if last_checker > check_name_dashes:
+add_note_here = True
+
+if match_next:
+  next_header_found = True
+  add_note_here = True
+
 if match:
   header_found = True
-elif header_found:
+  f.write(line)
+  continue
+
+if line.startswith(''):
+  f.write(line)
+  continue
+
+if header_found and add_note_here:
   if not line.startswith(''):
-f.write("""
-- New :doc:`%s
+f.write("""- New :doc:`%s
   ` check.
 
   FIXME: add release notes.
+
 """ % (check_name_dashes, check_name_dashes))
 note_added = True
 


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


[clang-tools-extra] r348840 - [clang-tidy] NFC Consolidate test absl::Time implementation

2018-12-11 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Dec 11 04:42:17 2018
New Revision: 348840

URL: http://llvm.org/viewvc/llvm-project?rev=348840&view=rev
Log:
[clang-tidy] NFC Consolidate test absl::Time implementation

Summary: Several tests re-implement these same prototypes (differently), so we 
can put them in a common location.

Patch by hwright.

Reviewers: JonasToth

Reviewed By: JonasToth

Tags: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/time/
clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/time/time.h
Modified:
clang-tools-extra/trunk/test/clang-tidy/abseil-duration-comparison.cpp
clang-tools-extra/trunk/test/clang-tidy/abseil-duration-factory-float.cpp
clang-tools-extra/trunk/test/clang-tidy/abseil-duration-factory-scale.cpp

clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp

Added: clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/time/time.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/time/time.h?rev=348840&view=auto
==
--- clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/time/time.h (added)
+++ clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/time/time.h Tue Dec 11 
04:42:17 2018
@@ -0,0 +1,72 @@
+// Mimic the implementation of absl::Duration
+namespace absl {
+
+using int64_t = long long int;
+
+class Duration {
+public:
+  Duration &operator*=(int64_t r);
+  Duration &operator*=(float r);
+  Duration &operator*=(double r);
+  template  Duration &operator*=(T r);
+
+  Duration &operator/=(int64_t r);
+  Duration &operator/=(float r);
+  Duration &operator/=(double r);
+  template  Duration &operator/=(T r);
+};
+
+template  Duration operator*(Duration lhs, T rhs);
+template  Duration operator*(T lhs, Duration rhs);
+template  Duration operator/(Duration lhs, T rhs);
+
+class Time{};
+
+constexpr Duration Nanoseconds(long long);
+constexpr Duration Microseconds(long long);
+constexpr Duration Milliseconds(long long);
+constexpr Duration Seconds(long long);
+constexpr Duration Minutes(long long);
+constexpr Duration Hours(long long);
+
+template  struct EnableIfFloatImpl {};
+template <> struct EnableIfFloatImpl { typedef int Type; };
+template <> struct EnableIfFloatImpl { typedef int Type; };
+template <> struct EnableIfFloatImpl { typedef int Type; };
+template  using EnableIfFloat = typename 
EnableIfFloatImpl::Type;
+
+template  = 0> Duration Nanoseconds(T n);
+template  = 0> Duration Microseconds(T n);
+template  = 0> Duration Milliseconds(T n);
+template  = 0> Duration Seconds(T n);
+template  = 0> Duration Minutes(T n);
+template  = 0> Duration Hours(T n);
+
+double ToDoubleHours(Duration d);
+double ToDoubleMinutes(Duration d);
+double ToDoubleSeconds(Duration d);
+double ToDoubleMilliseconds(Duration d);
+double ToDoubleMicroseconds(Duration d);
+double ToDoubleNanoseconds(Duration d);
+int64_t ToInt64Hours(Duration d);
+int64_t ToInt64Minutes(Duration d);
+int64_t ToInt64Seconds(Duration d);
+int64_t ToInt64Milliseconds(Duration d);
+int64_t ToInt64Microseconds(Duration d);
+int64_t ToInt64Nanoseconds(Duration d);
+
+// Relational Operators
+constexpr bool operator<(Duration lhs, Duration rhs);
+constexpr bool operator>(Duration lhs, Duration rhs);
+constexpr bool operator>=(Duration lhs, Duration rhs);
+constexpr bool operator<=(Duration lhs, Duration rhs);
+constexpr bool operator==(Duration lhs, Duration rhs);
+constexpr bool operator!=(Duration lhs, Duration rhs);
+
+// Additive Operators
+inline Time operator+(Time lhs, Duration rhs);
+inline Time operator+(Duration lhs, Time rhs);
+inline Time operator-(Time lhs, Duration rhs);
+inline Duration operator-(Time lhs, Time rhs);
+
+}  // namespace absl

Modified: clang-tools-extra/trunk/test/clang-tidy/abseil-duration-comparison.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/abseil-duration-comparison.cpp?rev=348840&r1=348839&r2=348840&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/abseil-duration-comparison.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/abseil-duration-comparison.cpp Tue 
Dec 11 04:42:17 2018
@@ -1,62 +1,6 @@
-// RUN: %check_clang_tidy %s abseil-duration-comparison %t
+// RUN: %check_clang_tidy %s abseil-duration-comparison %t -- -- -I%S/Inputs
 
-// Mimic the implementation of absl::Duration
-namespace absl {
-
-class Duration {};
-class Time{};
-
-Duration Nanoseconds(long long);
-Duration Microseconds(long long);
-Duration Milliseconds(long long);
-Duration Seconds(long long);
-Duration Minutes(long long);
-Duration Hours(long long);
-
-#define GENERATE_DURATION_FACTORY_OVERLOADS(NAME) \
-  Duration NAME(float n); \
-  Duration NAME(double n);\
-  template

[clang-tools-extra] r348842 - Use the standard Duration factory matcher

2018-12-11 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Dec 11 04:45:51 2018
New Revision: 348842

URL: http://llvm.org/viewvc/llvm-project?rev=348842&view=rev
Log:
Use the standard Duration factory matcher

Summary: A new check came in over the weekend; it should use our existing 
infrastructure for matching `absl::Duration` factories.

Patch by hwright.

Reviewers: JonasToth

Reviewed By: JonasToth

Subscribers: astrelni

Tags: #clang-tools-extra

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

Modified:

clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp?rev=348842&r1=348841&r2=348842&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp 
Tue Dec 11 04:45:51 2018
@@ -8,6 +8,7 @@
 
//===--===//
 
 #include "UpgradeDurationConversionsCheck.h"
+#include "DurationRewriter.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 
@@ -102,10 +103,7 @@ void UpgradeDurationConversionsCheck::re
   anyOf(hasCastKind(CK_UserDefinedConversion),
 has(implicitCastExpr(hasCastKind(CK_UserDefinedConversion,
   hasParent(callExpr(
-  callee(functionDecl(
-  hasAnyName("::absl::Nanoseconds", "::absl::Microseconds",
- "::absl::Milliseconds", "::absl::Seconds",
- "::absl::Minutes", "::absl::Hours"),
+  callee(functionDecl(DurationFactoryFunction(),
   unless(hasParent(functionTemplateDecl(),
   hasArgument(0, expr().bind("arg"),
   this);


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


[clang-tools-extra] r354903 - [clang-tidy] undo bitfields in ExceptionAnalyzer

2019-02-26 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Feb 26 10:15:17 2019
New Revision: 354903

URL: http://llvm.org/viewvc/llvm-project?rev=354903&view=rev
Log:
[clang-tidy] undo bitfields in ExceptionAnalyzer

Scoped enums do induce some problems with some MSVC and GCC versions
if used as bitfields. Therefor this is deactivated for now.

Modified:
clang-tools-extra/trunk/clang-tidy/utils/ExceptionAnalyzer.h

Modified: clang-tools-extra/trunk/clang-tidy/utils/ExceptionAnalyzer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/ExceptionAnalyzer.h?rev=354903&r1=354902&r2=354903&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/utils/ExceptionAnalyzer.h (original)
+++ clang-tools-extra/trunk/clang-tidy/utils/ExceptionAnalyzer.h Tue Feb 26 
10:15:17 2019
@@ -109,19 +109,17 @@ public:
 
 /// Keep track if the entity related to this 'ExceptionInfo' can in 
princple
 /// throw, if it's unknown or if it won't throw.
-State Behaviour : 2;
+State Behaviour;
 
 /// Keep track if the entity contains any unknown elements to keep track
 /// of the certainty of decisions and/or correct 'Behaviour' transition
 /// after filtering.
-bool ContainsUnknown : 1;
+bool ContainsUnknown;
 
 /// 'ThrownException' is empty if the 'Behaviour' is either 'NotThrowing' 
or
 /// 'Unknown'.
 Throwables ThrownExceptions;
   };
-  static_assert(sizeof(ExceptionInfo) <= 64u,
-"size of exceptioninfo shall be at max one cache line");
 
   ExceptionAnalyzer() = default;
 


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


[clang-tools-extra] r355093 - [clang-tidy] added cppcoreguidelines-explicit-virtual-functions

2019-02-28 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Thu Feb 28 06:55:12 2019
New Revision: 355093

URL: http://llvm.org/viewvc/llvm-project?rev=355093&view=rev
Log:
[clang-tidy] added cppcoreguidelines-explicit-virtual-functions

Addresses the bugzilla bug #30397. (https://bugs.llvm.org/show_bug.cgi?id=30397)
modernize-use-override suggests that destructors require the override specifier
and the CPP core guidelines do not recommend this.

Patch by lewmpk.

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

Added:

clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-explicit-virtual-functions.rst

clang-tools-extra/trunk/test/clang-tidy/modernize-use-override-no-destructors.cpp
Modified:

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.h
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-override.rst

Modified: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp?rev=355093&r1=355092&r2=355093&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 Thu Feb 28 06:55:12 2019
@@ -12,6 +12,7 @@
 #include "../misc/NonPrivateMemberVariablesInClassesCheck.h"
 #include "../misc/UnconventionalAssignOperatorCheck.h"
 #include "../modernize/AvoidCArraysCheck.h"
+#include "../modernize/UseOverrideCheck.h"
 #include "../readability/MagicNumbersCheck.h"
 #include "AvoidGotoCheck.h"
 #include "InterfacesGlobalInitCheck.h"
@@ -46,6 +47,8 @@ public:
 "cppcoreguidelines-avoid-goto");
 CheckFactories.registerCheck(
 "cppcoreguidelines-avoid-magic-numbers");
+CheckFactories.registerCheck(
+"cppcoreguidelines-explicit-virtual-functions");
 CheckFactories.registerCheck(
 "cppcoreguidelines-interfaces-global-init");
 CheckFactories.registerCheck(
@@ -91,6 +94,9 @@ public:
 Opts["cppcoreguidelines-non-private-member-variables-in-classes."
  "IgnoreClassesWithAllMemberVariablesBeingPublic"] = "1";
 
+Opts["cppcoreguidelines-explicit-virtual-functions."
+ "IgnoreDestructors"] = "1";
+
 return Options;
   }
 };

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp?rev=355093&r1=355092&r2=355093&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp Thu Feb 
28 06:55:12 2019
@@ -17,9 +17,20 @@ namespace clang {
 namespace tidy {
 namespace modernize {
 
+void UseOverrideCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IgnoreDestructors", IgnoreDestructors);
+}
+
 void UseOverrideCheck::registerMatchers(MatchFinder *Finder) {
   // Only register the matcher for C++11.
-  if (getLangOpts().CPlusPlus11)
+  if (!getLangOpts().CPlusPlus11)
+return;
+
+  if (IgnoreDestructors)
+Finder->addMatcher(
+cxxMethodDecl(isOverride(), 
unless(cxxDestructorDecl())).bind("method"),
+this);
+  else
 Finder->addMatcher(cxxMethodDecl(isOverride()).bind("method"), this);
 }
 

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.h?rev=355093&r1=355092&r2=355093&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.h Thu Feb 28 
06:55:12 2019
@@ -19,9 +19,14 @@ namespace modernize {
 class UseOverrideCheck : public ClangTidyCheck {
 public:
   UseOverrideCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  : ClangTidyCheck(Name, Context),
+IgnoreDestructors(Options.get("IgnoreDestructors", false)) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+
+private:
+  const bool IgnoreDestructors;
 };
 
 } // namespace modernize

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=355093&r1=355092&

[clang-tools-extra] r355094 - [clang-tidy] attempt to fix documentation build-error

2019-02-28 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Thu Feb 28 07:01:17 2019
New Revision: 355094

URL: http://llvm.org/viewvc/llvm-project?rev=355094&view=rev
Log:
[clang-tidy] attempt to fix documentation build-error

Modified:
clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-time-subtraction.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-time-subtraction.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-time-subtraction.rst?rev=355094&r1=355093&r2=355094&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-time-subtraction.rst 
(original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-time-subtraction.rst 
Thu Feb 28 07:01:17 2019
@@ -8,9 +8,10 @@ in the Time domain instead of the numeri
 
 There are two cases of Time subtraction in which deduce additional type
 information:
- - When the result is an ``absl::Duration`` and the first argument is an
-   ``absl::Time``.
- - When the second argument is a ``absl::Time``.
+
+- When the result is an ``absl::Duration`` and the first argument is an
+  ``absl::Time``.
+- When the second argument is a ``absl::Time``.
 
 In the first case, we must know the result of the operation, since without that
 the second operand could be either an ``absl::Time`` or an ``absl::Duration``.


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


[clang-tools-extra] r355095 - [clang-tidy] another issue in documentation, double empty line seemed to confuse code-block

2019-02-28 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Thu Feb 28 07:18:54 2019
New Revision: 355095

URL: http://llvm.org/viewvc/llvm-project?rev=355095&view=rev
Log:
[clang-tidy] another issue in documentation, double empty line seemed to 
confuse code-block

Modified:

clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-duration-subtraction.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-duration-subtraction.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-duration-subtraction.rst?rev=355095&r1=355094&r2=355095&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-duration-subtraction.rst 
(original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-duration-subtraction.rst 
Thu Feb 28 07:18:54 2019
@@ -21,7 +21,6 @@ Examples:
   // Suggestion - Subtraction in the absl::Duration domain instead
   double result = absl::ToDoubleSeconds(d - absl::Seconds(x));
 
-
   // Original - Subtraction of two Durations in the double domain
   absl::Duration d1, d2;
   double result = absl::ToDoubleSeconds(d1) - absl::ToDoubleSeconds(d2);


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


[clang-tools-extra] r355097 - [clang-tidy] tryfix documenation continued

2019-02-28 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Thu Feb 28 07:28:36 2019
New Revision: 355097

URL: http://llvm.org/viewvc/llvm-project?rev=355097&view=rev
Log:
[clang-tidy] tryfix documenation continued

Modified:

clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-duration-subtraction.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-duration-subtraction.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-duration-subtraction.rst?rev=355097&r1=355096&r2=355097&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-duration-subtraction.rst 
(original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-duration-subtraction.rst 
Thu Feb 28 07:28:36 2019
@@ -28,6 +28,7 @@ Examples:
   // Suggestion - Subtraction in the absl::Duration domain instead
   double result = absl::ToDoubleSeconds(d1 - d2);
 
+
 Note: As with other ``clang-tidy`` checks, it is possible that multiple fixes
 may overlap (as in the case of nested expressions), so not all occurences can
 be transformed in one run. In particular, this may occur for nested subtraction


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


[clang-tools-extra] r355098 - [clang-tidy] documentation fixing the actual correct file

2019-02-28 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Thu Feb 28 07:39:47 2019
New Revision: 355098

URL: http://llvm.org/viewvc/llvm-project?rev=355098&view=rev
Log:
[clang-tidy] documentation fixing the actual correct file

Modified:
clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-time-subtraction.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-time-subtraction.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-time-subtraction.rst?rev=355098&r1=355097&r2=355098&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-time-subtraction.rst 
(original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-time-subtraction.rst 
Thu Feb 28 07:39:47 2019
@@ -21,6 +21,7 @@ subtracting an ``absl::Time`` from an ``
 Examples:
 
 .. code-block:: c++
+
   int x;
   absl::Time t;
 


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


[clang-tools-extra] r355100 - [clang-tidy] include cppcoreguidelines-explicit-virtual-functions in list of checks and fix redirection

2019-02-28 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Thu Feb 28 07:47:10 2019
New Revision: 355100

URL: http://llvm.org/viewvc/llvm-project?rev=355100&view=rev
Log:
[clang-tidy] include cppcoreguidelines-explicit-virtual-functions in list of 
checks and fix redirection

Modified:

clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-explicit-virtual-functions.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-explicit-virtual-functions.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-explicit-virtual-functions.rst?rev=355100&r1=355099&r2=355100&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-explicit-virtual-functions.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-explicit-virtual-functions.rst
 Thu Feb 28 07:47:10 2019
@@ -1,6 +1,6 @@
 .. title:: clang-tidy - cppcoreguidelines-explicit-virtual-functions
 .. meta::
-   :http-equiv=refresh: 5;URL=cppcoreguidelines-explicit-virtual-functions.html
+   :http-equiv=refresh: 5;URL=modernize-use-override.html
 
 cppcoreguidelines-explicit-virtual-functions
 

Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst?rev=355100&r1=355099&r2=355100&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst Thu Feb 28 07:47:10 
2019
@@ -99,6 +99,7 @@ Clang-Tidy Checks
cppcoreguidelines-avoid-goto
cppcoreguidelines-avoid-magic-numbers (redirects to 
readability-magic-numbers) 
cppcoreguidelines-c-copy-assignment-signature (redirects to 
misc-unconventional-assign-operator) 

+   cppcoreguidelines-explicit-virtual-functions (redirects to 
modernize-use-override) 
cppcoreguidelines-interfaces-global-init
cppcoreguidelines-macro-usage
cppcoreguidelines-narrowing-conversions


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


[clang-tools-extra] r355102 - [clang-tidy] redirection in list of checks adjusted

2019-02-28 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Thu Feb 28 07:56:40 2019
New Revision: 355102

URL: http://llvm.org/viewvc/llvm-project?rev=355102&view=rev
Log:
[clang-tidy] redirection in list of checks adjusted

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

Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst?rev=355102&r1=355101&r2=355102&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst Thu Feb 28 07:56:40 
2019
@@ -99,7 +99,7 @@ Clang-Tidy Checks
cppcoreguidelines-avoid-goto
cppcoreguidelines-avoid-magic-numbers (redirects to 
readability-magic-numbers) 
cppcoreguidelines-c-copy-assignment-signature (redirects to 
misc-unconventional-assign-operator) 

-   cppcoreguidelines-explicit-virtual-functions (redirects to 
modernize-use-override) 
+   cppcoreguidelines-explicit-virtual-functions (redirects to 
modernize-use-override) 
cppcoreguidelines-interfaces-global-init
cppcoreguidelines-macro-usage
cppcoreguidelines-narrowing-conversions


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


[clang-tools-extra] r355108 - [clang-tidy] fix documentation link in list of clang-tidy checks

2019-02-28 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Thu Feb 28 09:53:51 2019
New Revision: 355108

URL: http://llvm.org/viewvc/llvm-project?rev=355108&view=rev
Log:
[clang-tidy] fix documentation link in list of clang-tidy checks

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

Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst?rev=355108&r1=355107&r2=355108&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst Thu Feb 28 09:53:51 
2019
@@ -99,7 +99,7 @@ Clang-Tidy Checks
cppcoreguidelines-avoid-goto
cppcoreguidelines-avoid-magic-numbers (redirects to 
readability-magic-numbers) 
cppcoreguidelines-c-copy-assignment-signature (redirects to 
misc-unconventional-assign-operator) 

-   cppcoreguidelines-explicit-virtual-functions (redirects to 
modernize-use-override) 
+   cppcoreguidelines-explicit-virtual-functions (redirects to 
modernize-use-override) 
cppcoreguidelines-interfaces-global-init
cppcoreguidelines-macro-usage
cppcoreguidelines-narrowing-conversions


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


[clang-tools-extra] r342393 - [clang-tidy] fix PR37913, templated exception factory diagnosed correctly

2018-09-17 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Mon Sep 17 06:55:10 2018
New Revision: 342393

URL: http://llvm.org/viewvc/llvm-project?rev=342393&view=rev
Log:
[clang-tidy] fix PR37913, templated exception factory diagnosed correctly

Summary:
PR37913 documents wrong behaviour for a templated exception factory function.
The check does misidentify dependent types as not derived from std::exception.

The fix to this problem is to ignore dependent types, the analysis works 
correctly
on the instantiated function.

Reviewers: aaron.ballman, alexfh, hokein, ilya-biryukov

Reviewed By: alexfh

Subscribers: lebedev.ri, nemanjai, mgorny, kbarton, xazax.hun, cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/hicpp-exception-baseclass.cpp

Modified: clang-tools-extra/trunk/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp?rev=342393&r1=342392&r2=342393&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp Mon 
Sep 17 06:55:10 2018
@@ -22,26 +22,44 @@ void ExceptionBaseclassCheck::registerMa
 return;
 
   Finder->addMatcher(
-  cxxThrowExpr(allOf(has(expr(unless(hasType(qualType(hasCanonicalType(
- hasDeclaration(cxxRecordDecl(isSameOrDerivedFrom(
- hasName("std::exception")),
- has(expr(unless(cxxUnresolvedConstructExpr(,
- eachOf(has(expr(hasType(namedDecl().bind("decl",
-anything(
+  cxxThrowExpr(
+  allOf(
+  unless(has(expr(anyOf(isTypeDependent(), isValueDependent(),
+  // The thrown value is not derived from 'std::exception'.
+  has(expr(unless(hasType(
+  qualType(hasCanonicalType(hasDeclaration(cxxRecordDecl(
+  isSameOrDerivedFrom(hasName("::std::exception")),
+  // This condition is always true, but will bind to the
+  // template value if the thrown type is templated.
+  anyOf(has(expr(hasType(
+substTemplateTypeParmType().bind("templ_type",
+anything()),
+  // Bind to the declaration of the type of the value that
+  // is thrown. 'anything()' is necessary to always suceed
+  // in the 'eachOf' because builtin types are not
+  // 'namedDecl'.
+  eachOf(has(expr(hasType(namedDecl().bind("decl", 
anything(
   .bind("bad_throw"),
   this);
 }
 
 void ExceptionBaseclassCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *BadThrow = Result.Nodes.getNodeAs("bad_throw");
+  assert(BadThrow && "Did not match the throw expression");
 
   diag(BadThrow->getSubExpr()->getBeginLoc(), "throwing an exception whose "
   "type %0 is not derived from "
   "'std::exception'")
   << BadThrow->getSubExpr()->getType() << BadThrow->getSourceRange();
 
-  const auto *TypeDecl = Result.Nodes.getNodeAs("decl");
-  if (TypeDecl != nullptr)
+  if (const auto *Template =
+  Result.Nodes.getNodeAs("templ_type"))
+diag(BadThrow->getSubExpr()->getBeginLoc(),
+ "type %0 is a template instantiation of %1", DiagnosticIDs::Note)
+<< BadThrow->getSubExpr()->getType()
+<< Template->getReplacedParameter()->getDecl();
+
+  if (const auto *TypeDecl = Result.Nodes.getNodeAs("decl"))
 diag(TypeDecl->getBeginLoc(), "type defined here", DiagnosticIDs::Note);
 }
 

Modified: clang-tools-extra/trunk/test/clang-tidy/hicpp-exception-baseclass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/hicpp-exception-baseclass.cpp?rev=342393&r1=342392&r2=342393&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/hicpp-exception-baseclass.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/hicpp-exception-baseclass.cpp Mon 
Sep 17 06:55:10 2018
@@ -2,6 +2,7 @@
 
 namespace std {
 class exception {};
+class invalid_argument : public exception {};
 } // namespace std
 
 class derived_exception : public std::exception {};
@@ -36,12 +37,12 @@ void problematic() {
   try {
 throw non_derived_exception();
 // CHECK-NOTES: [[@LINE-1]]:11: warning: throwing an exception whose type 
'non_derived_exception' is not derived from 'std::exception'
-// CHECK-NOTES: 9:1: note: type defined here
+// CHECK-NOTES: 10:1: note: type defined here
   } catch (non_deriv

[clang-tools-extra] r342458 - [clang-tidy] use CHECK-NOTES in tests for bugprone-argument-comment

2018-09-18 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Sep 18 03:15:15 2018
New Revision: 342458

URL: http://llvm.org/viewvc/llvm-project?rev=342458&view=rev
Log:
[clang-tidy] use CHECK-NOTES in tests for bugprone-argument-comment

Summary:
This patch uses CHECK-NOTES for the tests.
Its part of an effort to test *ALL* generated diagnostics in clang-tidy,
as emitted notes were previously ignored.

Reviewers: alexfh, aaron.ballman, hokein

Reviewed By: alexfh

Subscribers: xazax.hun, cfe-commits

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

Modified:
clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-gmock.cpp
clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-strict.cpp
clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-gmock.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-gmock.cpp?rev=342458&r1=342457&r2=342458&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-gmock.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-gmock.cpp 
Tue Sep 18 03:15:15 2018
@@ -83,17 +83,41 @@ class MockStandalone {
 void test_gmock_expectations() {
   MockDerived m;
   EXPECT_CALL(m, Method(/*param_one=*/1, /*param_tw=*/2));
-// CHECK-MESSAGES: [[@LINE-1]]:42: warning: argument name 'param_tw' in 
comment does not match parameter name 'param_two'
+// CHECK-NOTES: [[@LINE-1]]:42: warning: argument name 'param_tw' in comment 
does not match parameter name 'param_two'
+// CHECK-NOTES: [[@LINE-2]]:42: note: FIX-IT applied suggested code changes
+// CHECK-NOTES: [[@LINE-19]]:42: note: 'param_two' declared here
+// CHECK-NOTES: [[@LINE-15]]:3: note: actual callee ('gmock_Method') is 
declared here
+// CHECK-NOTES: [[@LINE-33]]:30: note: expanded from macro 'MOCK_METHOD2'
+// CHECK-NOTES: [[@LINE-36]]:7: note: expanded from macro 'GMOCK_METHOD2_'
+// CHECK-NOTES: note: expanded from here
 // CHECK-FIXES:   EXPECT_CALL(m, Method(/*param_one=*/1, /*param_two=*/2));
   EXPECT_CALL(m, Method2(/*p_on=*/3, /*p_two=*/4));
-// CHECK-MESSAGES: [[@LINE-1]]:26: warning: argument name 'p_on' in comment 
does not match parameter name 'p_one'
+// CHECK-NOTES: [[@LINE-1]]:26: warning: argument name 'p_on' in comment does 
not match parameter name 'p_one'
+// CHECK-NOTES: [[@LINE-2]]:26: note: FIX-IT applied suggested code changes
+// CHECK-NOTES: [[@LINE-27]]:28: note: 'p_one' declared here
+// CHECK-NOTES: [[@LINE-23]]:3: note: actual callee ('gmock_Method2') is 
declared here
+// CHECK-NOTES: [[@LINE-41]]:36: note: expanded from macro 'MOCK_CONST_METHOD2'
+// CHECK-NOTES: [[@LINE-45]]:7: note: expanded from macro 'GMOCK_METHOD2_'
+// CHECK-NOTES: note: expanded from here
 // CHECK-FIXES:   EXPECT_CALL(m, Method2(/*p_one=*/3, /*p_two=*/4));
 
   #define PARAM1 11
   #define PARAM2 22
   EXPECT_CALL(m, Method2(/*p_on1=*/PARAM1, /*p_tw2=*/PARAM2));
-// CHECK-MESSAGES: [[@LINE-1]]:26: warning: argument name 'p_on1' in comment 
does not match parameter name 'p_one'
-// CHECK-MESSAGES: [[@LINE-2]]:44: warning: argument name 'p_tw2' in comment 
does not match parameter name 'p_two'
+// CHECK-NOTES: [[@LINE-1]]:26: warning: argument name 'p_on1' in comment does 
not match parameter name 'p_one'
+// CHECK-NOTES: [[@LINE-2]]:26: note: FIX-IT applied suggested code changes
+// CHECK-NOTES: [[@LINE-39]]:28: note: 'p_one' declared here
+// CHECK-NOTES: [[@LINE-35]]:3: note: actual callee ('gmock_Method2') is 
declared here
+// CHECK-NOTES: [[@LINE-53]]:36: note: expanded from macro 'MOCK_CONST_METHOD2'
+// CHECK-NOTES: [[@LINE-57]]:7: note: expanded from macro 'GMOCK_METHOD2_'
+// CHECK-NOTES: note: expanded from here
+// CHECK-NOTES: [[@LINE-8]]:44: warning: argument name 'p_tw2' in comment does 
not match parameter name 'p_two'
+// CHECK-NOTES: [[@LINE-9]]:44: note: FIX-IT applied suggested code changes
+// CHECK-NOTES: [[@LINE-46]]:39: note: 'p_two' declared here
+// CHECK-NOTES: [[@LINE-42]]:3: note: actual callee ('gmock_Method2') is 
declared here
+// CHECK-NOTES: [[@LINE-60]]:36: note: expanded from macro 'MOCK_CONST_METHOD2'
+// CHECK-NOTES: [[@LINE-64]]:7: note: expanded from macro 'GMOCK_METHOD2_'
+// CHECK-NOTES: note: expanded from here
 // CHECK-FIXES:   EXPECT_CALL(m, Method2(/*p_one=*/PARAM1, /*p_two=*/PARAM2));
 
   MockStandalone m2;
@@ -103,6 +127,9 @@ void test_gmock_expectations() {
 void test_gmock_direct_calls() {
   MockDerived m;
   m.Method(/*param_one=*/1, /*param_tw=*/2);
-// CHECK-MESSAGES: [[@LINE-1]]:29: warning: argument name 'param_tw' in 
comment does not match parameter name 'param_two'
+// CHECK-NOTES: [[@LINE-1]]:29: warning: argument name 'param_tw' in comment 
does not match parameter name 'param_two'
+// CHECK-NOTES: [[@LINE-2]]:29: note: FIX-IT applied suggested code changes
+// CHECK-NOTES: [[

[clang-tools-extra] r342459 - [clang-tidy] use CHECK-NOTES in bugprone-forwarding-reference-overload

2018-09-18 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Sep 18 03:21:33 2018
New Revision: 342459

URL: http://llvm.org/viewvc/llvm-project?rev=342459&view=rev
Log:
[clang-tidy] use CHECK-NOTES in bugprone-forwarding-reference-overload

Reviewers: aaron.ballman, alexfh, hokein

Reviewed By: alexfh

Subscribers: xazax.hun, cfe-commits

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

Modified:

clang-tools-extra/trunk/test/clang-tidy/bugprone-forwarding-reference-overload.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/bugprone-forwarding-reference-overload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-forwarding-reference-overload.cpp?rev=342459&r1=342458&r2=342459&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/bugprone-forwarding-reference-overload.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/bugprone-forwarding-reference-overload.cpp
 Tue Sep 18 03:21:33 2018
@@ -20,27 +20,34 @@ template  constexpr bool jus
 class Test1 {
 public:
   template  Test1(T &&n);
-  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors 
[bugprone-forwarding-reference-overload]
+  // CHECK-NOTES: [[@LINE-1]]:25: warning: constructor accepting a forwarding 
reference can hide the copy and move constructors 
[bugprone-forwarding-reference-overload]
+  // CHECK-NOTES: 48:3: note: copy constructor declared here
+  // CHECK-NOTES: 49:3: note: copy constructor declared here
+  // CHECK-NOTES: 50:3: note: move constructor declared here
 
   template  Test1(T &&n, int i = 5, ...);
-  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
+  // CHECK-NOTES: :[[@LINE-1]]:25: warning: constructor accepting a forwarding 
reference can hide the copy and move constructors
+  // CHECK-NOTES: 48:3: note: copy constructor declared here
+  // CHECK-NOTES: 49:3: note: copy constructor declared here
+  // CHECK-NOTES: 50:3: note: move constructor declared here
 
   template ::type>
   Test1(T &&n);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
+  // CHECK-NOTES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding 
reference can hide the copy and move constructors
+  // CHECK-NOTES: 48:3: note: copy constructor declared here
+  // CHECK-NOTES: 49:3: note: copy constructor declared here
+  // CHECK-NOTES: 50:3: note: move constructor declared here
 
   template 
   Test1(T &&n, typename foo::enable_if::type i = 5, ...);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
+  // CHECK-NOTES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding 
reference can hide the copy and move constructors
+  // CHECK-NOTES: 48:3: note: copy constructor declared here
+  // CHECK-NOTES: 49:3: note: copy constructor declared here
+  // CHECK-NOTES: 50:3: note: move constructor declared here
 
   Test1(const Test1 &other) {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here
-
   Test1(Test1 &other) {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here
-
   Test1(Test1 &&other) {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: move constructor declared here
 };
 
 template  class Test2 {
@@ -96,10 +103,10 @@ private:
 class Test4 {
 public:
   template  Test4(T &&n);
-  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
+  // CHECK-NOTES: :[[@LINE-1]]:25: warning: constructor accepting a forwarding 
reference can hide the copy and move constructors
 
   Test4(const Test4 &rhs);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here
+  // CHECK-NOTES: :[[@LINE-1]]:3: note: copy constructor declared here
 };
 
 // Nothing can be hidden, the copy constructor is implicitly deleted.
@@ -114,10 +121,10 @@ public:
 class Test6 {
 public:
   template  Test6(T &&n);
-  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a 
forwarding reference can hide the move constructor
+  // CHECK-NOTES: :[[@LINE-1]]:25: warning: constructor accepting a forwarding 
reference can hide the move constructor
 
   Test6(Test6 &&rhs);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: note: move constructor declared here
+  // CHECK-NOTES: :[[@LINE-1]]:3: note: move constructor declared here
 private:
   Test6(const Test6 &rhs);
 };
@@ -141,5 +148,5 @@ class variant {
 public:
   template  >
   constexpr variant(_Arg&& __arg) {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
+  // CHECK-NOTES: :[[@LINE-1]]:13: warning: constructor accepting a forwarding 
reference can hide the copy and move cons

[clang-tools-extra] r342468 - [clang-tidy] use CHECK-NOTES in bugprone-unused-return-value

2018-09-18 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Sep 18 04:49:20 2018
New Revision: 342468

URL: http://llvm.org/viewvc/llvm-project?rev=342468&view=rev
Log:
[clang-tidy] use CHECK-NOTES in bugprone-unused-return-value

Reviewers: aaron.ballman, alexfh, hokein

Reviewed By: alexfh

Subscribers: xazax.hun, cfe-commits

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

Modified:

clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value-custom.cpp
clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value-custom.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value-custom.cpp?rev=342468&r1=342467&r2=342468&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value-custom.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value-custom.cpp 
Tue Sep 18 04:49:20 2018
@@ -47,32 +47,40 @@ void fun(int);
 
 void warning() {
   fun();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this 
function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value returned by this function 
should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast the expression to void to silence 
this warning
 
   (fun());
-  // CHECK-MESSAGES: [[@LINE-1]]:4: warning: the value returned by this 
function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:4: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:4: note: cast {{.*}} this warning
 
   ns::Outer::Inner ObjA1;
   ObjA1.memFun();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this 
function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   ns::AliasName::Inner ObjA2;
   ObjA2.memFun();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this 
function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   ns::Derived ObjA3;
   ObjA3.memFun();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this 
function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   ns::Type::staticFun();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this 
function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   ns::ClassTemplate ObjA4;
   ObjA4.memFun();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this 
function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   ns::ClassTemplate::staticFun();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this 
function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 }
 
 void noWarning() {

Modified: 
clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value.cpp?rev=342468&r1=342467&r2=342468&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value.cpp 
Tue Sep 18 04:49:20 2018
@@ -74,93 +74,116 @@ void useFuture(const std::future &fut);
 
 void warning() {
   std::async(increment, 42);
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this 
function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value returned by this function 
should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast the expression to void to silence 
this warning
 
   std::async(std::launch::async, increment, 42);
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this 
function should be used [bugprone-unused-return-value]
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: the value {{.*}} should be used
+  // CHECK-NOTES: [[@LINE-2]]:3: note: cast {{.*}} this warning
 
   Foo F;
   std::launder(&F);
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this 
f

[clang-tools-extra] r343000 - [clang-tidy] Add modernize-concat-nested-namespaces check

2018-09-25 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Sep 25 11:12:28 2018
New Revision: 343000

URL: http://llvm.org/viewvc/llvm-project?rev=343000&view=rev
Log:
[clang-tidy] Add modernize-concat-nested-namespaces check

Summary:
Finds instances of namespaces concatenated using explicit syntax, such as 
`namespace a { namespace b { [...] }}` and offers fix to glue it to `namespace 
a::b { [...] }`.

Properly handles `inline` and unnamed namespaces. ~~Also, detects empty blocks 
in nested namespaces and offers to remove them.~~

Test with common use cases included.
I ran the check against entire llvm repository. Except for expected `nested 
namespace definitions only available with -std=c++17 or -std=gnu++17` warnings 
I noticed no issues when the check was performed.

Example:
```
namespace a { namespace b {
void test();
}}

```
can become
```
namespace a::b {
void test();
}
```

Patch by wgml!

Reviewers: alexfh, aaron.ballman, hokein

Reviewed By: aaron.ballman

Subscribers: JonasToth, Eugene.Zelenko, lebedev.ri, mgorny, xazax.hun, 
cfe-commits

Tags: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/ConcatNestedNamespacesCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-concat-nested-namespaces.rst

clang-tools-extra/trunk/test/clang-tidy/modernize-concat-nested-namespaces.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt?rev=343000&r1=342999&r2=343000&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt Tue Sep 25 
11:12:28 2018
@@ -2,6 +2,7 @@ set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyModernizeModule
   AvoidBindCheck.cpp
+  ConcatNestedNamespacesCheck.cpp
   DeprecatedHeadersCheck.cpp
   LoopConvertCheck.cpp
   LoopConvertUtils.cpp

Added: 
clang-tools-extra/trunk/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp?rev=343000&view=auto
==
--- 
clang-tools-extra/trunk/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp 
(added)
+++ 
clang-tools-extra/trunk/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp 
Tue Sep 25 11:12:28 2018
@@ -0,0 +1,113 @@
+//===--- ConcatNestedNamespacesCheck.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 "ConcatNestedNamespacesCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include 
+#include 
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+static bool locationsInSameFile(const SourceManager &Sources,
+SourceLocation Loc1, SourceLocation Loc2) {
+  return Loc1.isFileID() && Loc2.isFileID() &&
+ Sources.getFileID(Loc1) == Sources.getFileID(Loc2);
+}
+
+static bool anonymousOrInlineNamespace(const NamespaceDecl &ND) {
+  return ND.isAnonymousNamespace() || ND.isInlineNamespace();
+}
+
+static bool singleNamedNamespaceChild(const NamespaceDecl &ND) {
+  NamespaceDecl::decl_range Decls = ND.decls();
+  if (std::distance(Decls.begin(), Decls.end()) != 1)
+return false;
+
+  const auto *ChildNamespace = dyn_cast(*Decls.begin());
+  return ChildNamespace && !anonymousOrInlineNamespace(*ChildNamespace);
+}
+
+static bool alreadyConcatenated(std::size_t NumCandidates,
+const SourceRange &ReplacementRange,
+const SourceManager &Sources,
+const LangOptions &LangOpts) {
+  CharSourceRange TextRange =
+  Lexer::getAsCharRange(ReplacementRange, Sources, LangOpts);
+  StringRef CurrentNamespacesText =
+  Lexer::getSourceText(TextRange, Sources, LangOpts);
+  return CurrentNamespacesText.count(':') == (NumCandidates - 1) * 2;
+}
+
+ConcatNestedNamespacesCheck::NamespaceString
+ConcatNestedNamespacesCheck::concatNamespaces() {
+  NamespaceString Result("namespace ");
+  Result.append(Namespaces.front()->getName());
+
+  std::for_each(std::next(Namespaces.begin()), Namespaces.end(),
+ 

[clang-tools-extra] r343001 - [clang-tidy] use CHECK-NOTES in tests for bugprone-macro-repeated-side-effects

2018-09-25 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Sep 25 11:15:52 2018
New Revision: 343001

URL: http://llvm.org/viewvc/llvm-project?rev=343001&view=rev
Log:
[clang-tidy] use CHECK-NOTES in tests for bugprone-macro-repeated-side-effects

Reviewers: alexfh, aaron.ballman, hokein

Reviewed By: alexfh

Subscribers: xazax.hun, cfe-commits

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

Modified:

clang-tools-extra/trunk/test/clang-tidy/bugprone-macro-repeated-side-effects.c

Modified: 
clang-tools-extra/trunk/test/clang-tidy/bugprone-macro-repeated-side-effects.c
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-macro-repeated-side-effects.c?rev=343001&r1=343000&r2=343001&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/bugprone-macro-repeated-side-effects.c 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/bugprone-macro-repeated-side-effects.c 
Tue Sep 25 11:15:52 2018
@@ -3,21 +3,29 @@
 #define badA(x,y)  ((x)+((x)+(y))+(y))
 void bad(int ret, int a, int b) {
   ret = badA(a++, b);
-  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: side effects in the 1st macro 
argument 'x' are repeated in macro expansion 
[bugprone-macro-repeated-side-effects]
+  // CHECK-NOTES: :[[@LINE-1]]:14: warning: side effects in the 1st macro 
argument 'x' are repeated in macro expansion 
[bugprone-macro-repeated-side-effects]
+  // CHECK-NOTES: :[[@LINE-4]]:9: note: macro 'badA' defined here
   ret = badA(++a, b);
-  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: side effects in the 1st macro 
argument 'x'
+  // CHECK-NOTES: :[[@LINE-1]]:14: warning: side effects in the 1st macro 
argument 'x'
+  // CHECK-NOTES: :[[@LINE-7]]:9: note: macro 'badA' defined here
   ret = badA(a--, b);
-  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: side effects in the 1st macro 
argument 'x'
+  // CHECK-NOTES: :[[@LINE-1]]:14: warning: side effects in the 1st macro 
argument 'x'
+  // CHECK-NOTES: :[[@LINE-10]]:9: note: macro 'badA' defined here
   ret = badA(--a, b);
-  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: side effects in the 1st macro 
argument 'x'
+  // CHECK-NOTES: :[[@LINE-1]]:14: warning: side effects in the 1st macro 
argument 'x'
+  // CHECK-NOTES: :[[@LINE-13]]:9: note: macro 'badA' defined here
   ret = badA(a, b++);
-  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: side effects in the 2nd macro 
argument 'y'
+  // CHECK-NOTES: :[[@LINE-1]]:17: warning: side effects in the 2nd macro 
argument 'y'
+  // CHECK-NOTES: :[[@LINE-16]]:9: note: macro 'badA' defined here
   ret = badA(a, ++b);
-  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: side effects in the 2nd macro 
argument 'y'
+  // CHECK-NOTES: :[[@LINE-1]]:17: warning: side effects in the 2nd macro 
argument 'y'
+  // CHECK-NOTES: :[[@LINE-19]]:9: note: macro 'badA' defined here
   ret = badA(a, b--);
-  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: side effects in the 2nd macro 
argument 'y'
+  // CHECK-NOTES: :[[@LINE-1]]:17: warning: side effects in the 2nd macro 
argument 'y'
+  // CHECK-NOTES: :[[@LINE-22]]:9: note: macro 'badA' defined here
   ret = badA(a, --b);
-  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: side effects in the 2nd macro 
argument 'y'
+  // CHECK-NOTES: :[[@LINE-1]]:17: warning: side effects in the 2nd macro 
argument 'y'
+  // CHECK-NOTES: :[[@LINE-25]]:9: note: macro 'badA' defined here
 }
 
 
@@ -25,15 +33,20 @@ void bad(int ret, int a, int b) {
 #define LIMIT(X,A,B) ((X) < (A) ? (A) : ((X) > (B) ? (B) : (X)))// two ?:
 void question(int x) {
   MIN(x++, 12);
-  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: side effects in the 1st macro 
argument 'A'
+  // CHECK-NOTES: :[[@LINE-1]]:7: warning: side effects in the 1st macro 
argument 'A'
+  // CHECK-NOTES: :[[@LINE-5]]:9: note: macro 'MIN' defined here
   MIN(34, x++);
-  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: side effects in the 2nd macro 
argument 'B'
+  // CHECK-NOTES: :[[@LINE-1]]:11: warning: side effects in the 2nd macro 
argument 'B'
+  // CHECK-NOTES: :[[@LINE-8]]:9: note: macro 'MIN' defined here
   LIMIT(x++, 0, 100);
-  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: side effects in the 1st macro 
argument 'X'
+  // CHECK-NOTES: :[[@LINE-1]]:9: warning: side effects in the 1st macro 
argument 'X'
+  // CHECK-NOTES: :[[@LINE-10]]:9: note: macro 'LIMIT' defined here
   LIMIT(20, x++, 100);
-  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: side effects in the 2nd macro 
argument 'A'
+  // CHECK-NOTES: :[[@LINE-1]]:13: warning: side effects in the 2nd macro 
argument 'A'
+  // CHECK-NOTES: :[[@LINE-13]]:9: note: macro 'LIMIT' defined here
   LIMIT(20, 0, x++);
-  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: side effects in the 3rd macro 
argument 'B'
+  // CHECK-NOTES: :[[@LINE-1]]:16: warning: side effects in the 3rd macro 
argument 'B'
+  // CHECK-NOTES: :[[@LINE-16]]:9: note: macro 'LIMIT' defined here
 }
 
 // False positive: Repeated side effects is intentional.
@@ -41,7 +54,

[clang-tools-extra] r343198 - [clang-tidy] use CHECK-NOTES in tests for bugprone-forward-declaration-namespace

2018-09-27 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Thu Sep 27 05:17:59 2018
New Revision: 343198

URL: http://llvm.org/viewvc/llvm-project?rev=343198&view=rev
Log:
[clang-tidy] use CHECK-NOTES in tests for bugprone-forward-declaration-namespace

Reviewers: aaron.ballman, alexfh, hokein

Subscribers: xazax.hun, cfe-commits

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

Modified:

clang-tools-extra/trunk/test/clang-tidy/bugprone-forward-declaration-namespace.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/bugprone-forward-declaration-namespace.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-forward-declaration-namespace.cpp?rev=343198&r1=343197&r2=343198&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/bugprone-forward-declaration-namespace.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/bugprone-forward-declaration-namespace.cpp
 Thu Sep 27 05:17:59 2018
@@ -3,19 +3,19 @@
 namespace {
 // This is a declaration in a wrong namespace.
 class T_A;
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration 'T_A' is never 
referenced, but a declaration with the same name found in another namespace 
'na' [bugprone-forward-declaration-namespace]
-// CHECK-MESSAGES: note: a declaration of 'T_A' is found here
-// CHECK-MESSAGES: :[[@LINE-3]]:7: warning: no definition found for 'T_A', but 
a definition with the same name 'T_A' found in another namespace '(global)' 
[bugprone-forward-declaration-namespace]
-// CHECK-MESSAGES: note: a definition of 'T_A' is found here
+// CHECK-NOTES: :[[@LINE-1]]:7: warning: declaration 'T_A' is never 
referenced, but a declaration with the same name found in another namespace 
'na' [bugprone-forward-declaration-namespace]
+// CHECK-NOTES: note: a declaration of 'T_A' is found here
+// CHECK-NOTES: :[[@LINE-3]]:7: warning: no definition found for 'T_A', but a 
definition with the same name 'T_A' found in another namespace '(global)' 
[bugprone-forward-declaration-namespace]
+// CHECK-NOTES: note: a definition of 'T_A' is found here
 }
 
 namespace na {
 // This is a declaration in a wrong namespace.
 class T_A;
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration 'T_A' is never 
referenced, but a declaration with the same name found in another namespace 
'(anonymous)'
-// CHECK-MESSAGES: note: a declaration of 'T_A' is found here
-// CHECK-MESSAGES: :[[@LINE-3]]:7: warning: no definition found for 'T_A', but 
a definition with the same name 'T_A' found in another namespace '(global)'
-// CHECK-MESSAGES: note: a definition of 'T_A' is found here
+// CHECK-NOTES: :[[@LINE-1]]:7: warning: declaration 'T_A' is never 
referenced, but a declaration with the same name found in another namespace 
'(anonymous)'
+// CHECK-NOTES: note: a declaration of 'T_A' is found here
+// CHECK-NOTES: :[[@LINE-3]]:7: warning: no definition found for 'T_A', but a 
definition with the same name 'T_A' found in another namespace '(global)'
+// CHECK-NOTES: note: a definition of 'T_A' is found here
 }
 
 class T_A;
@@ -25,8 +25,8 @@ class T_A {
 };
 
 class NESTED;
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: no definition found for 'NESTED', 
but a definition with the same name 'NESTED' found in another namespace 
'(anonymous namespace)::nq::(anonymous)'
-// CHECK-MESSAGES: note: a definition of 'NESTED' is found here
+// CHECK-NOTES: :[[@LINE-1]]:7: warning: no definition found for 'NESTED', but 
a definition with the same name 'NESTED' found in another namespace '(anonymous 
namespace)::nq::(anonymous)'
+// CHECK-NOTES: note: a definition of 'NESTED' is found here
 
 namespace {
 namespace nq {
@@ -38,10 +38,10 @@ class NESTED {};
 
 namespace na {
 class T_B;
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration 'T_B' is never 
referenced, but a declaration with the same name found in another namespace 'nb'
-// CHECK-MESSAGES: note: a declaration of 'T_B' is found here
-// CHECK-MESSAGES: :[[@LINE-3]]:7: warning: no definition found for 'T_B', but 
a definition with the same name 'T_B' found in another namespace 'nb'
-// CHECK-MESSAGES: note: a definition of 'T_B' is found here
+// CHECK-NOTES: :[[@LINE-1]]:7: warning: declaration 'T_B' is never 
referenced, but a declaration with the same name found in another namespace 'nb'
+// CHECK-NOTES: note: a declaration of 'T_B' is found here
+// CHECK-NOTES: :[[@LINE-3]]:7: warning: no definition found for 'T_B', but a 
definition with the same name 'T_B' found in another namespace 'nb'
+// CHECK-NOTES: note: a definition of 'T_B' is found here
 }
 
 namespace nb {
@@ -56,10 +56,10 @@ class T_B {
 
 namespace na {
 class T_B;
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration 'T_B' is never 
referenced, but a declaration with the same name found in another namespace 'nb'
-// CHECK-MESSAGES: note: a declaration of 'T_B' is found here
-// CHECK-MESSAGES: :[[@LINE-3]]:7: warning: no definition found for 'T_B', but 
a defi

[clang-tools-extra] r343199 - [clang-tidy] use CHECK-NOTES in tests for bugprone-use-after-move

2018-09-27 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Thu Sep 27 05:22:48 2018
New Revision: 343199

URL: http://llvm.org/viewvc/llvm-project?rev=343199&view=rev
Log:
[clang-tidy] use CHECK-NOTES in tests for bugprone-use-after-move

Reviewers: alexfh, aaron.ballman, hokein

Subscribers: xazax.hun, cfe-commits

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

Modified:
clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp

Modified: clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp?rev=343199&r1=343198&r2=343199&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp Thu Sep 
27 05:22:48 2018
@@ -125,8 +125,8 @@ void simple() {
   a.foo();
   A other_a = std::move(a);
   a.foo();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'a' used after it was moved
-  // CHECK-MESSAGES: [[@LINE-3]]:15: note: move occurred here
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: 'a' used after it was moved
+  // CHECK-NOTES: [[@LINE-3]]:15: note: move occurred here
 }
 
 // A warning should only be emitted for one use-after-move.
@@ -135,8 +135,8 @@ void onlyFlagOneUseAfterMove() {
   a.foo();
   A other_a = std::move(a);
   a.foo();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'a' used after it was moved
-  // CHECK-MESSAGES: [[@LINE-3]]:15: note: move occurred here
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: 'a' used after it was moved
+  // CHECK-NOTES: [[@LINE-3]]:15: note: move occurred here
   a.foo();
 }
 
@@ -146,8 +146,8 @@ void moveAfterMove() {
 A a;
 std::move(a);
 std::move(a);
-// CHECK-MESSAGES: [[@LINE-1]]:15: warning: 'a' used after it was moved
-// CHECK-MESSAGES: [[@LINE-3]]:5: note: move occurred here
+// CHECK-NOTES: [[@LINE-1]]:15: warning: 'a' used after it was moved
+// CHECK-NOTES: [[@LINE-3]]:5: note: move occurred here
   }
   // This is also true if the move itself turns into the use on the second loop
   // iteration.
@@ -155,9 +155,9 @@ void moveAfterMove() {
 A a;
 for (int i = 0; i < 10; ++i) {
   std::move(a);
-  // CHECK-MESSAGES: [[@LINE-1]]:17: warning: 'a' used after it was moved
-  // CHECK-MESSAGES: [[@LINE-2]]:7: note: move occurred here
-  // CHECK-MESSAGES: [[@LINE-3]]:17: note: the use happens in a later loop
+  // CHECK-NOTES: [[@LINE-1]]:17: warning: 'a' used after it was moved
+  // CHECK-NOTES: [[@LINE-2]]:7: note: move occurred here
+  // CHECK-NOTES: [[@LINE-3]]:17: note: the use happens in a later loop
 }
   }
 }
@@ -166,8 +166,8 @@ void moveAfterMove() {
 void parameters(A a) {
   std::move(a);
   a.foo();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'a' used after it was moved
-  // CHECK-MESSAGES: [[@LINE-3]]:3: note: move occurred here
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: 'a' used after it was moved
+  // CHECK-NOTES: [[@LINE-3]]:3: note: move occurred here
 }
 
 void standardSmartPtr() {
@@ -180,22 +180,22 @@ void standardSmartPtr() {
 ptr.get();
 static_cast(ptr);
 *ptr;
-// CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'ptr' used after it was moved
-// CHECK-MESSAGES: [[@LINE-5]]:5: note: move occurred here
+// CHECK-NOTES: [[@LINE-1]]:6: warning: 'ptr' used after it was moved
+// CHECK-NOTES: [[@LINE-5]]:5: note: move occurred here
   }
   {
 std::unique_ptr ptr;
 std::move(ptr);
 ptr->foo();
-// CHECK-MESSAGES: [[@LINE-1]]:5: warning: 'ptr' used after it was moved
-// CHECK-MESSAGES: [[@LINE-3]]:5: note: move occurred here
+// CHECK-NOTES: [[@LINE-1]]:5: warning: 'ptr' used after it was moved
+// CHECK-NOTES: [[@LINE-3]]:5: note: move occurred here
   }
   {
 std::unique_ptr ptr;
 std::move(ptr);
 ptr[0];
-// CHECK-MESSAGES: [[@LINE-1]]:5: warning: 'ptr' used after it was moved
-// CHECK-MESSAGES: [[@LINE-3]]:5: note: move occurred here
+// CHECK-NOTES: [[@LINE-1]]:5: warning: 'ptr' used after it was moved
+// CHECK-NOTES: [[@LINE-3]]:5: note: move occurred here
   }
   {
 std::shared_ptr ptr;
@@ -203,15 +203,15 @@ void standardSmartPtr() {
 ptr.get();
 static_cast(ptr);
 *ptr;
-// CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'ptr' used after it was moved
-// CHECK-MESSAGES: [[@LINE-5]]:5: note: move occurred here
+// CHECK-NOTES: [[@LINE-1]]:6: warning: 'ptr' used after it was moved
+// CHECK-NOTES: [[@LINE-5]]:5: note: move occurred here
   }
   {
 std::shared_ptr ptr;
 std::move(ptr);
 ptr->foo();
-// CHECK-MESSAGES: [[@LINE-1]]:5: warning: 'ptr' used after it was moved
-// CHECK-MESSAGES: [[@LINE-3]]:5: note: move occurred here
+// CHECK-NOTES: [[@LINE-1]]:5: warning: 'ptr' used after it was moved
+// CHECK-NOTES: [[@LINE-3]]:5: note: move occurred here
   

[clang-tools-extra] r343201 - [clang-tidy] use CHECK-NOTES in tests for bugprone suspicious-enum-usage

2018-09-27 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Thu Sep 27 05:30:44 2018
New Revision: 343201

URL: http://llvm.org/viewvc/llvm-project?rev=343201&view=rev
Log:
[clang-tidy] use CHECK-NOTES in tests for bugprone suspicious-enum-usage

Reviewers: alexfh, aaron.ballman, hokein

Subscribers: xazax.hun, cfe-commits

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

Modified:

clang-tools-extra/trunk/test/clang-tidy/bugprone-suspicious-enum-usage-strict.cpp
clang-tools-extra/trunk/test/clang-tidy/bugprone-suspicious-enum-usage.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/bugprone-suspicious-enum-usage-strict.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-suspicious-enum-usage-strict.cpp?rev=343201&r1=343200&r2=343201&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/bugprone-suspicious-enum-usage-strict.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/bugprone-suspicious-enum-usage-strict.cpp
 Thu Sep 27 05:30:44 2018
@@ -10,23 +10,23 @@ enum A {
   G = 63
 };
 
-// CHECK-MESSAGES: :[[@LINE+2]]:1: warning: enum type seems like a bitmask 
(contains mostly power-of-2 literals) but a literal is not power-of-2
-// CHECK-MESSAGES: :76:7: note: used here as a bitmask
+// CHECK-NOTES: :[[@LINE+2]]:1: warning: enum type seems like a bitmask 
(contains mostly power-of-2 literals) but a literal is not power-of-2
+// CHECK-NOTES: :76:7: note: used here as a bitmask
 enum X {
   X = 8,
   Y = 16,
   Z = 4,
   ZZ = 3
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: enum type seems like a bitmask 
(contains mostly power-of-2 literals), but this literal is not a power-of-2 
[bugprone-suspicious-enum-usage]
-// CHECK-MESSAGES: :70:13: note: used here as a bitmask
+  // CHECK-NOTES: :[[@LINE-1]]:3: warning: enum type seems like a bitmask 
(contains mostly power-of-2 literals), but this literal is not a power-of-2 
[bugprone-suspicious-enum-usage]
+// CHECK-NOTES: :70:13: note: used here as a bitmask
 };
-// CHECK-MESSAGES: :[[@LINE+2]]:1: warning: enum type seems like a bitmask 
(contains mostly power-of-2 literals) but some literals are not power-of-2
-// CHECK-MESSAGES: :73:8: note: used here as a bitmask
+// CHECK-NOTES: :[[@LINE+2]]:1: warning: enum type seems like a bitmask 
(contains mostly power-of-2 literals) but some literals are not power-of-2
+// CHECK-NOTES: :73:8: note: used here as a bitmask
 enum PP {
   P = 2,
   Q = 3,
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: enum type seems like a bitmask 
(contains mostly power-of-2 literals), but this literal is not a power-of-2
-  // CHECK-MESSAGES: :65:11: note: used here as a bitmask
+  // CHECK-NOTES: :[[@LINE-1]]:3: warning: enum type seems like a bitmask 
(contains mostly power-of-2 literals), but this literal is not a power-of-2
+  // CHECK-NOTES: :65:11: note: used here as a bitmask
   R = 4,
   S = 8,
   T = 16,
@@ -58,10 +58,10 @@ Days bestDay() {
 int trigger() {
   if (bestDay() | A)
 return 1;
-  // CHECK-MESSAGES: :[[@LINE-2]]:17: warning: enum values are from different 
enum types
+  // CHECK-NOTES: :[[@LINE-2]]:17: warning: enum values are from different 
enum types
   if (I | Y)
 return 1;
-  // CHECK-MESSAGES: :[[@LINE-2]]:9: warning: enum values are from different 
enum types
+  // CHECK-NOTES: :[[@LINE-2]]:9: warning: enum values are from different enum 
types
   if (P + Q == R)
 return 1;
   else if ((S | R) == T)

Modified: 
clang-tools-extra/trunk/test/clang-tidy/bugprone-suspicious-enum-usage.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-suspicious-enum-usage.cpp?rev=343201&r1=343200&r2=343201&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-suspicious-enum-usage.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-suspicious-enum-usage.cpp 
Thu Sep 27 05:30:44 2018
@@ -54,10 +54,10 @@ int trigger() {
   int emptytest = EmptyVal | B;
   if (bestDay() | A)
 return 1;
-  // CHECK-MESSAGES: :[[@LINE-2]]:17: warning: enum values are from different 
enum types
+  // CHECK-NOTES: :[[@LINE-2]]:17: warning: enum values are from different 
enum types
   if (I | Y)
 return 1;
-  // CHECK-MESSAGES: :[[@LINE-2]]:9: warning: enum values are from different 
enum types
+  // CHECK-NOTES: :[[@LINE-2]]:9: warning: enum values are from different enum 
types
 }
 
 int dont_trigger() {


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


[clang-tools-extra] r343564 - [clang-tidy] NFC use CHECK-NOTES in tests for cppcoreguidelines-owning-memory

2018-10-02 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Oct  2 02:38:20 2018
New Revision: 343564

URL: http://llvm.org/viewvc/llvm-project?rev=343564&view=rev
Log:
[clang-tidy] NFC use CHECK-NOTES in tests for cppcoreguidelines-owning-memory

Reviewers: alexfh, aaron.ballman, hokein

Reviewed By: alexfh

Subscribers: nemanjai, xazax.hun, kbarton, cfe-commits

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

Modified:

clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-containers.cpp
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-containers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-containers.cpp?rev=343564&r1=343563&r2=343564&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-containers.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-containers.cpp
 Tue Oct  2 02:38:20 2018
@@ -37,22 +37,23 @@ int main() {
   // Rangebased looping in resource vector.
   for (auto *Element : OwnerStdVector) {
 Element = new int(42);
-// CHECK-MESSAGES: [[@LINE-1]]:5: warning: assigning newly created 
'gsl::owner<>' to non-owner 'int *'
+// CHECK-NOTES: [[@LINE-1]]:5: warning: assigning newly created 
'gsl::owner<>' to non-owner 'int *'
   }
   for (auto *Element : OwnerStdVector) {
 delete Element;
-// CHECK-MESSAGES: [[@LINE-1]]:5: warning: deleting a pointer through a 
type that is not marked 'gsl::owner<>'; consider using a smart pointer instead
-// CHECK-MESSAGES: [[@LINE-3]]:8: note: variable declared here
+// CHECK-NOTES: [[@LINE-1]]:5: warning: deleting a pointer through a type 
that is not marked 'gsl::owner<>'; consider using a smart pointer instead
+// CHECK-NOTES: [[@LINE-3]]:8: note: variable declared here
   }
 
   // Indexbased looping in resource vector.
   for (int i = 0; i < 100; ++i) {
 OwnerStdVector[i] = new int(42);
-// CHECK-MESSAGES: [[@LINE-1]]:5: warning: assigning newly created 
'gsl::owner<>' to non-owner 'int *'
+// CHECK-NOTES: [[@LINE-1]]:5: warning: assigning newly created 
'gsl::owner<>' to non-owner 'int *'
   }
   for (int i = 0; i < 100; ++i) {
 delete OwnerStdVector[i];
-// CHECK-MESSAGES: [[@LINE-1]]:5: warning: deleting a pointer through a 
type that is not marked 'gsl::owner<>'; consider using a smart pointer instead
+// CHECK-NOTES: [[@LINE-1]]:5: warning: deleting a pointer through a type 
that is not marked 'gsl::owner<>'; consider using a smart pointer instead
+// CHECK-NOTES: [[@LINE-21]]:3: note: variable declared here
 // A note gets emitted here pointing to the return value of the operator[] 
from the
 // vector implementation. Maybe this is considered misleading.
   }

Modified: 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory.cpp?rev=343564&r1=343563&r2=343564&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory.cpp 
Tue Oct  2 02:38:20 2018
@@ -36,17 +36,17 @@ gsl::owner returns_owner2() { ret
 int *returns_no_owner1() { return nullptr; }
 int *returns_no_owner2() {
   return new int(42);
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: returning a newly created 
resource of type 'int *' or 'gsl::owner<>' from a function whose return type is 
not 'gsl::owner<>'
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: returning a newly created resource 
of type 'int *' or 'gsl::owner<>' from a function whose return type is not 
'gsl::owner<>'
 }
 int *returns_no_owner3() {
   int *should_be_owner = new int(42);
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'int *' 
with a newly created 'gsl::owner<>'
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: initializing non-owner 'int *' with 
a newly created 'gsl::owner<>'
   return should_be_owner;
 }
 int *returns_no_owner4() {
   gsl::owner owner = new int(42);
   return owner;
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: returning a newly created 
resource of type 'int *' or 'gsl::owner<>' from a function whose return type is 
not 'gsl::owner<>'
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: returning a newly created resource 
of type 'int *' or 'gsl::owner<>' from a function whose return type is not 
'gsl::owner<>'
 }
 
 unique_ptr returns_no_owner5() {
@@ -71,11 +71,11 @@ void test_assignment_and_initialization(
   int stack_int2;
 
   gsl::owner owned_int1 = &stack_int1; // BAD
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: expected initialization with 
value of type 'gsl::

[clang-tools-extra] r343565 - [clang-tidy] NFC use CHECK-NOTES in test for cppgoreguidelines-avoid-goto

2018-10-02 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Oct  2 02:38:26 2018
New Revision: 343565

URL: http://llvm.org/viewvc/llvm-project?rev=343565&view=rev
Log:
[clang-tidy] NFC use CHECK-NOTES in test for cppgoreguidelines-avoid-goto

Reviewers: alexfh, aaron.ballman, hokein

Reviewed By: alexfh

Subscribers: nemanjai, xazax.hun, kbarton, cfe-commits

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

Modified:
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-avoid-goto.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-avoid-goto.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-avoid-goto.cpp?rev=343565&r1=343564&r2=343565&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-avoid-goto.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-avoid-goto.cpp 
Tue Oct  2 02:38:26 2018
@@ -5,8 +5,8 @@ void noop() {}
 int main() {
   noop();
   goto jump_to_me;
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow 
control
-  // CHECK-MESSAGES: [[@LINE+3]]:1: note: label defined here
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-NOTES: [[@LINE+3]]:1: note: label defined here
   noop();
 
 jump_to_me:;
@@ -14,14 +14,14 @@ jump_to_me:;
 jump_backwards:;
   noop();
   goto jump_backwards;
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow 
control
-  // CHECK-MESSAGES: [[@LINE-4]]:1: note: label defined here
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-NOTES: [[@LINE-4]]:1: note: label defined here
 
   goto jump_in_line;
   ;
 jump_in_line:;
-  // CHECK-MESSAGES: [[@LINE-3]]:3: warning: avoid using 'goto' for flow 
control
-  // CHECK-MESSAGES: [[@LINE-2]]:1: note: label defined here
+  // CHECK-NOTES: [[@LINE-3]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-NOTES: [[@LINE-2]]:1: note: label defined here
 
   // Test the GNU extension 
https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
 some_label:;
@@ -132,8 +132,8 @@ before_the_loop:
 for (int j = 0; j < 10; ++j) {
   if (i * j > 80)
 goto before_the_loop;
-  // CHECK-MESSAGES: [[@LINE-1]]:9: warning: avoid using 'goto' for flow 
control
-  // CHECK-MESSAGES: [[@LINE-8]]:1: note: label defined here
+  // CHECK-NOTES: [[@LINE-1]]:9: warning: avoid using 'goto' for flow 
control
+  // CHECK-NOTES: [[@LINE-8]]:1: note: label defined here
 }
   }
 }


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


[clang-tools-extra] r343673 - [clang-tidy] NFC reorder registering in CppCoreGuidelines module

2018-10-03 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Oct  3 03:37:19 2018
New Revision: 343673

URL: http://llvm.org/viewvc/llvm-project?rev=343673&view=rev
Log:
[clang-tidy] NFC reorder registering in CppCoreGuidelines module

Modified:

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp?rev=343673&r1=343672&r2=343673&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 Wed Oct  3 03:37:19 2018
@@ -40,10 +40,10 @@ public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
 CheckFactories.registerCheck(
 "cppcoreguidelines-avoid-goto");
-CheckFactories.registerCheck(
-"cppcoreguidelines-interfaces-global-init");
 CheckFactories.registerCheck(
 "cppcoreguidelines-avoid-magic-numbers");
+CheckFactories.registerCheck(
+"cppcoreguidelines-interfaces-global-init");
 CheckFactories.registerCheck(
 "cppcoreguidelines-narrowing-conversions");
 CheckFactories.registerCheck("cppcoreguidelines-no-malloc");


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


[clang-tools-extra] r343788 - [clang-tidy] Added pointer types to clang-tidy readability-identifier-naming check.

2018-10-04 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Thu Oct  4 08:47:57 2018
New Revision: 343788

URL: http://llvm.org/viewvc/llvm-project?rev=343788&view=rev
Log:
[clang-tidy] Added pointer types to clang-tidy readability-identifier-naming 
check.

Summary:

Option to check for different naming conventions on the following types:

  - GlobalConstantPointer
  - GlobalPointer
  - LocalConstantPointer
  - LocalPointer
  - PointerParameter
  - ConstantPointerParameter

When not specified, the conventions for the non pointer types will be applied 
(GlobalConstant, GlobalVariable, LocalConstant, ...).

Patch by ffigueras!

Reviewers: alexfh, kbobyrev

Reviewed By: alexfh

Subscribers: xazax.hun, cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp?rev=343788&r1=343787&r2=343788&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp 
Thu Oct  4 08:47:57 2018
@@ -77,8 +77,12 @@ namespace readability {
 m(ClassConstant) \
 m(ClassMember) \
 m(GlobalConstant) \
+m(GlobalConstantPointer) \
+m(GlobalPointer) \
 m(GlobalVariable) \
 m(LocalConstant) \
+m(LocalConstantPointer) \
+m(LocalPointer) \
 m(LocalVariable) \
 m(StaticConstant) \
 m(StaticVariable) \
@@ -87,6 +91,8 @@ namespace readability {
 m(ConstantParameter) \
 m(ParameterPack) \
 m(Parameter) \
+m(PointerParameter) \
+m(ConstantPointerParameter) \
 m(AbstractClass) \
 m(Struct) \
 m(Class) \
@@ -486,6 +492,9 @@ static StyleKind findStyleKind(
   return SK_ConstexprVariable;
 
 if (!Type.isNull() && Type.isConstQualified()) {
+  if (Type.getTypePtr()->isAnyPointerType() && 
NamingStyles[SK_ConstantPointerParameter])
+return SK_ConstantPointerParameter;
+
   if (NamingStyles[SK_ConstantParameter])
 return SK_ConstantParameter;
 
@@ -496,6 +505,9 @@ static StyleKind findStyleKind(
 if (Decl->isParameterPack() && NamingStyles[SK_ParameterPack])
   return SK_ParameterPack;
 
+if (!Type.isNull() && Type.getTypePtr()->isAnyPointerType() && 
NamingStyles[SK_PointerParameter])
+return SK_PointerParameter;
+
 if (NamingStyles[SK_Parameter])
   return SK_Parameter;
 
@@ -512,12 +524,18 @@ static StyleKind findStyleKind(
   if (Decl->isStaticDataMember() && NamingStyles[SK_ClassConstant])
 return SK_ClassConstant;
 
+  if (Decl->isFileVarDecl() && Type.getTypePtr()->isAnyPointerType() && 
NamingStyles[SK_GlobalConstantPointer])
+return SK_GlobalConstantPointer;
+
   if (Decl->isFileVarDecl() && NamingStyles[SK_GlobalConstant])
 return SK_GlobalConstant;
 
   if (Decl->isStaticLocal() && NamingStyles[SK_StaticConstant])
 return SK_StaticConstant;
 
+  if (Decl->isLocalVarDecl() && Type.getTypePtr()->isAnyPointerType() && 
NamingStyles[SK_LocalConstantPointer])
+return SK_LocalConstantPointer;
+
   if (Decl->isLocalVarDecl() && NamingStyles[SK_LocalConstant])
 return SK_LocalConstant;
 
@@ -531,11 +549,17 @@ static StyleKind findStyleKind(
 if (Decl->isStaticDataMember() && NamingStyles[SK_ClassMember])
   return SK_ClassMember;
 
+if (Decl->isFileVarDecl() && Type.getTypePtr()->isAnyPointerType() && 
NamingStyles[SK_GlobalPointer])
+  return SK_GlobalPointer;
+
 if (Decl->isFileVarDecl() && NamingStyles[SK_GlobalVariable])
   return SK_GlobalVariable;
 
 if (Decl->isStaticLocal() && NamingStyles[SK_StaticVariable])
   return SK_StaticVariable;
+ 
+if (Decl->isLocalVarDecl() && Type.getTypePtr()->isAnyPointerType() && 
NamingStyles[SK_LocalPointer])
+  return SK_LocalPointer;
 
 if (Decl->isLocalVarDecl() && NamingStyles[SK_LocalVariable])
   return SK_LocalVariable;

Modified: 
clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp?rev=343788&r1=343787&r2=343788&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp 
Thu Oct  4 08:47:57 2018
@@ -67,7 +67,19 @@
 // RUN: {key: readability-identifier-naming.MacroDefinitionCase, value: 
UPPER_CASE}, \
 // RUN: {key: readability-identifier-naming.TypeAliasCase, value: 
camel_Snake_Back}

[clang-tools-extra] r343789 - [clang-tidy] fix PR39167, bugprone-exception-escape hangs-up

2018-10-04 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Thu Oct  4 08:49:25 2018
New Revision: 343789

URL: http://llvm.org/viewvc/llvm-project?rev=343789&view=rev
Log:
[clang-tidy] fix PR39167, bugprone-exception-escape hangs-up

Summary:
The check bugprone-exception-escape should not register
if -fno-exceptions is set for the compile options. Bailing out on non-cplusplus
and non-exceptions language options resolves the issue.

Reviewers: alexfh, aaron.ballman, baloghadamsoftware

Reviewed By: alexfh

Subscribers: lebedev.ri, xazax.hun, rnkovacs, cfe-commits

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

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

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.cpp?rev=343789&r1=343788&r2=343789&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/ExceptionEscapeCheck.cpp Thu 
Oct  4 08:49:25 2018
@@ -186,6 +186,9 @@ void ExceptionEscapeCheck::storeOptions(
 }
 
 void ExceptionEscapeCheck::registerMatchers(MatchFinder *Finder) {
+  if (!getLangOpts().CPlusPlus || !getLangOpts().CXXExceptions)
+return;
+
   Finder->addMatcher(
   functionDecl(allOf(throws(unless(isIgnored(IgnoredExceptions))),
  anyOf(isNoThrow(), cxxDestructorDecl(),


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


[clang-tools-extra] r343791 - [clang-tidy] NFC use CHECK-NOTES in tests for performance-move-constructor-init

2018-10-04 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Thu Oct  4 08:55:37 2018
New Revision: 343791

URL: http://llvm.org/viewvc/llvm-project?rev=343791&view=rev
Log:
[clang-tidy] NFC use CHECK-NOTES in tests for performance-move-constructor-init

Reviewers: alexfh, aaron.ballman, hokein

Reviewed By: alexfh

Subscribers: lebedev.ri, xazax.hun, cfe-commits

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

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

clang-tools-extra/trunk/test/clang-tidy/performance-move-constructor-init.cpp

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=343791&r1=343790&r2=343791&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 Thu Oct  4 
08:55:37 2018
@@ -164,7 +164,9 @@ def main():
 
   if has_check_notes:
 notes_file = temp_file_name + '.notes'
-write_file(notes_file, clang_tidy_output)
+filtered_output = [line for line in clang_tidy_output.splitlines()
+   if not "note: FIX-IT applied suggested changes" in line]
+write_file(notes_file, '\n'.join(filtered_output))
 try:
   subprocess.check_output(
   ['FileCheck', '-input-file=' + notes_file, input_file_name,

Modified: 
clang-tools-extra/trunk/test/clang-tidy/performance-move-constructor-init.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/performance-move-constructor-init.cpp?rev=343791&r1=343790&r2=343791&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/performance-move-constructor-init.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/performance-move-constructor-init.cpp 
Thu Oct  4 08:55:37 2018
@@ -30,9 +30,9 @@ struct B {
 struct D : B {
   D() : B() {}
   D(const D &RHS) : B(RHS) {}
-  // CHECK-MESSAGES: :[[@LINE+3]]:16: warning: move constructor initializes 
base class by calling a copy constructor [performance-move-constructor-init]
-  // CHECK-MESSAGES: 26:3: note: copy constructor being called
-  // CHECK-MESSAGES: 27:3: note: candidate move constructor here
+  // CHECK-NOTES: :[[@LINE+3]]:16: warning: move constructor initializes base 
class by calling a copy constructor [performance-move-constructor-init]
+  // CHECK-NOTES: 26:3: note: copy constructor being called
+  // CHECK-NOTES: 27:3: note: candidate move constructor here
   D(D &&RHS) : B(RHS) {}
 };
 
@@ -75,8 +75,10 @@ struct L : K {
 
 struct M {
   B Mem;
-  // CHECK-MESSAGES: :[[@LINE+1]]:16: warning: move constructor initializes 
class member by calling a copy constructor [performance-move-constructor-init]
+  // CHECK-NOTES: :[[@LINE+1]]:16: warning: move constructor initializes class 
member by calling a copy constructor [performance-move-constructor-init]
   M(M &&RHS) : Mem(RHS.Mem) {}
+  // CHECK-NOTES: 26:3: note: copy constructor being called
+  // CHECK-NOTES: 27:3: note: candidate move constructor here
 };
 
 struct N {
@@ -109,7 +111,7 @@ struct TriviallyCopyable {
 
 struct Positive {
   Positive(Movable M) : M_(M) {}
-  // CHECK-MESSAGES: [[@LINE-1]]:12: warning: pass by value and use std::move 
[modernize-pass-by-value]
+  // CHECK-NOTES: [[@LINE-1]]:12: warning: pass by value and use std::move 
[modernize-pass-by-value]
   // CHECK-FIXES: Positive(Movable M) : M_(std::move(M)) {}
   Movable M_;
 };


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


[clang-tools-extra] r343792 - [clang-tidy] NFC use CHECK-NOTES in tests for fuchsia-default-arguments

2018-10-04 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Thu Oct  4 08:59:30 2018
New Revision: 343792

URL: http://llvm.org/viewvc/llvm-project?rev=343792&view=rev
Log:
[clang-tidy] NFC use CHECK-NOTES in tests for fuchsia-default-arguments

Reviewers: alexfh, aaron.ballman, hokein

Reviewed By: alexfh

Subscribers: xazax.hun, cfe-commits

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

Modified:
clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments.cpp

Modified: clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments.cpp?rev=343792&r1=343791&r2=343792&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments.cpp Thu 
Oct  4 08:59:30 2018
@@ -1,14 +1,13 @@
 // RUN: %check_clang_tidy %s fuchsia-default-arguments %t
 
 int foo(int value = 5) { return value; }
-// CHECK-MESSAGES: [[@LINE-1]]:9: warning: declaring a parameter with a 
default argument is disallowed [fuchsia-default-arguments]
+// CHECK-NOTES: [[@LINE-1]]:9: warning: declaring a parameter with a default 
argument is disallowed [fuchsia-default-arguments]
 // CHECK-FIXES: int foo(int value) { return value; }
 
 int f() {
   foo();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: calling a function that uses a 
default argument is disallowed [fuchsia-default-arguments]
-  // CHECK-NEXT: note: default parameter was declared here:
-  // CHECK-NEXT: int foo(int value = 5) { return value; }
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: calling a function that uses a 
default argument is disallowed [fuchsia-default-arguments]
+  // CHECK-NOTES: [[@LINE-8]]:9: note: default parameter was declared here
 }
 
 int bar(int value) { return value; }
@@ -21,7 +20,7 @@ int n() {
 class Baz {
 public:
   int a(int value = 5) { return value; }
-  // CHECK-MESSAGES: [[@LINE-1]]:9: warning: declaring a parameter with a 
default argument is disallowed [fuchsia-default-arguments]
+  // CHECK-NOTES: [[@LINE-1]]:9: warning: declaring a parameter with a default 
argument is disallowed [fuchsia-default-arguments]
   // CHECK-FIXES: int a(int value) { return value; }
 
   int b(int value) { return value; }
@@ -30,7 +29,7 @@ public:
 class Foo {
   // Fix should be suggested in declaration
   int a(int value = 53);
-  // CHECK-MESSAGES: [[@LINE-1]]:9: warning: declaring a parameter with a 
default argument is disallowed [fuchsia-default-arguments]
+  // CHECK-NOTES: [[@LINE-1]]:9: warning: declaring a parameter with a default 
argument is disallowed [fuchsia-default-arguments]
   // CHECK-FIXES: int a(int value);
 };
 
@@ -41,7 +40,7 @@ int Foo::a(int value) {
 
 // Elided functions
 void f(int = 5) {};
-// CHECK-MESSAGES: [[@LINE-1]]:8: warning: declaring a parameter with a 
default argument is disallowed [fuchsia-default-arguments]
+// CHECK-NOTES: [[@LINE-1]]:8: warning: declaring a parameter with a default 
argument is disallowed [fuchsia-default-arguments]
 // CHECK-FIXES: void f(int) {};
 
 void g(int) {};
@@ -50,12 +49,12 @@ void g(int) {};
 #define D(val) = val
 
 void h(int i D(5));
-// CHECK-MESSAGES: [[@LINE-1]]:8: warning: declaring a parameter with a 
default argument is disallowed [fuchsia-default-arguments]
+// CHECK-NOTES: [[@LINE-1]]:8: warning: declaring a parameter with a default 
argument is disallowed [fuchsia-default-arguments]
 // CHECK-FIXES-NOT: void h(int i);
 
 void x(int i);
 void x(int i = 12);
-// CHECK-MESSAGES: [[@LINE-1]]:8: warning: declaring a parameter with a 
default argument is disallowed [fuchsia-default-arguments]
+// CHECK-NOTES: [[@LINE-1]]:8: warning: declaring a parameter with a default 
argument is disallowed [fuchsia-default-arguments]
 // CHECK-FIXES: void x(int i);
 
 void x(int i) {}
@@ -65,17 +64,17 @@ struct S {
 };
 
 void S::x(int i = 12) {}
-// CHECK-MESSAGES: [[@LINE-1]]:11: warning: declaring a parameter with a 
default argument is disallowed [fuchsia-default-arguments]
+// CHECK-NOTES: [[@LINE-1]]:11: warning: declaring a parameter with a default 
argument is disallowed [fuchsia-default-arguments]
 // CHECK-FIXES: void S::x(int i) {}
 
 int main() {
   S s;
   s.x();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: calling a function that uses a 
default argument is disallowed [fuchsia-default-arguments]
-  // CHECK-NEXT: note: default parameter was declared here:
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: calling a function that uses a 
default argument is disallowed [fuchsia-default-arguments]
+  // CHECK-NOTES: [[@LINE-9]]:11: note: default parameter was declared here
   // CHECK-NEXT: void S::x(int i = 12) {}
   x();
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: calling a function that uses a 
default argument is disallowed [fuchsia-default-arguments]
-  // CHECK-NEXT: note: default parameter was declared here:
+  // CHECK-NO

[clang-tools-extra] r343796 - [clangd] fix another ambigous constructor in DexTest

2018-10-04 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Thu Oct  4 09:29:58 2018
New Revision: 343796

URL: http://llvm.org/viewvc/llvm-project?rev=343796&view=rev
Log:
[clangd] fix another ambigous constructor in DexTest

Modified:
clang-tools-extra/trunk/unittests/clangd/DexTests.cpp

Modified: clang-tools-extra/trunk/unittests/clangd/DexTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/DexTests.cpp?rev=343796&r1=343795&r2=343796&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/DexTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/DexTests.cpp Thu Oct  4 09:29:58 
2018
@@ -317,9 +317,9 @@ TEST(DexIterators, Boost) {
 
 TEST(DexIterators, Optimizations) {
   Corpus C{5};
-  const PostingList L1({1});
-  const PostingList L2({2});
-  const PostingList L3({3});
+  const PostingList L1{1};
+  const PostingList L2{2};
+  const PostingList L3{3};
 
   // empty and/or yield true/false
   EXPECT_EQ(llvm::to_string(*C.intersect()), "true");


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


[clang-tools-extra] r343797 - [clang-tidy] fix failing unit tests

2018-10-04 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Thu Oct  4 09:39:41 2018
New Revision: 343797

URL: http://llvm.org/viewvc/llvm-project?rev=343797&view=rev
Log:
[clang-tidy] fix failing unit tests

The removal from the FIX-IT notes through the check-clang-tidy
script was done incorrect. I did not detect beforehand but adjusted
the script and tests accordingly

Modified:
clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-gmock.cpp
clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-strict.cpp
clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment.cpp
clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py
clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-gmock.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-gmock.cpp?rev=343797&r1=343796&r2=343797&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-gmock.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-argument-comment-gmock.cpp 
Thu Oct  4 09:39:41 2018
@@ -84,20 +84,18 @@ void test_gmock_expectations() {
   MockDerived m;
   EXPECT_CALL(m, Method(/*param_one=*/1, /*param_tw=*/2));
 // CHECK-NOTES: [[@LINE-1]]:42: warning: argument name 'param_tw' in comment 
does not match parameter name 'param_two'
-// CHECK-NOTES: [[@LINE-2]]:42: note: FIX-IT applied suggested code changes
-// CHECK-NOTES: [[@LINE-19]]:42: note: 'param_two' declared here
-// CHECK-NOTES: [[@LINE-15]]:3: note: actual callee ('gmock_Method') is 
declared here
-// CHECK-NOTES: [[@LINE-33]]:30: note: expanded from macro 'MOCK_METHOD2'
-// CHECK-NOTES: [[@LINE-36]]:7: note: expanded from macro 'GMOCK_METHOD2_'
+// CHECK-NOTES: [[@LINE-18]]:42: note: 'param_two' declared here
+// CHECK-NOTES: [[@LINE-14]]:3: note: actual callee ('gmock_Method') is 
declared here
+// CHECK-NOTES: [[@LINE-32]]:30: note: expanded from macro 'MOCK_METHOD2'
+// CHECK-NOTES: [[@LINE-35]]:7: note: expanded from macro 'GMOCK_METHOD2_'
 // CHECK-NOTES: note: expanded from here
 // CHECK-FIXES:   EXPECT_CALL(m, Method(/*param_one=*/1, /*param_two=*/2));
   EXPECT_CALL(m, Method2(/*p_on=*/3, /*p_two=*/4));
 // CHECK-NOTES: [[@LINE-1]]:26: warning: argument name 'p_on' in comment does 
not match parameter name 'p_one'
-// CHECK-NOTES: [[@LINE-2]]:26: note: FIX-IT applied suggested code changes
-// CHECK-NOTES: [[@LINE-27]]:28: note: 'p_one' declared here
-// CHECK-NOTES: [[@LINE-23]]:3: note: actual callee ('gmock_Method2') is 
declared here
-// CHECK-NOTES: [[@LINE-41]]:36: note: expanded from macro 'MOCK_CONST_METHOD2'
-// CHECK-NOTES: [[@LINE-45]]:7: note: expanded from macro 'GMOCK_METHOD2_'
+// CHECK-NOTES: [[@LINE-25]]:28: note: 'p_one' declared here
+// CHECK-NOTES: [[@LINE-21]]:3: note: actual callee ('gmock_Method2') is 
declared here
+// CHECK-NOTES: [[@LINE-39]]:36: note: expanded from macro 'MOCK_CONST_METHOD2'
+// CHECK-NOTES: [[@LINE-43]]:7: note: expanded from macro 'GMOCK_METHOD2_'
 // CHECK-NOTES: note: expanded from here
 // CHECK-FIXES:   EXPECT_CALL(m, Method2(/*p_one=*/3, /*p_two=*/4));
 
@@ -105,18 +103,16 @@ void test_gmock_expectations() {
   #define PARAM2 22
   EXPECT_CALL(m, Method2(/*p_on1=*/PARAM1, /*p_tw2=*/PARAM2));
 // CHECK-NOTES: [[@LINE-1]]:26: warning: argument name 'p_on1' in comment does 
not match parameter name 'p_one'
-// CHECK-NOTES: [[@LINE-2]]:26: note: FIX-IT applied suggested code changes
-// CHECK-NOTES: [[@LINE-39]]:28: note: 'p_one' declared here
-// CHECK-NOTES: [[@LINE-35]]:3: note: actual callee ('gmock_Method2') is 
declared here
-// CHECK-NOTES: [[@LINE-53]]:36: note: expanded from macro 'MOCK_CONST_METHOD2'
-// CHECK-NOTES: [[@LINE-57]]:7: note: expanded from macro 'GMOCK_METHOD2_'
+// CHECK-NOTES: [[@LINE-36]]:28: note: 'p_one' declared here
+// CHECK-NOTES: [[@LINE-32]]:3: note: actual callee ('gmock_Method2') is 
declared here
+// CHECK-NOTES: [[@LINE-50]]:36: note: expanded from macro 'MOCK_CONST_METHOD2'
+// CHECK-NOTES: [[@LINE-54]]:7: note: expanded from macro 'GMOCK_METHOD2_'
 // CHECK-NOTES: note: expanded from here
-// CHECK-NOTES: [[@LINE-8]]:44: warning: argument name 'p_tw2' in comment does 
not match parameter name 'p_two'
-// CHECK-NOTES: [[@LINE-9]]:44: note: FIX-IT applied suggested code changes
-// CHECK-NOTES: [[@LINE-46]]:39: note: 'p_two' declared here
-// CHECK-NOTES: [[@LINE-42]]:3: note: actual callee ('gmock_Method2') is 
declared here
-// CHECK-NOTES: [[@LINE-60]]:36: note: expanded from macro 'MOCK_CONST_METHOD2'
-// CHECK-NOTES: [[@LINE-64]]:7: note: expanded from macro 'GMOCK_METHOD2_'
+// CHECK-NOTES: [[@LINE-7]]:44: warning: argument name 'p_tw2' in comment does 
not match parameter name 'p_two'
+// CHECK-NOTES: [[@LINE-42]]:39: note: 'p_two' declared here
+// CHECK-NOTES: [[@LINE-38]]:3: note: actual callee ('gmo

[clang-tools-extra] r343848 - [clang-tidy] Replace deprecated std::ios_base aliases

2018-10-05 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Fri Oct  5 06:36:00 2018
New Revision: 343848

URL: http://llvm.org/viewvc/llvm-project?rev=343848&view=rev
Log:
[clang-tidy] Replace deprecated std::ios_base aliases

This check warns the uses of the deprecated member types of std::ios_base
and replaces those that have a non-deprecated equivalent.

Patch by andobence!

Reviewd by: alexfh

Revision ID: https://reviews.llvm.org/D51332

Added:

clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-deprecated-ios-base-aliases.rst

clang-tools-extra/trunk/test/clang-tidy/modernize-deprecated-ios-base-aliases.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt?rev=343848&r1=343847&r2=343848&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt Fri Oct  5 
06:36:00 2018
@@ -4,6 +4,7 @@ add_clang_library(clangTidyModernizeModu
   AvoidBindCheck.cpp
   ConcatNestedNamespacesCheck.cpp
   DeprecatedHeadersCheck.cpp
+  DeprecatedIosBaseAliasesCheck.cpp
   LoopConvertCheck.cpp
   LoopConvertUtils.cpp
   MakeSharedCheck.cpp

Added: 
clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp?rev=343848&view=auto
==
--- 
clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp 
(added)
+++ 
clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp 
Fri Oct  5 06:36:00 2018
@@ -0,0 +1,80 @@
+//===--- DeprecatedIosBaseAliasesCheck.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 "DeprecatedIosBaseAliasesCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+static const std::array DeprecatedTypes = {
+"::std::ios_base::io_state",  "::std::ios_base::open_mode",
+"::std::ios_base::seek_dir",  "::std::ios_base::streamoff",
+"::std::ios_base::streampos",
+};
+
+static const llvm::StringMap ReplacementTypes = {
+{"io_state", "iostate"},
+{"open_mode", "openmode"},
+{"seek_dir", "seekdir"}};
+
+void DeprecatedIosBaseAliasesCheck::registerMatchers(MatchFinder *Finder) {
+  // Only register the matchers for C++; the functionality currently does not
+  // provide any benefit to other languages, despite being benign.
+  if (!getLangOpts().CPlusPlus)
+return;
+
+  auto IoStateDecl = typedefDecl(hasAnyName(DeprecatedTypes)).bind("TypeDecl");
+  auto IoStateType =
+  qualType(hasDeclaration(IoStateDecl), unless(elaboratedType()));
+
+  Finder->addMatcher(typeLoc(loc(IoStateType)).bind("TypeLoc"), this);
+}
+
+void DeprecatedIosBaseAliasesCheck::check(
+const MatchFinder::MatchResult &Result) {
+  SourceManager &SM = *Result.SourceManager;
+
+  const auto *Typedef = Result.Nodes.getNodeAs("TypeDecl");
+  StringRef TypeName = Typedef->getName();
+  bool HasReplacement = ReplacementTypes.count(TypeName);
+
+  const auto *TL = Result.Nodes.getNodeAs("TypeLoc");
+  SourceLocation IoStateLoc = TL->getBeginLoc();
+
+  // Do not generate fixits for matches depending on template arguments and
+  // macro expansions.
+  bool Fix = HasReplacement && !TL->getType()->isDependentType();
+  if (IoStateLoc.isMacroID()) {
+IoStateLoc = SM.getSpellingLoc(IoStateLoc);
+Fix = false;
+  }
+
+  SourceLocation EndLoc = IoStateLoc.getLocWithOffset(TypeName.size() - 1);
+
+  if (HasReplacement) {
+auto FixName = ReplacementTypes.lookup(TypeName);
+auto Builder = diag(IoStateLoc, "'std::ios_base::%0' is deprecated; use "
+"'std::ios_base::%1' instead")
+   << TypeName << FixName;
+
+if (Fix)
+  Builder << FixItHint::CreateReplacement(SourceRange(IoStateLoc, EndLoc),
+  FixName);
+  } else
+diag(IoStateLoc, "'std::ios_base::%0' is deprecated") << TypeNa

[clang-tools-extra] r343850 - [clang-tidy] NFC refactor lexer-utils to be usable without ASTContext

2018-10-05 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Fri Oct  5 07:15:19 2018
New Revision: 343850

URL: http://llvm.org/viewvc/llvm-project?rev=343850&view=rev
Log:
[clang-tidy] NFC refactor lexer-utils to be usable without ASTContext

Summary:
This patch is a small refactoring necessary for
'readability-isolate-declaration' and does not introduce functional changes.
It allows to use the utility functions without a full `ASTContext` and requires 
only the `SourceManager` and the `LangOpts`.

Reviewers: alexfh, aaron.ballman, hokein

Reviewed By: alexfh

Subscribers: nemanjai, xazax.hun, kbarton, cfe-commits

Tags: #clang-tools-extra

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

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

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
clang-tools-extra/trunk/clang-tidy/utils/FixItHintUtils.cpp
clang-tools-extra/trunk/clang-tidy/utils/LexerUtils.cpp
clang-tools-extra/trunk/clang-tidy/utils/LexerUtils.h

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.cpp?rev=343850&r1=343849&r2=343850&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.cpp Fri 
Oct  5 07:15:19 2018
@@ -91,8 +91,9 @@ static std::vector> Comments;
   while (Loc.isValid()) {
-clang::Token Tok =
-utils::lexer::getPreviousToken(*Ctx, Loc, /*SkipComments=*/false);
+clang::Token Tok = utils::lexer::getPreviousToken(
+Loc, Ctx->getSourceManager(), Ctx->getLangOpts(),
+/*SkipComments=*/false);
 if (Tok.isNot(tok::comment))
   break;
 Loc = Tok.getLocation();

Modified: 
clang-tools-extra/trunk/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp?rev=343850&r1=343849&r2=343850&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp 
Fri Oct  5 07:15:19 2018
@@ -40,7 +40,8 @@ void SuspiciousSemicolonCheck::check(con
 return;
 
   ASTContext &Ctxt = *Result.Context;
-  auto Token = utils::lexer::getPreviousToken(Ctxt, LocStart);
+  auto Token = utils::lexer::getPreviousToken(LocStart, 
Ctxt.getSourceManager(),
+  Ctxt.getLangOpts());
   auto &SM = *Result.SourceManager;
   unsigned SemicolonLine = SM.getSpellingLineNumber(LocStart);
 

Modified: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp?rev=343850&r1=343849&r2=343850&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp 
Fri Oct  5 07:15:19 2018
@@ -120,12 +120,14 @@ struct IntializerInsertion {
 switch (Placement) {
 case InitializerPlacement::New:
   Location = utils::lexer::getPreviousToken(
- Context, Constructor.getBody()->getBeginLoc())
+ Constructor.getBody()->getBeginLoc(),
+ Context.getSourceManager(), Context.getLangOpts())
  .getLocation();
   break;
 case InitializerPlacement::Before:
   Location = utils::lexer::getPreviousToken(
- Context, Where->getSourceRange().getBegin())
+ Where->getSourceRange().getBegin(),
+ Context.getSourceManager(), Context.getLangOpts())
  .getLocation();
   break;
 case InitializerPlacement::After:

Modified: clang-tools-extra/trunk/clang-tidy/utils/FixItHintUtils.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/FixItHintUtils.cpp?rev=343850&r1=343849&r2=343850&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/utils/FixItHintUtils.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/utils/FixItHintUtils.cpp Fri Oct  5 
07:15:19 2018
@@ -18,7 +18,8 @@ namespace fixit {
 
 FixItHint changeVarDeclToReference(const VarDecl &Var, ASTContext &Context) {
   SourceLocation AmpLocation = Var.getLocation();
-  auto Token = utils::lexer::getPreviousToken(Context, AmpLocation);
+  auto Token = utils::lexe

Re: [clang-tools-extra] r343848 - [clang-tidy] Replace deprecated std::ios_base aliases

2018-10-09 Thread Jonas Toth via cfe-commits
Hi, sorry for the late response. I will look at it, currently multiple
things to do though.


Am 09.10.2018 um 11:10 schrieb Mikael Holmén via cfe-commits:
> Hi Jonas, Bence,
>
> On 10/08/2018 08:22 AM, Mikael Holmén via cfe-commits wrote:
>> Hi Jonas,
>>
>> I get the follwing warning/error when compiling this commit with clang 3.6:
>>
>> ../tools/clang/tools/extra/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp:21:5:
>> error: suggest braces around initialization of subobject
>> [-Werror,-Wmissing-braces]
>>   "::std::ios_base::io_state",  "::std::ios_base::open_mode",
>>   ^~~
>> 1 error generated.
>>
>>
>> It looks like r343916 tried to fix it (but failed? and was reverted) so
>> I suppose I'm not alone seeing it.
> This is still giving the warning with clang 3.6.
>
> Thanks,
> Mikael
>
>> Regards,
>> Mikael
>>
>> On 10/05/2018 03:36 PM, Jonas Toth via cfe-commits wrote:
>>> Author: jonastoth
>>> Date: Fri Oct  5 06:36:00 2018
>>> New Revision: 343848
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=343848&view=rev
>>> Log:
>>> [clang-tidy] Replace deprecated std::ios_base aliases
>>>
>>> This check warns the uses of the deprecated member types of std::ios_base
>>> and replaces those that have a non-deprecated equivalent.
>>>
>>> Patch by andobence!
>>>
>>> Reviewd by: alexfh
>>>
>>> Revision ID: https://reviews.llvm.org/D51332
>>>
>>> Added:
>>>   
>>> clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp
>>>   
>>> clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.h
>>>   
>>> clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-deprecated-ios-base-aliases.rst
>>>   
>>> clang-tools-extra/trunk/test/clang-tidy/modernize-deprecated-ios-base-aliases.cpp
>>> Modified:
>>>   clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
>>>   clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp
>>>   clang-tools-extra/trunk/docs/ReleaseNotes.rst
>>>   clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
>>>
>>> Modified: clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt?rev=343848&r1=343847&r2=343848&view=diff
>>> ==
>>> --- clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt (original)
>>> +++ clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt Fri Oct  5 
>>> 06:36:00 2018
>>> @@ -4,6 +4,7 @@ add_clang_library(clangTidyModernizeModu
>>>  AvoidBindCheck.cpp
>>>  ConcatNestedNamespacesCheck.cpp
>>>  DeprecatedHeadersCheck.cpp
>>> +  DeprecatedIosBaseAliasesCheck.cpp
>>>  LoopConvertCheck.cpp
>>>  LoopConvertUtils.cpp
>>>  MakeSharedCheck.cpp
>>>
>>> Added: 
>>> clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp?rev=343848&view=auto
>>> ==
>>> --- 
>>> clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp
>>>  (added)
>>> +++ 
>>> clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp
>>>  Fri Oct  5 06:36:00 2018
>>> @@ -0,0 +1,80 @@
>>> +//===--- DeprecatedIosBaseAliasesCheck.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 "DeprecatedIosBaseAliasesCheck.h"
>>> +#include "clang/AST/ASTContext.h"
>>> +#include "clang/ASTMatchers/ASTMatchFinder.h"
>>> +
>>> +using namespace clang::ast_matchers;
>>> +
>>> +namespace clang

  1   2   >