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
> <cfe-commits@lists.llvm.org <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=rev
> <http://llvm.org/viewvc/llvm-project?rev=314808=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=314807=314808=diff
> 
> <http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp?rev=314808=314807=314808=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=auto
> 
> <http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-bug34747.cpp?rev=314808=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 <<(C);
> +};
> +
> +template 
> +struct foo {
> +  typedef OutputStream stream_type;
> +  foo(stream_type ) {
> +    o << 'x'; // warning occured here, fixed now
> +  }
> +};
> +
> +void bar(OutputStream ) {
> +  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=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=314912=314913=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=314912=314913=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=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',

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
> 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=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


[clang-tools-extra] r312102 - [clang-tidy] test commit for granted access

2017-08-30 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Aug 30 00:50:28 2017
New Revision: 312102

URL: http://llvm.org/viewvc/llvm-project?rev=312102=rev
Log:
[clang-tidy] test commit for granted access

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

Modified: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/NoMallocCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/NoMallocCheck.cpp?rev=312102=312101=312102=diff
==
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/NoMallocCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/NoMallocCheck.cpp Wed 
Aug 30 00:50:28 2017
@@ -29,7 +29,7 @@ Matcher hasAnyListedName(c
   utils::options::parseStringList(FunctionNames);
   return hasAnyName(std::vector(NameList.begin(), NameList.end()));
 }
-}
+} // namespace
 
 void NoMallocCheck::storeOptions(ClangTidyOptions::OptionMap ) {
   Options.store(Opts, "Allocations", AllocList);


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


Re: [clang-tools-extra] r312134 - [clang-tidy] Improve hicpp-exception-baseclass to handle generic code better

2017-08-30 Thread Jonas Toth via cfe-commits

Hello Diana,

you are right, i did not commit anything earlier, I am really new to the 
process, these were my first commits.


I am sorry that i broke the bots, i thought i would get an automatic 
mail, when they find a problem and i was in the commit range. Is there 
anything automated to find out such issues? I feel a little overwhelmed 
with this big amount of builders.


Sorry again, I will look into it.

Regard, Jonas


Am 30.08.2017 um 18:12 schrieb Diana Picus:

Hi Jonas,

I haven't seen any commit from you (*) fixing the buildbot failures
caused by your previous commit (r312122). This has been keeping
several bots red for quite a while:
http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15/builds/10590
http://lab.llvm.org:8011/builders/clang-x86-windows-msvc2015/builds/6845
etc etc

It's customary to keep an eye on the buildbots and either revert or
fix such problems as soon as possible. It's particularly inappropriate
to commit something else on top before dealing with the bot failures.

For the record, Alex has been trying to help you on IRC in #llvm:
"alexlorenz: jonas_toth: btw, char is not signed by default (it's
platform-specific), so you should use 'signed char' in your clang-tidy
test to fix the bot failures"

Please be more careful with the buildbots in the future.

Thanks,
Diana

(*) My apologies if I missed it, but I really don't see anything in
cfe-commits nor in the situation of the bots to reflect that.

On 30 August 2017 at 17:59, Jonas Toth via cfe-commits
<cfe-commits@lists.llvm.org> wrote:

Author: jonastoth
Date: Wed Aug 30 08:59:01 2017
New Revision: 312134

URL: http://llvm.org/viewvc/llvm-project?rev=312134=rev
Log:
[clang-tidy] Improve hicpp-exception-baseclass to handle generic code better

Summary:
This patch is a followup to the first revision D36583, that had problems with
generic code and its diagnostic messages, which were found by @lebedev.ri

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

Reviewed By: aaron.ballman, lebedev.ri

Subscribers: klimek, sbenza, cfe-commits, JDevlieghere, lebedev.ri, xazax.hun

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

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=312134=312133=312134=diff
==
--- clang-tools-extra/trunk/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp Wed 
Aug 30 08:59:01 2017
@@ -11,8 +11,6 @@
  #include "clang/AST/ASTContext.h"
  #include "clang/ASTMatchers/ASTMatchFinder.h"

-#include 
-
  using namespace clang::ast_matchers;

  namespace clang {
@@ -24,20 +22,23 @@ void ExceptionBaseclassCheck::registerMa
  return;

Finder->addMatcher(
-  cxxThrowExpr(
-  allOf(
-  has(expr(unless(hasType(cxxRecordDecl(
-  isSameOrDerivedFrom(hasName("std::exception"))),
-  eachOf(has(expr(hasType(namedDecl().bind("decl", 
anything(
+  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(
.bind("bad_throw"),
this);
  }

  void ExceptionBaseclassCheck::check(const MatchFinder::MatchResult ) {
const auto *BadThrow = Result.Nodes.getNodeAs("bad_throw");
-  diag(BadThrow->getLocStart(),
-   "throwing an exception whose type is not derived from 'std::exception'")
-  << BadThrow->getSourceRange();
+
+  diag(BadThrow->getSubExpr()->getLocStart(), "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)

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=312134=312133=312134=diff
==
--- clang-tools-extra/trunk/test

[clang-tools-extra] r312134 - [clang-tidy] Improve hicpp-exception-baseclass to handle generic code better

2017-08-30 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Aug 30 08:59:01 2017
New Revision: 312134

URL: http://llvm.org/viewvc/llvm-project?rev=312134=rev
Log:
[clang-tidy] Improve hicpp-exception-baseclass to handle generic code better

Summary:
This patch is a followup to the first revision D36583, that had problems with 
generic code and its diagnostic messages, which were found by @lebedev.ri

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

Reviewed By: aaron.ballman, lebedev.ri

Subscribers: klimek, sbenza, cfe-commits, JDevlieghere, lebedev.ri, xazax.hun

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

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=312134=312133=312134=diff
==
--- clang-tools-extra/trunk/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp Wed 
Aug 30 08:59:01 2017
@@ -11,8 +11,6 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 
-#include 
-
 using namespace clang::ast_matchers;
 
 namespace clang {
@@ -24,20 +22,23 @@ void ExceptionBaseclassCheck::registerMa
 return;
 
   Finder->addMatcher(
-  cxxThrowExpr(
-  allOf(
-  has(expr(unless(hasType(cxxRecordDecl(
-  isSameOrDerivedFrom(hasName("std::exception"))),
-  eachOf(has(expr(hasType(namedDecl().bind("decl", 
anything(
+  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(
   .bind("bad_throw"),
   this);
 }
 
 void ExceptionBaseclassCheck::check(const MatchFinder::MatchResult ) {
   const auto *BadThrow = Result.Nodes.getNodeAs("bad_throw");
-  diag(BadThrow->getLocStart(),
-   "throwing an exception whose type is not derived from 'std::exception'")
-  << BadThrow->getSourceRange();
+
+  diag(BadThrow->getSubExpr()->getLocStart(), "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)

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=312134=312133=312134=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/hicpp-exception-baseclass.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/hicpp-exception-baseclass.cpp Wed 
Aug 30 08:59:01 2017
@@ -5,38 +5,175 @@ class exception {};
 } // namespace std
 
 class derived_exception : public std::exception {};
+class deep_hierarchy : public derived_exception {};
 class non_derived_exception {};
+class terrible_idea : public non_derived_exception, public derived_exception 
{};
+
+// FIXME: More complicated kinds of inheritance should be checked later, but 
there is
+// currently no way use ASTMatchers for this kind of task.
+#if 0
+class bad_inheritance : private std::exception {};
+class no_good_inheritance : protected std::exception {};
+class really_creative : public non_derived_exception, private std::exception 
{};
+#endif
 
 void problematic() {
   try {
-throw int(42); // Built in is not allowed
-// CHECK-MESSAGES: [[@LINE-1]]:5: warning: throwing an exception whose type is 
not derived from 'std::exception'
+throw int(42);
+// CHECK-MESSAGES: [[@LINE-1]]:11: warning: throwing an exception whose 
type 'int' is not derived from 'std::exception'
   } catch (int e) {
   }
-  throw int(42); // Bad
-// CHECK-MESSAGES: [[@LINE-1]]:3: warning: throwing an exception whose type is 
not derived from 'std::exception'
+  throw int(42);
+  // CHECK-MESSAGES: [[@LINE-1]]:9: warning: throwing an exception whose type 
'int' is not derived from 'std::exception'
+
+  try {
+throw 12;
+// CHECK-MESSAGES: [[@LINE-1]]:11: warning: throwing an exception whose 
type 'int' is not derived from 'std::exception'
+  } catch (...) {
+throw; // Ok, even if the type is not known, conforming code can never 
rethrow a non-std::exception object.
+  }
 
   try {
-   

[clang-tools-extra] r312141 - [clang-tidy] fix buildbot

2017-08-30 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Aug 30 10:21:41 2017
New Revision: 312141

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

Use `signed char` instead of `char`.

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=312141=312140=312141=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise.cpp Wed Aug 30 
10:21:41 2017
@@ -17,10 +17,10 @@ StreamClass >>(StreamClass ,
 }
 struct AnotherStream {
   AnotherStream <<(unsigned char c) { return *this; }
-  AnotherStream <<(char c) { return *this; }
+  AnotherStream <<(signed char c) { return *this; }
 
   AnotherStream >>(unsigned char c) { return *this; }
-  AnotherStream >>(char c) { return *this; }
+  AnotherStream >>(signed char c) { return *this; }
 };
 
 void binary_bitwise() {
@@ -47,8 +47,8 @@ void binary_bitwise() {
 
   unsigned char UByte1 = 0u;
   unsigned char UByte2 = 16u;
-  char SByte1 = 0;
-  char SByte2 = 16;
+  signed char SByte1 = 0;
+  signed char SByte2 = 16;
 
   UByte1 = UByte1 & UByte2; // Ok
   UByte1 = SByte1 & UByte2;
@@ -88,12 +88,12 @@ void binary_bitwise() {
 }
 
 void f1(unsigned char c) {}
-void f2(char c) {}
+void f2(signed char c) {}
 void f3(int c) {}
 
 void unary_bitwise() {
   unsigned char UByte1 = 0u;
-  char SByte1 = 0;
+  signed char SByte1 = 0;
 
   UByte1 = ~UByte1; // Ok
   SByte1 = ~UByte1;
@@ -164,7 +164,7 @@ void streams_should_work() {
 
   AnotherStream as;
   unsigned char uc = 1u;
-  char sc = 1;
+  signed char sc = 1;
   as << uc; // Ok
   as << sc; // Ok
   as >> uc; // Ok


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


Re: [clang-tools-extra] r312134 - [clang-tidy] Improve hicpp-exception-baseclass to handle generic code better

2017-08-30 Thread Jonas Toth via cfe-commits

Hi Diana,

i will investigate this issue. Can i see from somewhere, what email my 
buildbot uses?


To fix the break I created a new Patch https://reviews.llvm.org/D37301

What is the right thing now, wait for review or just commit it and that 
review would occur on the commit?


Thank you for your help and patience.


Regard Jonas


Am 30.08.2017 um 18:25 schrieb Diana Picus:

Hi Jonas,

Usually the buildbots send emails when you're in the commit range. I'm
surprised that you haven't received anything. Are you sure you don't
have some mail filters that are catching them and sending them
somewhere unexpected?

In any case, you can see a live-but-slow buildbot status here:
http://lab.llvm.org:8011/console
I usually keep an eye on that when I commit something.

We also have the #llvm and #llvm-build channels where the buildbots
post reports of failed builds and who is in the commit range, so you
should see those unless you're specifically ignoring the
llvmbb-llvm-build, bb9-chapuni, bb-pgr and green-dragon-bot users.

Hope that helps,
Diana

On 30 August 2017 at 18:16, Jonas Toth <jonas.t...@gmail.com> wrote:

Hello Diana,

you are right, i did not commit anything earlier, I am really new to the
process, these were my first commits.

I am sorry that i broke the bots, i thought i would get an automatic mail,
when they find a problem and i was in the commit range. Is there anything
automated to find out such issues? I feel a little overwhelmed with this big
amount of builders.

Sorry again, I will look into it.

Regard, Jonas



Am 30.08.2017 um 18:12 schrieb Diana Picus:

Hi Jonas,

I haven't seen any commit from you (*) fixing the buildbot failures
caused by your previous commit (r312122). This has been keeping
several bots red for quite a while:
http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15/builds/10590
http://lab.llvm.org:8011/builders/clang-x86-windows-msvc2015/builds/6845
etc etc

It's customary to keep an eye on the buildbots and either revert or
fix such problems as soon as possible. It's particularly inappropriate
to commit something else on top before dealing with the bot failures.

For the record, Alex has been trying to help you on IRC in #llvm:
"alexlorenz: jonas_toth: btw, char is not signed by default (it's
platform-specific), so you should use 'signed char' in your clang-tidy
test to fix the bot failures"

Please be more careful with the buildbots in the future.

Thanks,
Diana

(*) My apologies if I missed it, but I really don't see anything in
cfe-commits nor in the situation of the bots to reflect that.

On 30 August 2017 at 17:59, Jonas Toth via cfe-commits
<cfe-commits@lists.llvm.org> wrote:

Author: jonastoth
Date: Wed Aug 30 08:59:01 2017
New Revision: 312134

URL: http://llvm.org/viewvc/llvm-project?rev=312134=rev
Log:
[clang-tidy] Improve hicpp-exception-baseclass to handle generic code
better

Summary:
This patch is a followup to the first revision D36583, that had problems
with
generic code and its diagnostic messages, which were found by @lebedev.ri

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

Reviewed By: aaron.ballman, lebedev.ri

Subscribers: klimek, sbenza, cfe-commits, JDevlieghere, lebedev.ri,
xazax.hun

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

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=312134=312133=312134=diff

==
--- clang-tools-extra/trunk/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
(original)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
Wed Aug 30 08:59:01 2017
@@ -11,8 +11,6 @@
   #include "clang/AST/ASTContext.h"
   #include "clang/ASTMatchers/ASTMatchFinder.h"

-#include 
-
   using namespace clang::ast_matchers;

   namespace clang {
@@ -24,20 +22,23 @@ void ExceptionBaseclassCheck::registerMa
   return;

 Finder->addMatcher(
-  cxxThrowExpr(
-  allOf(
-  has(expr(unless(hasType(cxxRecordDecl(
-  isSameOrDerivedFrom(hasName("std::exception"))),
-  eachOf(has(expr(hasType(namedDecl().bind("decl",
anything(
+
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(
 .bind("bad_throw"),
 this);
   }

   void ExceptionBaseclassCheck::check(const MatchFinder::Ma

[clang-tools-extra] r312901 - [clang-tidy] add more aliases for the hicpp module

2017-09-11 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Mon Sep 11 02:20:07 2017
New Revision: 312901

URL: http://llvm.org/viewvc/llvm-project?rev=312901=rev
Log:
[clang-tidy] add more aliases for the hicpp module

This patch will introduce even more aliases for the hicpp-module to already 
existing
checks and is a follow up for D30383 finishing the other sections.
It fixes a forgotten highlight in hicpp-braces-around-statements.rst, too.

Added:
clang-tools-extra/trunk/docs/clang-tidy/checks/hicpp-deprecated-headers.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/hicpp-move-const-arg.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/hicpp-no-array-decay.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/hicpp-no-malloc.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/hicpp-static-assert.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/hicpp-use-auto.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/hicpp-use-emplace.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/hicpp-use-noexcept.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/hicpp-use-nullptr.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/hicpp-vararg.rst
Modified:
clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/hicpp-braces-around-statements.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp?rev=312901=312900=312901=diff
==
--- clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp Mon Sep 11 
02:20:07 2017
@@ -10,16 +10,26 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "../cppcoreguidelines/NoMallocCheck.h"
+#include "../cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.h"
 #include "../cppcoreguidelines/ProTypeMemberInitCheck.h"
+#include "../cppcoreguidelines/ProTypeVarargCheck.h"
 #include "../cppcoreguidelines/SpecialMemberFunctionsCheck.h"
 #include "../google/DefaultArgumentsCheck.h"
 #include "../google/ExplicitConstructorCheck.h"
+#include "../misc/MoveConstantArgumentCheck.h"
 #include "../misc/NewDeleteOverloadsCheck.h"
 #include "../misc/NoexceptMoveConstructorCheck.h"
+#include "../misc/StaticAssertCheck.h"
 #include "../misc/UndelegatedConstructor.h"
 #include "../misc/UseAfterMoveCheck.h"
+#include "../modernize/DeprecatedHeadersCheck.h"
+#include "../modernize/UseAutoCheck.h"
+#include "../modernize/UseEmplaceCheck.h"
 #include "../modernize/UseEqualsDefaultCheck.h"
 #include "../modernize/UseEqualsDeleteCheck.h"
+#include "../modernize/UseNoexceptCheck.h"
+#include "../modernize/UseNullptrCheck.h"
 #include "../modernize/UseOverrideCheck.h"
 #include "../readability/BracesAroundStatementsCheck.h"
 #include "../readability/FunctionSizeCheck.h"
@@ -37,6 +47,8 @@ public:
   void addCheckFactories(ClangTidyCheckFactories ) override {
 CheckFactories.registerCheck(
 "hicpp-braces-around-statements");
+CheckFactories.registerCheck(
+"hicpp-deprecated-headers");
 CheckFactories.registerCheck(
 "hicpp-exception-baseclass");
 CheckFactories.registerCheck(
@@ -51,22 +63,40 @@ public:
 "hicpp-invalid-access-moved");
 CheckFactories.registerCheck(
 "hicpp-member-init");
+CheckFactories.registerCheck(
+"hicpp-move-const-arg");
 CheckFactories.registerCheck(
 "hicpp-new-delete-operators");
 CheckFactories.registerCheck(
 "hicpp-noexcept-move");
+CheckFactories
+.registerCheck(
+"hicpp-no-array-decay");
 CheckFactories.registerCheck("hicpp-no-assembler");
+CheckFactories.registerCheck(
+"hicpp-no-malloc");
 CheckFactories
 .registerCheck(
 "hicpp-special-member-functions");
+CheckFactories.registerCheck(
+"hicpp-static-assert");
+CheckFactories.registerCheck("hicpp-use-auto");
 CheckFactories.registerCheck(
 "hicpp-undelegated-constructor");
+CheckFactories.registerCheck(
+"hicpp-use-emplace");
 CheckFactories.registerCheck(
 "hicpp-use-equals-default");
 CheckFactories.registerCheck(
 "hicpp-use-equals-delete");
+CheckFactories.registerCheck(
+"hicpp-use-noexcept");
+CheckFactories.registerCheck(
+"hicpp-use-nullptr");
 CheckFactories.registerCheck(
 "hicpp-use-override");
+CheckFactories.registerCheck(
+"hicpp-vararg");
   }
 };
 

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=312901=312900=312901=diff

[clang-tools-extra] r313059 - [clang-tidy] Revert Implement type-based check for gsl::owner

2017-09-12 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Sep 12 11:35:54 2017
New Revision: 313059

URL: http://llvm.org/viewvc/llvm-project?rev=313059=rev
Log:
[clang-tidy] Revert Implement type-based check for gsl::owner

This should unbreak the buildbot for visual studio 2015 for now.

Removed:
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
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/utils/Matchers.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/cppcoreguidelines/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt?rev=313059=313058=313059=diff
==
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt 
(original)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt Tue Sep 
12 11:35:54 2017
@@ -4,7 +4,6 @@ add_clang_library(clangTidyCppCoreGuidel
   CppCoreGuidelinesTidyModule.cpp
   InterfacesGlobalInitCheck.cpp
   NoMallocCheck.cpp
-  OwningMemoryCheck.cpp
   ProBoundsArrayToPointerDecayCheck.cpp
   ProBoundsConstantArrayIndexCheck.cpp
   ProBoundsPointerArithmeticCheck.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=313059=313058=313059=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 Tue Sep 12 11:35:54 2017
@@ -13,7 +13,6 @@
 #include "../misc/UnconventionalAssignOperatorCheck.h"
 #include "InterfacesGlobalInitCheck.h"
 #include "NoMallocCheck.h"
-#include "OwningMemoryCheck.h"
 #include "ProBoundsArrayToPointerDecayCheck.h"
 #include "ProBoundsConstantArrayIndexCheck.h"
 #include "ProBoundsPointerArithmeticCheck.h"
@@ -38,8 +37,6 @@ public:
 CheckFactories.registerCheck(
 "cppcoreguidelines-interfaces-global-init");
 CheckFactories.registerCheck("cppcoreguidelines-no-malloc");
-CheckFactories.registerCheck(
-"cppcoreguidelines-owning-memory");
 CheckFactories.registerCheck(
 "cppcoreguidelines-pro-bounds-array-to-pointer-decay");
 CheckFactories.registerCheck(

Removed: 
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=313058=auto
==
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp 
(removed)
@@ -1,315 +0,0 @@
-//===--- OwningMemoryCheck.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 "OwningMemoryCheck.h"
-#include "../utils/Matchers.h"
-#include "../utils/OptionsUtils.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include 
-#include 
-
-using namespace clang::ast_matchers;
-using namespace clang::ast_matchers::internal;
-
-namespace clang {
-namespace tidy {
-namespace cppcoreguidelines {
-
-/// Match common cases, where the owner semantic is relevant, like function
-/// calls, delete expressions and others.
-void OwningMemoryCheck::registerMatchers(MatchFinder *Finder) {
-  if (!getLangOpts().CPlusPlus11)
-return;
-
-  const auto OwnerDecl = typeAliasTemplateDecl(hasName("::gsl::owner"));
-  const auto IsOwnerType = hasType(OwnerDecl);
-  const auto CreatesOwner =
-  anyOf(cxxNewExpr(), callExpr(callee(functionDecl(
-  returns(qualType(hasDeclaration(OwnerDecl)));
-  const auto ConsideredOwner = anyOf(IsOwnerType, CreatesOwner);
-
-  // Find delete expressions that delete non-owners.
-  Finder->addMatcher(
-  cxxDeleteExpr(
-  hasDescendant(
-  declRefExpr(unless(ConsideredOwner)).bind("deleted_variable")))
-  

[clang-tools-extra] r313067 - [clang-tidy] Implement type-based check for `gsl::owner`

2017-09-12 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Sep 12 13:00:42 2017
New Revision: 313067

URL: http://llvm.org/viewvc/llvm-project?rev=313067=rev
Log:
[clang-tidy] Implement type-based check for `gsl::owner`

This check implements the typebased semantic of `gsl::owner`.
Meaning, that 
- only `gsl::owner` is allowed to get `delete`d
- `new` expression must be assigned to `gsl::owner`
- function calls that expect `gsl::owner` as argument, must get either an owner
  or a newly created and recognized resource (in the moment only `new`ed memory)
- assignment to `gsl::owner` must be either a resource or another owner
- functions returning an `gsl::owner` are considered as factories, and their 
result
  must be assigned to an `gsl::owner`
- classes that have an `gsl::owner`-member must declare a non-default destructor

There are some problems that occur when typededuction is in place.
For example `auto Var = function_that_returns_owner();` the type of `Var` will 
not be
an `gsl::owner`. This case is catched, and explicitly noted.

But cases like fully templated functions
```
template  
void f(T t) { delete t; }
// ...
f(gsl::owner(new int(42)));
```
Will created false positive (the deletion is problematic), since the type 
deduction
removes the wrapping `typeAlias`.

Codereview in D36354


Added:
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
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/utils/Matchers.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/cppcoreguidelines/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt?rev=313067=313066=313067=diff
==
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt 
(original)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt Tue Sep 
12 13:00:42 2017
@@ -4,6 +4,7 @@ add_clang_library(clangTidyCppCoreGuidel
   CppCoreGuidelinesTidyModule.cpp
   InterfacesGlobalInitCheck.cpp
   NoMallocCheck.cpp
+  OwningMemoryCheck.cpp
   ProBoundsArrayToPointerDecayCheck.cpp
   ProBoundsConstantArrayIndexCheck.cpp
   ProBoundsPointerArithmeticCheck.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=313067=313066=313067=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 Tue Sep 12 13:00:42 2017
@@ -13,6 +13,7 @@
 #include "../misc/UnconventionalAssignOperatorCheck.h"
 #include "InterfacesGlobalInitCheck.h"
 #include "NoMallocCheck.h"
+#include "OwningMemoryCheck.h"
 #include "ProBoundsArrayToPointerDecayCheck.h"
 #include "ProBoundsConstantArrayIndexCheck.h"
 #include "ProBoundsPointerArithmeticCheck.h"
@@ -37,6 +38,8 @@ public:
 CheckFactories.registerCheck(
 "cppcoreguidelines-interfaces-global-init");
 CheckFactories.registerCheck("cppcoreguidelines-no-malloc");
+CheckFactories.registerCheck(
+"cppcoreguidelines-owning-memory");
 CheckFactories.registerCheck(
 "cppcoreguidelines-pro-bounds-array-to-pointer-decay");
 CheckFactories.registerCheck(

Added: 
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=313067=auto
==
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp 
Tue Sep 12 13:00:42 2017
@@ -0,0 +1,316 @@
+//===--- OwningMemoryCheck.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 "OwningMemoryCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include 

[clang-tools-extra] r313043 - [clang-tidy] Implement type-based check for `gsl::owner`

2017-09-12 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Sep 12 09:20:51 2017
New Revision: 313043

URL: http://llvm.org/viewvc/llvm-project?rev=313043=rev
Log:
[clang-tidy] Implement type-based check for `gsl::owner`

This check implements the typebased semantic of `gsl::owner`.
Meaning, that 
- only `gsl::owner` is allowed to get `delete`d
- `new` expression must be assigned to `gsl::owner`
- function calls that expect `gsl::owner` as argument, must get either an owner
  or a newly created and recognized resource (in the moment only `new`ed memory)
- assignment to `gsl::owner` must be either a resource or another owner
- functions returning an `gsl::owner` are considered as factories, and their 
result
  must be assigned to an `gsl::owner`
- classes that have an `gsl::owner`-member must declare a non-default destructor

There are some problems that occur when typededuction is in place.
For example `auto Var = function_that_returns_owner();` the type of `Var` will 
not be
an `gsl::owner`. This case is catched, and explicitly noted.

But cases like fully templated functions
```
template  
void f(T t) { delete t; }
// ...
f(gsl::owner(new int(42)));
```
Will created false positive (the deletion is problematic), since the type 
deduction
removes the wrapping `typeAlias`.

Please give your comments :)

Added:
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
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/utils/Matchers.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/cppcoreguidelines/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt?rev=313043=313042=313043=diff
==
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt 
(original)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt Tue Sep 
12 09:20:51 2017
@@ -4,6 +4,7 @@ add_clang_library(clangTidyCppCoreGuidel
   CppCoreGuidelinesTidyModule.cpp
   InterfacesGlobalInitCheck.cpp
   NoMallocCheck.cpp
+  OwningMemoryCheck.cpp
   ProBoundsArrayToPointerDecayCheck.cpp
   ProBoundsConstantArrayIndexCheck.cpp
   ProBoundsPointerArithmeticCheck.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=313043=313042=313043=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 Tue Sep 12 09:20:51 2017
@@ -13,6 +13,7 @@
 #include "../misc/UnconventionalAssignOperatorCheck.h"
 #include "InterfacesGlobalInitCheck.h"
 #include "NoMallocCheck.h"
+#include "OwningMemoryCheck.h"
 #include "ProBoundsArrayToPointerDecayCheck.h"
 #include "ProBoundsConstantArrayIndexCheck.h"
 #include "ProBoundsPointerArithmeticCheck.h"
@@ -37,6 +38,8 @@ public:
 CheckFactories.registerCheck(
 "cppcoreguidelines-interfaces-global-init");
 CheckFactories.registerCheck("cppcoreguidelines-no-malloc");
+CheckFactories.registerCheck(
+"cppcoreguidelines-owning-memory");
 CheckFactories.registerCheck(
 "cppcoreguidelines-pro-bounds-array-to-pointer-decay");
 CheckFactories.registerCheck(

Added: 
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=313043=auto
==
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp 
Tue Sep 12 09:20:51 2017
@@ -0,0 +1,315 @@
+//===--- OwningMemoryCheck.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 "OwningMemoryCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"

[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=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=314807=314808=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=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 <<(C);
+};
+
+template 
+struct foo {
+  typedef OutputStream stream_type;
+  foo(stream_type ) {
+o << 'x'; // warning occured here, fixed now
+  }
+};
+
+void bar(OutputStream ) {
+  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=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=314810=314811=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=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=314811=314812=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=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=314815=314816=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 ) {
   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


[clang-tools-extra] r312122 - [clang-tidy] hicpp bitwise operations on signed integers

2017-08-30 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Aug 30 06:32:05 2017
New Revision: 312122

URL: http://llvm.org/viewvc/llvm-project?rev=312122=rev
Log:
[clang-tidy] hicpp bitwise operations on signed integers

Summary:
This check implements the rule [[ 
http://www.codingstandard.com/section/5-6-shift-operators/ | 5.6. HIC++ ]]
that forbidds bitwise operations on signed integer types.

Reviewers: aaron.ballman, hokein, alexfh, Eugene.Zelenko

Reviewed By: aaron.ballman

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

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

Added:
clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp
clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/hicpp-signed-bitwise.rst
clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/hicpp/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.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/hicpp/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/hicpp/CMakeLists.txt?rev=312122=312121=312122=diff
==
--- clang-tools-extra/trunk/clang-tidy/hicpp/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/CMakeLists.txt Wed Aug 30 06:32:05 
2017
@@ -4,6 +4,7 @@ add_clang_library(clangTidyHICPPModule
   ExceptionBaseclassCheck.cpp
   NoAssemblerCheck.cpp
   HICPPTidyModule.cpp
+  SignedBitwiseCheck.cpp
 
   LINK_LIBS
   clangAST

Modified: clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp?rev=312122=312121=312122=diff
==
--- clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp Wed Aug 30 
06:32:05 2017
@@ -26,6 +26,7 @@
 #include "../readability/IdentifierNamingCheck.h"
 #include "ExceptionBaseclassCheck.h"
 #include "NoAssemblerCheck.h"
+#include "SignedBitwiseCheck.h"
 
 namespace clang {
 namespace tidy {
@@ -38,6 +39,8 @@ public:
 "hicpp-braces-around-statements");
 CheckFactories.registerCheck(
 "hicpp-exception-baseclass");
+CheckFactories.registerCheck(
+"hicpp-signed-bitwise");
 CheckFactories.registerCheck(
 "hicpp-explicit-conversions");
 CheckFactories.registerCheck(

Added: 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=312122=auto
==
--- clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp Wed Aug 30 
06:32:05 2017
@@ -0,0 +1,56 @@
+//===--- SignedBitwiseCheck.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 "SignedBitwiseCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+using namespace clang::ast_matchers::internal;
+
+namespace clang {
+namespace tidy {
+namespace hicpp {
+
+void SignedBitwiseCheck::registerMatchers(MatchFinder *Finder) {
+  const auto SignedIntegerOperand =
+  
expr(ignoringImpCasts(hasType(isSignedInteger(.bind("signed_operand");
+
+  // Match binary bitwise operations on signed integer arguments.
+  Finder->addMatcher(
+  binaryOperator(allOf(anyOf(hasOperatorName("|"), hasOperatorName("&"),
+ hasOperatorName("^"), hasOperatorName("<<"),
+ hasOperatorName(">>")),
+   hasEitherOperand(SignedIntegerOperand)))
+  .bind("binary_signed"),
+  this);
+
+  // Match unary operations on signed integer types.
+  Finder->addMatcher(unaryOperator(allOf(hasOperatorName("~"),
+ 
hasUnaryOperand(SignedIntegerOperand)))
+ .bind("unary_signed"),
+ this);
+}
+
+void SignedBitwiseCheck::check(const MatchFinder::MatchResult ) {
+  const ast_matchers::BoundNodes  = Result.Nodes;
+  const auto *SignedBinary = N.getNodeAs("binary_signed");
+  const auto *SignedUnary = N.getNodeAs("unary_signed");
+  const auto *SignedOperand = N.getNodeAs("signed_operand");
+
+  const bool IsUnary = 

[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=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=316092=316093=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=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=316093=316094=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


[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=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=316091=316092=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 ) {
+  const std::vector NameList =
+  utils::options::parseStringList(FunctionNames);
+  return hasAnyName(std::vector(NameList.begin(), NameList.end()));
+}
+} // namespace
+
+void OwningMemoryCheck::storeOptions(ClangTidyOptions::OptionMap ) {
+  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] r318670 - [clang-tidy] revert hicpp-multiway-paths-covered

2017-11-20 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Mon Nov 20 10:01:35 2017
New Revision: 318670

URL: http://llvm.org/viewvc/llvm-project?rev=318670=rev
Log:
[clang-tidy] revert hicpp-multiway-paths-covered

The address sanitizer found a stackoverflow with this patch.
There is no obvious fix. This patch will be reapplied when the problem
is found.

Removed:
clang-tools-extra/trunk/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
clang-tools-extra/trunk/clang-tidy/hicpp/MultiwayPathsCoveredCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/hicpp-multiway-paths-covered.rst

clang-tools-extra/trunk/test/clang-tidy/hicpp-multiway-paths-covered-else.cpp
clang-tools-extra/trunk/test/clang-tidy/hicpp-multiway-paths-covered.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/hicpp/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.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/hicpp/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/hicpp/CMakeLists.txt?rev=318670=318669=318670=diff
==
--- clang-tools-extra/trunk/clang-tidy/hicpp/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/CMakeLists.txt Mon Nov 20 10:01:35 
2017
@@ -2,7 +2,6 @@ set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyHICPPModule
   ExceptionBaseclassCheck.cpp
-  MultiwayPathsCoveredCheck.cpp
   NoAssemblerCheck.cpp
   HICPPTidyModule.cpp
   SignedBitwiseCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp?rev=318670=318669=318670=diff
==
--- clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp Mon Nov 20 
10:01:35 2017
@@ -35,7 +35,6 @@
 #include "../readability/FunctionSizeCheck.h"
 #include "../readability/IdentifierNamingCheck.h"
 #include "ExceptionBaseclassCheck.h"
-#include "MultiwayPathsCoveredCheck.h"
 #include "NoAssemblerCheck.h"
 #include "SignedBitwiseCheck.h"
 
@@ -54,8 +53,6 @@ public:
 "hicpp-exception-baseclass");
 CheckFactories.registerCheck(
 "hicpp-signed-bitwise");
-CheckFactories.registerCheck(
-"hicpp-multiway-paths-covered");
 CheckFactories.registerCheck(
 "hicpp-explicit-conversions");
 CheckFactories.registerCheck(

Removed: clang-tools-extra/trunk/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp?rev=318669=auto
==
--- clang-tools-extra/trunk/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp 
(removed)
@@ -1,179 +0,0 @@
-//===--- MultiwayPathsCoveredCheck.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 "MultiwayPathsCoveredCheck.h"
-#include "clang/AST/ASTContext.h"
-
-#include 
-
-using namespace clang::ast_matchers;
-
-namespace clang {
-namespace tidy {
-namespace hicpp {
-
-void MultiwayPathsCoveredCheck::storeOptions(
-ClangTidyOptions::OptionMap ) {
-  Options.store(Opts, "WarnOnMissingElse", WarnOnMissingElse);
-}
-
-void MultiwayPathsCoveredCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(
-  stmt(allOf(
-  anyOf(switchStmt(forEachSwitchCase(defaultStmt()))
-.bind("switch-default"),
-switchStmt(unless(hasDescendant(switchCase(
-.bind("degenerate-switch"),
-// This matcher must be the last one of the three
-// 'switchStmt' options.
-// Otherwise the cases 'switch-default' and
-// 'degenerate-switch' are not found correctly.
-switchStmt(forEachSwitchCase(unless(defaultStmt(
-.bind("switch-no-default")),
-  switchStmt(hasCondition(allOf(
-  // Match on switch statements that have either a bit-field or an
-  // integer condition. The ordering in 'anyOf()' is important
-  // because the last condition is the most general.
-  anyOf(ignoringImpCasts(memberExpr(hasDeclaration(
-fieldDecl(isBitField()).bind("bitfield",
-

[clang-tools-extra] r318600 - [clang-tidy] Add new hicpp-multiway-paths-covered check for missing branches

2017-11-18 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Sat Nov 18 11:48:33 2017
New Revision: 318600

URL: http://llvm.org/viewvc/llvm-project?rev=318600=rev
Log:
[clang-tidy] Add new hicpp-multiway-paths-covered check for missing branches

Summary:
This check searches for missing `else` branches in `if-else if`-chains and
missing `default` labels in `switch` statements, that use integers as condition.

It is very similar to -Wswitch, but concentrates on integers only, since enums 
are
already covered.

The option to warn for missing `else` branches is deactivated by default, since 
it is
very noise on larger code bases.

Running it on LLVM:
{F5354858} for default configuration
{F5354866} just for llvm/lib/Analysis/ScalarEvolution.cpp, the else-path 
checker is very noisy!

Reviewers: alexfh, aaron.ballman, hokein

Reviewed By: aaron.ballman

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

Tags: #clang-tools-extra

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


Added:
clang-tools-extra/trunk/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
clang-tools-extra/trunk/clang-tidy/hicpp/MultiwayPathsCoveredCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/hicpp-multiway-paths-covered.rst

clang-tools-extra/trunk/test/clang-tidy/hicpp-multiway-paths-covered-else.cpp
clang-tools-extra/trunk/test/clang-tidy/hicpp-multiway-paths-covered.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/hicpp/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.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/hicpp/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/hicpp/CMakeLists.txt?rev=318600=318599=318600=diff
==
--- clang-tools-extra/trunk/clang-tidy/hicpp/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/CMakeLists.txt Sat Nov 18 11:48:33 
2017
@@ -2,6 +2,7 @@ set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyHICPPModule
   ExceptionBaseclassCheck.cpp
+  MultiwayPathsCoveredCheck.cpp
   NoAssemblerCheck.cpp
   HICPPTidyModule.cpp
   SignedBitwiseCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp?rev=318600=318599=318600=diff
==
--- clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp Sat Nov 18 
11:48:33 2017
@@ -35,6 +35,7 @@
 #include "../readability/FunctionSizeCheck.h"
 #include "../readability/IdentifierNamingCheck.h"
 #include "ExceptionBaseclassCheck.h"
+#include "MultiwayPathsCoveredCheck.h"
 #include "NoAssemblerCheck.h"
 #include "SignedBitwiseCheck.h"
 
@@ -53,6 +54,8 @@ public:
 "hicpp-exception-baseclass");
 CheckFactories.registerCheck(
 "hicpp-signed-bitwise");
+CheckFactories.registerCheck(
+"hicpp-multiway-paths-covered");
 CheckFactories.registerCheck(
 "hicpp-explicit-conversions");
 CheckFactories.registerCheck(

Added: clang-tools-extra/trunk/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp?rev=318600=auto
==
--- clang-tools-extra/trunk/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp Sat 
Nov 18 11:48:33 2017
@@ -0,0 +1,179 @@
+//===--- MultiwayPathsCoveredCheck.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 "MultiwayPathsCoveredCheck.h"
+#include "clang/AST/ASTContext.h"
+
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace hicpp {
+
+void MultiwayPathsCoveredCheck::storeOptions(
+ClangTidyOptions::OptionMap ) {
+  Options.store(Opts, "WarnOnMissingElse", WarnOnMissingElse);
+}
+
+void MultiwayPathsCoveredCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  stmt(allOf(
+  anyOf(switchStmt(forEachSwitchCase(defaultStmt()))
+.bind("switch-default"),
+switchStmt(unless(hasDescendant(switchCase(
+.bind("degenerate-switch"),
+// This matcher must be the last one of the three
+// 'switchStmt' options.
+// Otherwise the 

[clang-tools-extra] r319785 - [clang-tidy] adjust cppcoreguidelines-owning-memory documentation

2017-12-05 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Dec  5 08:37:49 2017
New Revision: 319785

URL: http://llvm.org/viewvc/llvm-project?rev=319785=rev
Log:
[clang-tidy] adjust cppcoreguidelines-owning-memory documentation

Summary:
A user of the check opened a bugreport and reported that `std::exchange`
triggers a false positive. I adjusted the doc to include a list of known
(std) constructs that do trigger the issue with templates forgetting the
type alias.

Reviewers: aaron.ballman, alexfh, hokein

Reviewed By: aaron.ballman

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

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

Modified:

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

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-owning-memory.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-owning-memory.rst?rev=319785=319784=319785=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-owning-memory.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-owning-memory.rst
 Tue Dec  5 08:37:49 2017
@@ -111,7 +111,11 @@ The ``gsl::owner`` is declared as a
 In template functions and classes, like in the example below, the information
 of the type aliases gets lost. Therefore using ``gsl::owner`` in a heavy 
templated
 code base might lead to false positives. 
-This limitation results in ``std::vector>`` not being diagnosed 
correctly.
+
+Known code constructs that do not get diagnosed correctly are:
+
+- ``std::exchange``
+- ``std::vector>``
 
 .. code-block:: c++
 


___
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] r316767 - [clang-tidy] Fix bug 34845, offending standard bitmask types

2017-10-27 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Fri Oct 27 07:44:08 2017
New Revision: 316767

URL: http://llvm.org/viewvc/llvm-project?rev=316767=rev
Log:
[clang-tidy] Fix bug 34845, offending standard bitmask types

Summary:
The C++ standard allows implementations to choose the underlying type for
bitmask types (e.g. std::ios_base::openmode). MSVC implemented some of them
as signed integers resulting in warnings for usual code like
`auto dd = std::ios_base::badbit | std::ios_base::failbit;`

These false positives were reported in 
https://bugs.llvm.org/show_bug.cgi?id=34845

The fix allows bitwise |,&,^ for known standard bitmask types under the 
condition
that both operands are such bitmask types.
Shifting and bitwise complement are still forbidden.

Reviewers: aaron.ballman, alexfh, hokein

Reviewed By: aaron.ballman

Subscribers: xazax.hun

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

Added:

clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-standard-types.cpp

clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-standard-types.h
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=316767=316766=316767=diff
==
--- clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp Fri Oct 27 
07:44:08 2017
@@ -20,34 +20,72 @@ namespace hicpp {
 
 void SignedBitwiseCheck::registerMatchers(MatchFinder *Finder) {
   const auto SignedIntegerOperand =
-  
expr(ignoringImpCasts(hasType(isSignedInteger(.bind("signed_operand");
+  
expr(ignoringImpCasts(hasType(isSignedInteger(.bind("signed-operand");
+
+  // The standard [bitmask.types] allows some integral types to be implemented
+  // as signed types. Exclude these types from diagnosing for bitwise or(|) and
+  // bitwise and(&). Shifting and complementing such values is still not
+  // allowed.
+  const auto BitmaskType = namedDecl(anyOf(
+  hasName("::std::locale::category"), hasName("::std::ctype_base::mask"),
+  hasName("::std::ios_base::fmtflags"), 
hasName("::std::ios_base::iostate"),
+  hasName("::std::ios_base::openmode")));
+  const auto IsStdBitmask = 
ignoringImpCasts(declRefExpr(hasType(BitmaskType)));
 
   // Match binary bitwise operations on signed integer arguments.
   Finder->addMatcher(
-  binaryOperator(allOf(anyOf(hasOperatorName("|"), hasOperatorName("&"),
- hasOperatorName("^"), hasOperatorName("<<"),
- hasOperatorName(">>")),
+  binaryOperator(
+  allOf(anyOf(hasOperatorName("^"), hasOperatorName("|"),
+  hasOperatorName("&")),
+
+unless(allOf(hasLHS(IsStdBitmask), hasRHS(IsStdBitmask))),
+
+hasEitherOperand(SignedIntegerOperand),
+hasLHS(hasType(isInteger())), hasRHS(hasType(isInteger()
+  .bind("binary-no-sign-interference"),
+  this);
+
+  // Shifting and complement is not allowed for any signed integer type because
+  // the sign bit may corrupt the result.
+  Finder->addMatcher(
+  binaryOperator(allOf(anyOf(hasOperatorName("<<"), hasOperatorName(">>")),
hasEitherOperand(SignedIntegerOperand),
hasLHS(hasType(isInteger())),
hasRHS(hasType(isInteger()
-  .bind("binary_signed"),
+  .bind("binary-sign-interference"),
   this);
 
   // Match unary operations on signed integer types.
   Finder->addMatcher(unaryOperator(allOf(hasOperatorName("~"),
  
hasUnaryOperand(SignedIntegerOperand)))
- .bind("unary_signed"),
+ .bind("unary-signed"),
  this);
 }
 
 void SignedBitwiseCheck::check(const MatchFinder::MatchResult ) {
   const ast_matchers::BoundNodes  = Result.Nodes;
-  const auto *SignedBinary = N.getNodeAs("binary_signed");
-  const auto *SignedUnary = N.getNodeAs("unary_signed");
-  const auto *SignedOperand = N.getNodeAs("signed_operand");
+  const auto *SignedOperand = N.getNodeAs("signed-operand");
+  assert(SignedOperand &&
+ "No signed operand found in problematic bitwise operations");
+
+  bool IsUnary = false;
+  SourceLocation Location;
+
+  if (const auto *UnaryOp = N.getNodeAs("unary-signed")) {
+IsUnary = true;
+Location = UnaryOp->getLocStart();
+  } else {
+if (const auto *BinaryOp =
+N.getNodeAs("binary-no-sign-interference"))
+  Location = BinaryOp->getLocStart();
+else if (const auto *BinaryOp =
+ N.getNodeAs("binary-sign-interference"))
+  Location = BinaryOp->getLocStart();
+

[clang-tools-extra] r322624 - [clang-tidy] fix minor formatting issue

2018-01-17 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Jan 17 02:23:50 2018
New Revision: 322624

URL: http://llvm.org/viewvc/llvm-project?rev=322624=rev
Log:
[clang-tidy] fix minor formatting issue

Modified:
clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp

Modified: clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp?rev=322624=322623=322624=diff
==
--- clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp Wed Jan 17 
02:23:50 2018
@@ -51,8 +51,7 @@ public:
 "hicpp-deprecated-headers");
 CheckFactories.registerCheck(
 "hicpp-exception-baseclass");
-CheckFactories.registerCheck(
-"hicpp-signed-bitwise");
+CheckFactories.registerCheck("hicpp-signed-bitwise");
 CheckFactories.registerCheck(
 "hicpp-explicit-conversions");
 CheckFactories.registerCheck(


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


[clang-tools-extra] r322626 - [clang-tidy] implement check for goto

2018-01-17 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Jan 17 02:27:41 2018
New Revision: 322626

URL: http://llvm.org/viewvc/llvm-project?rev=322626=rev
Log:
[clang-tidy] implement check for goto

The usage of `goto` is discourage in C++ since forever. This check implements
a warning for every `goto`. Even though there are (rare) valid use cases for
`goto`, better high level constructs should be used.

`goto` is used sometimes in C programs to free resources at the end of 
functions in the case of errors. This pattern is better implemented with
RAII in C++.

Reviewers: aaron.ballman, alexfh, hokein

Reviewed By: aaron.ballman

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

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

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

clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-avoid-goto.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/hicpp-avoid-goto.rst
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-avoid-goto.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt

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

Added: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp?rev=322626=auto
==
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp Wed 
Jan 17 02:27:41 2018
@@ -0,0 +1,55 @@
+//===--- AvoidGotoCheck.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 "AvoidGotoCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace cppcoreguidelines {
+
+AST_MATCHER(GotoStmt, isForwardJumping) {
+  return Node.getLocStart() < Node.getLabel()->getLocStart();
+}
+
+void AvoidGotoCheck::registerMatchers(MatchFinder *Finder) {
+  if (!getLangOpts().CPlusPlus)
+return;
+
+  // TODO: This check does not recognize `IndirectGotoStmt` which is a
+  // GNU extension. These must be matched separately and an AST matcher
+  // is currently missing for them.
+
+  // Check if the 'goto' is used for control flow other than jumping
+  // out of a nested loop.
+  auto Loop = stmt(anyOf(forStmt(), cxxForRangeStmt(), whileStmt(), doStmt()));
+  auto NestedLoop =
+  stmt(anyOf(forStmt(hasAncestor(Loop)), 
cxxForRangeStmt(hasAncestor(Loop)),
+ whileStmt(hasAncestor(Loop)), doStmt(hasAncestor(Loop;
+
+  Finder->addMatcher(gotoStmt(anyOf(unless(hasAncestor(NestedLoop)),
+unless(isForwardJumping(
+ .bind("goto"),
+ this);
+}
+
+void AvoidGotoCheck::check(const MatchFinder::MatchResult ) {
+  const auto *Goto = Result.Nodes.getNodeAs("goto");
+
+  diag(Goto->getGotoLoc(), "avoid using 'goto' for flow control")
+  << Goto->getSourceRange();
+  diag(Goto->getLabel()->getLocStart(), "label defined here",
+   DiagnosticIDs::Note);
+}
+} // namespace cppcoreguidelines
+} // namespace tidy
+} // namespace clang

Added: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/AvoidGotoCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/AvoidGotoCheck.h?rev=322626=auto
==
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/AvoidGotoCheck.h 
(added)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/AvoidGotoCheck.h Wed 
Jan 17 02:27:41 2018
@@ -0,0 +1,36 @@
+//===--- AvoidGotoCheck.h - clang-tidy---*- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_AVOIDGOTOCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_AVOIDGOTOCHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {

[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=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=338392=338393=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=338392=338393=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.
+extern volatile int 

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=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=338021=338022=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].
 
 
 
+Matcherhttp://clang.llvm.org/doxygen/classclang_1_1Type.html;>TypedecltypeTypeMatcherhttp://clang.llvm.org/doxygen/classclang_1_1DecltypeType.html;>DecltypeType...
+Matches types nodes 
representing C++11 decltype(expr) types.
+
+Given:
+  short i = 1;
+  int j = 42;
+  decltype(i + j) result = i + j;
+decltypeType() 
+  matches "decltype(i + j)"
+
+
+
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1Type.html;>TypedependentSizedArrayTypeMatcherhttp://clang.llvm.org/doxygen/classclang_1_1DependentSizedArrayType.html;>DependentSizedArrayType...
 Matches C++ 
arrays whose size is a value-dependent expression.
 
@@ -5156,6 +5168,19 @@ declaration of class D.
 
 
 
+Matcherhttp://clang.llvm.org/doxygen/classclang_1_1DecltypeType.html;>DecltypeTypehasUnderlyingTypeMatcherhttp://clang.llvm.org/doxygen/classclang_1_1Type.html;>Type
+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: Matcherhttp://clang.llvm.org/doxygen/classclang_1_1DecltypeType.html;>DecltypeType
+
+
+
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1DoStmt.html;>DoStmthasBodyMatcherhttp://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>Stmt 
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


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


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=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=338995=338996=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: 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


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=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=340623=340624=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=340623=340624=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


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=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=340622=340623=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=340622=340623=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


[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=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=340927=340928=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=340927=340928=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=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 
) {
+  const auto *InternalDependency =
+  Result.Nodes.getNodeAs("InternalDep");
+
+  diag(InternalDependency->getBeginLoc(),
+   "do not reference any 'internal' namespaces; those implementation "
+   "details are reserved to Abseil");
+}
+
+} // 

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=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=337702=337703=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=337702=337703=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=337702=337703=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=337702=337703=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] 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=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=337711=337712=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 ,
- 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=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=337715=337716=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=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 not use pointer 

[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=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=337706=337707=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=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=337709=337710=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 ,
+ 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


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=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=341283=341284=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=341283=341284=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] 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=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=341038=341039=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


[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=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=341932=341933=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


[clang-tools-extra] r329789 - [clang-tidy] add missing assignment operations in hicpp-signed-bitwise

2018-04-11 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Apr 11 02:53:08 2018
New Revision: 329789

URL: http://llvm.org/viewvc/llvm-project?rev=329789=rev
Log:
[clang-tidy] add missing assignment operations in hicpp-signed-bitwise

This patch resolves the bug https://bugs.llvm.org/show_bug.cgi?id=36963.

- implement missing assignment operators for hicpp-signed-bitwise
- mention fix in release notes

Reviewers:
aaron.ballman, hokein, alexfh

Differential: https://reviews.llvm.org/D45414


Modified:
clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst

clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-standard-types.cpp
clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise.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=329789=329788=329789=diff
==
--- clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp Wed Apr 11 
02:53:08 2018
@@ -36,7 +36,8 @@ void SignedBitwiseCheck::registerMatcher
   Finder->addMatcher(
   binaryOperator(
   allOf(anyOf(hasOperatorName("^"), hasOperatorName("|"),
-  hasOperatorName("&")),
+  hasOperatorName("&"), hasOperatorName("^="),
+  hasOperatorName("|="), hasOperatorName("&=")),
 
 unless(allOf(hasLHS(IsStdBitmask), hasRHS(IsStdBitmask))),
 
@@ -48,10 +49,11 @@ void SignedBitwiseCheck::registerMatcher
   // Shifting and complement is not allowed for any signed integer type because
   // the sign bit may corrupt the result.
   Finder->addMatcher(
-  binaryOperator(allOf(anyOf(hasOperatorName("<<"), hasOperatorName(">>")),
-   hasEitherOperand(SignedIntegerOperand),
-   hasLHS(hasType(isInteger())),
-   hasRHS(hasType(isInteger()
+  binaryOperator(
+  allOf(anyOf(hasOperatorName("<<"), hasOperatorName(">>"),
+  hasOperatorName("<<="), hasOperatorName(">>=")),
+hasEitherOperand(SignedIntegerOperand),
+hasLHS(hasType(isInteger())), hasRHS(hasType(isInteger()
   .bind("binary-sign-interference"),
   this);
 
@@ -84,10 +86,8 @@ void SignedBitwiseCheck::check(const Mat
 else
   llvm_unreachable("unexpected matcher result");
   }
-
-  diag(Location,
-   "use of a signed integer operand with a %select{binary|unary}0 bitwise "
-   "operator")
+  diag(Location, "use of a signed integer operand with a "
+ "%select{binary|unary}0 bitwise operator")
   << IsUnary << SignedOperand->getSourceRange();
 }
 

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=329789=329788=329789=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Wed Apr 11 02:53:08 2018
@@ -156,6 +156,9 @@ Improvements to clang-tidy
   `
   added.
 
+- Adding the missing bitwise assignment operations to 
+  :doc:`hicpp-signed-bitwise `.
+
 - The 'misc-forwarding-reference-overload' check was renamed to 
:doc:`bugprone-forwarding-reference-overload
   `
 

Modified: 
clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-standard-types.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-standard-types.cpp?rev=329789=329788=329789=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-standard-types.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-standard-types.cpp 
Wed Apr 11 02:53:08 2018
@@ -8,13 +8,19 @@ void pure_bitmask_types() {
   std::locale::category C = std::locale::category::ctype;
 
   SResult = std::locale::category::none | std::locale::category::collate;
+  SResult|= std::locale::category::collate;
   SResult = std::locale::category::ctype & std::locale::category::monetary;
+  SResult&= std::locale::category::monetary;
   SResult = std::locale::category::numeric ^ std::locale::category::time;
+  SResult^= std::locale::category::time;
   SResult = std::locale::category::messages | std::locale::category::all;
 
   SResult = std::locale::category::all & C;
+  SResult&= std::locale::category::all;
   SResult = std::locale::category::all | C;
+  SResult|= std::locale::category::all;
   SResult = std::locale::category::all ^ C;
+  SResult^= std::locale::category::all;
 
   // std::ctype_base::mask
   std::ctype_base::mask M = std::ctype_base::mask::punct;

[clang-tools-extra] r329790 - [clang-tidy] fix buildbots from hicpp-signed-bitwise

2018-04-11 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Apr 11 03:22:25 2018
New Revision: 329790

URL: http://llvm.org/viewvc/llvm-project?rev=329790=rev
Log:
[clang-tidy] fix buildbots from hicpp-signed-bitwise

The applied patch to diagnose assignment operators introduced
breakage on some architectures. This patch tries to rectify that.


Modified:

clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-standard-types.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-standard-types.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-standard-types.cpp?rev=329790=329789=329790=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-standard-types.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-standard-types.cpp 
Wed Apr 11 03:22:25 2018
@@ -93,11 +93,16 @@ void still_forbidden() {
   // Staying within the allowed standard types is ok for bitwise assignment
   // operations.
   std::ctype_base::mask var = std::ctype_base::mask::print;
-  var<<= std::ctype_base::mask::upper;
-  var>>= std::ctype_base::mask::upper;
-  var &= std::ctype_base::mask::upper;
-  var |= std::ctype_base::mask::upper;
-  var ^= std::ctype_base::mask::upper;
+  SResult<<= std::ctype_base::mask::upper;
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand 
with a binary bitwise operator
+  SResult>>= std::ctype_base::mask::upper;
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand 
with a binary bitwise operator
+  SResult &= std::ctype_base::mask::upper;
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand 
with a binary bitwise operator
+  SResult |= std::ctype_base::mask::upper;
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand 
with a binary bitwise operator
+  SResult ^= std::ctype_base::mask::upper;
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand 
with a binary bitwise operator
 
   UResult = std::locale::category::collate << 1u;
   UResult = std::locale::category::ctype << 1;


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


[clang-tools-extra] r328107 - [clang-tidy] Resubmit hicpp-multiway-paths-covered without breaking test

2018-03-21 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Mar 21 08:34:15 2018
New Revision: 328107

URL: http://llvm.org/viewvc/llvm-project?rev=328107=rev
Log:
[clang-tidy] Resubmit hicpp-multiway-paths-covered without breaking test

The original check did break the green buildbot in the sanitizer build.
It took a while to redroduce and understand the issue.

There occured a stackoverflow while parsing the AST. The testcase with
256 case labels was the problem because each case label added another
stackframe. It seemed that the issue occured only in 'RelWithDebInfo' builds
and not in normal sanitizer builds.

To simplify the matchers the recognition for the different kinds of switch
statements has been moved into a seperate function and will not be done with
ASTMatchers. This is an attempt to reduce recursion and stacksize as well.

The new check removed this big testcase. Covering all possible values is still
implemented for bitfields and works there. The same logic on integer types
will lead to the issue.

Running it over LLVM gives the following results:


Differential: https://reviews.llvm.org/D40737

Added:
clang-tools-extra/trunk/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
clang-tools-extra/trunk/clang-tidy/hicpp/MultiwayPathsCoveredCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/hicpp-multiway-paths-covered.rst

clang-tools-extra/trunk/test/clang-tidy/hicpp-multiway-paths-covered-else.cpp
clang-tools-extra/trunk/test/clang-tidy/hicpp-multiway-paths-covered.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/hicpp/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.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/hicpp/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/hicpp/CMakeLists.txt?rev=328107=328106=328107=diff
==
--- clang-tools-extra/trunk/clang-tidy/hicpp/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/CMakeLists.txt Wed Mar 21 08:34:15 
2018
@@ -2,6 +2,7 @@ set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyHICPPModule
   ExceptionBaseclassCheck.cpp
+  MultiwayPathsCoveredCheck.cpp
   NoAssemblerCheck.cpp
   HICPPTidyModule.cpp
   SignedBitwiseCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp?rev=328107=328106=328107=diff
==
--- clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/HICPPTidyModule.cpp Wed Mar 21 
08:34:15 2018
@@ -36,6 +36,7 @@
 #include "../readability/FunctionSizeCheck.h"
 #include "../readability/IdentifierNamingCheck.h"
 #include "ExceptionBaseclassCheck.h"
+#include "MultiwayPathsCoveredCheck.h"
 #include "NoAssemblerCheck.h"
 #include "SignedBitwiseCheck.h"
 
@@ -54,6 +55,8 @@ public:
 "hicpp-deprecated-headers");
 CheckFactories.registerCheck(
 "hicpp-exception-baseclass");
+CheckFactories.registerCheck(
+"hicpp-multiway-paths-covered");
 CheckFactories.registerCheck("hicpp-signed-bitwise");
 CheckFactories.registerCheck(
 "hicpp-explicit-conversions");

Added: clang-tools-extra/trunk/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp?rev=328107=auto
==
--- clang-tools-extra/trunk/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp Wed 
Mar 21 08:34:15 2018
@@ -0,0 +1,181 @@
+//===--- MultiwayPathsCoveredCheck.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 "MultiwayPathsCoveredCheck.h"
+#include "clang/AST/ASTContext.h"
+
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace hicpp {
+
+void MultiwayPathsCoveredCheck::storeOptions(
+ClangTidyOptions::OptionMap ) {
+  Options.store(Opts, "WarnOnMissingElse", WarnOnMissingElse);
+}
+
+void MultiwayPathsCoveredCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  switchStmt(
+  hasCondition(allOf(
+  // Match on switch statements that have either a bit-field or
+  // an integer condition. The ordering in 'anyOf()' is
+  // important because the last condition is the 

[clang-tools-extra] r328108 - [Fix] fix type deduction on ARM and MSVC

2018-03-21 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Wed Mar 21 08:50:15 2018
New Revision: 328108

URL: http://llvm.org/viewvc/llvm-project?rev=328108=rev
Log:
[Fix] fix type deduction on ARM and MSVC

Modified:
clang-tools-extra/trunk/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp?rev=328108=328107=328108=diff
==
--- clang-tools-extra/trunk/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp Wed 
Mar 21 08:50:15 2018
@@ -167,7 +167,7 @@ void MultiwayPathsCoveredCheck::handleSw
   return twoPow(BitfieldDecl->getBitWidthValue(*Result.Context));
 }
 
-return 0ul;
+return static_cast(0);
   }();
 
   // FIXME: Transform the 'switch' into an 'if' for CaseCount == 1.


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


[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=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=343197=343198=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 definition with the 

[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=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=343198=343199=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=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=343200=343201=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=343200=343201=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] 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=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=343849=343850=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=343849=343850=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  = *Result.Context;
-  auto Token = utils::lexer::getPreviousToken(Ctxt, LocStart);
+  auto Token = utils::lexer::getPreviousToken(LocStart, 
Ctxt.getSourceManager(),
+  Ctxt.getLangOpts());
   auto  = *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=343849=343850=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=343849=343850=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 , ASTContext ) {
   SourceLocation AmpLocation = Var.getLocation();
-  auto Token = utils::lexer::getPreviousToken(Context, AmpLocation);
+  auto Token = utils::lexer::getPreviousToken(
+  AmpLocation, Context.getSourceManager(), 

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=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=344381=344382=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] 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=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 ) {
  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 ) {
  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=344373=344374=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=344373=344374=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=auto

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=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=344387=344388=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] 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=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=344378=344379=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


[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=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=344383=344384=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


[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=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=31=32=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=31=32=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=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-array-type";
-static const char 

[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=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=30=31=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] 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=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=344939=344940=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=344939=344940=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=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 ,
+const MacroDirective *MD) override {
+if 

[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=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=344946=344947=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=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=345166=345167=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 ) 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=345166=345167=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=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 ) {
+  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 ,
+  SourceRange Range) {
+  return !clang::Lexer::makeFileCharRange(
+  clang::CharSourceRange::getCharRange(Range),
+  *Result.SourceManager, Result.Context->getLangOpts())
+  

[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=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=345734=345735=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=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 ,
+ const LangOptions ) {
+  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 bool isMacroID(SourceRange R) {

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=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=345736=345737=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] 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=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=345735=345736=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


[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=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=345737=345738=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=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=345741=345742=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=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=345994=345995=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=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=346172=346173=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=346172=346173=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=346172=346173=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=346172=346173=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 the programmer.
 
 
-  .. code-block:: c++
+.. 

[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=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=346175=346176=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=346175=346176=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


[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=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=346554=346555=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=346554=346555=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([0]); // OK
 
   for (auto  : 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


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=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=346553=346554=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.
 
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Expr.html;>ExprignoringParensMatcherhttps://clang.llvm.org/doxygen/classclang_1_1Expr.html;>Expr 
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.
+
+
+
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html;>FieldDeclhasInClassInitializerMatcherhttps://clang.llvm.org/doxygen/classclang_1_1Expr.html;>Expr 
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=346553=346554=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=346553=346554=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=346553=346554=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] 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=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=346664=346665=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=346664=346665=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=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::StringLiteral LoopVarCastName =
+

[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=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=346675=346676=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=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=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=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


[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=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=343790=343791=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=343790=343791=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 ) : 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 &) : 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 &) : 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] 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=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=343787=343788=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=343787=343788=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}, \
 // RUN: {key: 

[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=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=343796=343797=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 ('gmock_Method2') is 

[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=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=343788=343789=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] 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=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=343791=343792=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-NOTES: 

[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=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=343795=343796=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] 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=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=343672=343673=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 ) 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] 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=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=343847=343848=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=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 ) {
+  SourceManager  = *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") << TypeName;
+}
+
+} // namespace 

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=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=343847=343848=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=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 {
>>> +name

[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=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=344043=344044=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 ) {
 }
 
 SymbolSlab::const_iterator SymbolSlab::find(const SymbolID ) const {
-  auto It = llvm::lower_bound(
-  Symbols, ID, [](const Symbol , const SymbolID ) { return S.ID < I; 
});
+  auto It = std::lower_bound(
+  Symbols.begin(), Symbols.end(), ID,
+  [](const Symbol , const SymbolID ) { 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=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=344045=344046=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] 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=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=343563=343564=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=343563=343564=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 = _int1; // BAD
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: expected initialization with 
value of type 'gsl::owner<>'; got 'int *'
+  // 

[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=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=343564=343565=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] 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=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=342999=343000=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=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 ,
+SourceLocation Loc1, SourceLocation Loc2) {
+  return Loc1.isFileID() && Loc2.isFileID() &&
+ Sources.getFileID(Loc1) == Sources.getFileID(Loc2);
+}
+
+static bool anonymousOrInlineNamespace(const NamespaceDecl ) {
+  return ND.isAnonymousNamespace() || ND.isInlineNamespace();
+}
+
+static bool singleNamedNamespaceChild(const NamespaceDecl ) {
+  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 ,
+const SourceManager ,
+const LangOptions ) {
+  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(),
+[](const NamespaceDecl *ND) {
+  

[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=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=343000=343001=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,8 @@ void 

[clang-tools-extra] r350466 - [Documentation] fix order of checks in checks/list.rst

2019-01-05 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Sat Jan  5 03:40:05 2019
New Revision: 350466

URL: http://llvm.org/viewvc/llvm-project?rev=350466=rev
Log:
[Documentation] fix order of checks in checks/list.rst

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=350466=350465=350466=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst Sat Jan  5 03:40:05 
2019
@@ -13,8 +13,8 @@ Clang-Tidy Checks
abseil-no-internal-dependencies
abseil-no-namespace
abseil-redundant-strcat-calls
-   abseil-string-find-startswith
abseil-str-cat-append
+   abseil-string-find-startswith
abseil-upgrade-duration-conversions
android-cloexec-accept
android-cloexec-accept4
@@ -91,8 +91,8 @@ Clang-Tidy Checks
cert-msc50-cpp
cert-msc51-cpp
cert-oop11-cpp (redirects to performance-move-constructor-init) 

-   cppcoreguidelines-avoid-goto
cppcoreguidelines-avoid-c-arrays (redirects to modernize-avoid-c-arrays) 

+   cppcoreguidelines-avoid-goto
cppcoreguidelines-avoid-magic-numbers (redirects to 
readability-magic-numbers) 
cppcoreguidelines-c-copy-assignment-signature (redirects to 
misc-unconventional-assign-operator) 

cppcoreguidelines-interfaces-global-init
@@ -159,6 +159,7 @@ Clang-Tidy Checks
hicpp-special-member-functions (redirects to 
cppcoreguidelines-special-member-functions) 
hicpp-static-assert (redirects to misc-static-assert) 
hicpp-undelegated-constructor (redirects to 
bugprone-undelegated-constructor) 
+   hicpp-uppercase-literal-suffix (redirects to 
readability-uppercase-literal-suffix) 
hicpp-use-auto (redirects to modernize-use-auto) 
hicpp-use-emplace (redirects to modernize-use-emplace) 
hicpp-use-equals-default (redirects to modernize-use-equals-default) 

@@ -167,7 +168,6 @@ Clang-Tidy Checks
hicpp-use-nullptr (redirects to modernize-use-nullptr) 
hicpp-use-override (redirects to modernize-use-override) 

hicpp-vararg (redirects to cppcoreguidelines-pro-type-vararg) 
-   hicpp-uppercase-literal-suffix (redirects to 
readability-uppercase-literal-suffix) 
llvm-header-guard
llvm-include-order
llvm-namespace-comment


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


[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=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=351568=351569=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=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=351742=351743=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] 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=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=348792=348793=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=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=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 *=(int64_t r);
+  Duration *=(float r);
+  Duration *=(double r);
+  template  Duration *=(T r);
+
+  Duration /=(int64_t r);
+  Duration /=(float r);
+  Duration /=(double r);
+  template  Duration /=(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=348839=348840=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\
-  Duration NAME(T n);
-
-GENERATE_DURATION_FACTORY_OVERLOADS(Nanoseconds);

[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=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=348841=348842=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] 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=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=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 ) {
+  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 ) {
+  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 ) {
+  const ASTContext  = *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)) {
+   

[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=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=348340=348341=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=348340=348341=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)( - 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] 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=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=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 ) {
-  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 ) {
-  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 ) {
-  const ASTContext  = *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] 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=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=348164=348165=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 ) 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=348164=348165=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=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},
-   {"ToInt64Nanoseconds", 

  1   2   >