Commit Graph

315 Commits

Author SHA1 Message Date
Daniel Marjamaki e0384e51b0 [clang-tidy] Enhance clang-tidy misc-macro-repeated-side-effects...
Enhance clang-tidy misc-macro-repeated-side-effects to handle ? and : better.

When ? is used in a macro, there are 2 possible control flow paths through the macro.
These paths are tracked separately so problems can be detected properly.

http://reviews.llvm.org/D10653

llvm-svn: 241245
2015-07-02 07:49:55 +00:00
Daniel Marjamaki bf5e59c78b [clang-tidy] minor coding style tweak. make functions static.
llvm-svn: 241160
2015-07-01 13:29:27 +00:00
Alexander Kornienko 6ae400d122 [clang-tidy] Enhance clang-tidy readability-simplify-boolean-expr...
Enhance clang-tidy readability-simplify-boolean-expr to handle 'if (e) return
true; return false;' and improve replacement expressions.

This changeset extends the simplify boolean expression check in clang-tidy to
simplify if (e) return true; return false; to return e; (note the lack of an
else clause on the if statement.) By default, chained conditional assignment is
left unchanged, unless a configuration parameter is set to non-zero to override
this behavior.

It also improves the handling of replacement expressions to apply
static_cast<bool>(expr) when expr is not of type bool.

http://reviews.llvm.org/D9810

Patch by Richard Thomson!

llvm-svn: 241155
2015-07-01 12:39:40 +00:00
Daniel Marjamaki 4a38b0b493 [clang-tidy] Fix false positives in the macro parentheses checker
Summary:
There were false positives in C++ code where macro argument was a type.

Reviewers: alexfh

Differential Revision: http://reviews.llvm.org/D10801

llvm-svn: 240938
2015-06-29 12:18:11 +00:00
Daniel Marjamaki 91d35a5e22 [clang-tidy] Fix false positives in misc-macro-parentheses checker
llvm-svn: 240399
2015-06-23 12:45:14 +00:00
Justin Bogner 7b92cac037 clang-tidy: Remove an unused private field. NFC
Clang was warning on this.

llvm-svn: 239988
2015-06-18 04:15:04 +00:00
Daniel Marjamaki 71c9257f07 clang-tidy: Add checker that warn when macro argument with side effects is repeated in the macro
llvm-svn: 239909
2015-06-17 14:19:35 +00:00
Alexander Kornienko 50d7f4617f [clang-tidy] Move user-defined matches to unnamed namespaces to prevent ODR violations.
llvm-svn: 239904
2015-06-17 13:11:37 +00:00
Daniel Marjamaki 302275a938 clang-tidy: Add checker that warns about missing parentheses in macros
* calculations in the replacement list should be inside parentheses
* macro arguments should be inside parentheses

llvm-svn: 239820
2015-06-16 14:27:31 +00:00
Samuel Benzaquen cfacf8ae9e [clang-tidy] Force braces around leaf 'else if' for consistency.
Summary:
Force braces around leaf 'else if' for consistency.
This complements r233697.

Reviewers: alexfh

Subscribers: curdeius, cfe-commits

Differential Revision: http://reviews.llvm.org/D10245

llvm-svn: 239054
2015-06-04 16:36:58 +00:00
Szabolcs Sipos 43a298cb36 [clang-tidy] Fix for llvm.org/PR23355
misc-static-assert and misc-assert-side-effect will handle __builtin_expect based asserts correctly.

llvm-svn: 238548
2015-05-29 09:49:59 +00:00
Alexander Kornienko 7ed89bcd3b [clang-tidy] Renamed misc-noexcept-move-ctors to misc-noexcept-move-constructor
llvm-svn: 238326
2015-05-27 14:24:11 +00:00
Alexander Kornienko bf5bd94142 [clang-tidy] misc-noexcept-move-ctors should ignore implicit constructors and assignments.
llvm-svn: 238202
2015-05-26 14:35:09 +00:00
Alexander Kornienko 2b56649cd2 [clang-tidy] Don't issue most google-readability-casting warnings on .c files included in other files.
This is done sometimes for testing purposes, and the check needs to handle this
consistently.

llvm-svn: 238193
2015-05-26 10:47:48 +00:00
Szabolcs Sipos 0acf19ed53 [clang-tidy] Fix for llvm.org/PR23572
misc-static-assert won't report asserts whose conditions contain calls to non constexpr functions.

llvm-svn: 238098
2015-05-23 14:21:01 +00:00
Alexander Kornienko 3396a8b8e6 Add a clang-tidy check for move constructors/assignment ops without noexcept.
Summary:
Add a clang-tidy check (misc-noexcept-move-ctors) for move constructors
and assignment operators not using noexcept.

http://llvm.org/PR23519

Reviewers: klimek

Reviewed By: klimek

Subscribers: curdeius, cfe-commits

Differential Revision: http://reviews.llvm.org/D9933

llvm-svn: 238013
2015-05-22 10:31:17 +00:00
Alexander Kornienko 19bbeaf410 [clang-tidy] Disable google-readability-casting for .c files and their headers.
Some people have reasons to compile their .c files as C++ in some configurations
(e.g. for testing purposes), so just looking at LangOptions is not enough. This
patch disables the check on all .c files (and also for the headers included from
.c files).

llvm-svn: 237905
2015-05-21 14:08:56 +00:00
Alexander Kornienko fb3e2cd8cc [clang-tidy] Enhance clang-tidy readability-simplify-boolean-expr check...
Enhance clang-tidy readability-simplify-boolean-expr check to handle chained
conditional assignment and chained conditional return.

Based on feedback from applying this tool to the clang/LLVM codebase, this
changeset improves the readability-simplify-boolean-expr check so that
conditional assignment or return statements at the end of a chain of if/else if
statements are left unchanged unless a configuration option is supplied.

http://reviews.llvm.org/D8996

Patch by Richard Thomson!

llvm-svn: 237541
2015-05-17 12:31:12 +00:00
Alexander Kornienko bdaa681fc6 [clang-tidy] Treat all types with non-trivial destructors as RAII.
This solves some false negatives at a cost of adding some false positives that
can be fixed easily and (almost) automatically.

llvm-svn: 237120
2015-05-12 12:17:20 +00:00
Szabolcs Sipos 60ce8bb0be [clang-tidy] Fix for llvm.org/PR23161
The misc-static-assert check will not warn on the followings:
    assert(NULL == "shouldn't warn");
    assert(__null == "shouldn't warn");

Where NULL is a macro defined as __null.

llvm-svn: 236812
2015-05-08 07:56:24 +00:00
Richard Smith 33de8566f0 Update to match clang r236404.
llvm-svn: 236405
2015-05-04 03:15:55 +00:00
Daniel Jasper a73aed0c9b clang-tidy: [readability-else-after-return] Fix false positive. This
might be a little too strict now, but better be too strict than do the
wrong thing.

llvm-svn: 235932
2015-04-27 22:42:20 +00:00
Benjamin Kramer 73d2749a18 [clang-tidy] Remove static StringSet in favor of binary search.
The number of strings is so small that performance doesn't matter and adding
the thread safe static initialization and destruction overhead is just not
worth it. No functional change intended.

llvm-svn: 235192
2015-04-17 13:52:08 +00:00
Alexander Kornienko f5e72b0448 [clang-tidy] Add readability-simplify-boolean-expr check to clang-tidy
This check looks for comparisons between boolean expressions and boolean
constants and simplifies them to just use the appropriate boolean expression
directly.

if (b == true) becomes if (b)
if (b == false) becomes if (!b)
if (b && true) becomes if (b)
if (b && false) becomes if (false)
if (b || true) becomes if (true)
if (b || false) becomes if (b)
e ? true : false becomes e
e ? false : true becomes !e
if (true) t(); else f(); becomes t();
if (false) t(); else f(); becomes f();
if (e) return true; else return false; becomes return (e);
if (e) return false; else return true; becomes return !(e);
if (e) b = true; else b = false; becomes b = e;
if (e) b = false; else b = true; becomes b = !(e);

http://reviews.llvm.org/D7648

Patch by Richard Thomson!

llvm-svn: 234626
2015-04-10 19:26:43 +00:00
Szabolcs Sipos 8429681d57 [clang-tidy] Fix for llvm.org/PR23161
The misc-static-assert check will not warn on the followings:
  assert("Some message" == NULL);
  assert(NULL == "Some message");

llvm-svn: 234596
2015-04-10 13:55:39 +00:00
Samuel Benzaquen 91d85dc6bc [clang-tidy] Ignore expressions with incompatible deleters.
Summary:
Do not warn on .reset(.release()) expressions if the deleters are not
compatible.
Using plain assignment will probably not work.

Reviewers: klimek

Subscribers: curdeius, cfe-commits

Differential Revision: http://reviews.llvm.org/D8422

llvm-svn: 234512
2015-04-09 17:51:01 +00:00
Alexander Kornienko 66d7e30b3c [clang-tidy] Fix for http://llvm.org/PR23130
NamespaceCommentCheck: Don't remove the token placed immediately after the
namespace closing brace.

llvm-svn: 234403
2015-04-08 12:54:57 +00:00
Alexander Kornienko 0b024619df [clang-tidy] Clarify message for the google-explicit-constructor check
Use "constructors that are callable with a single argument" instead of
"single-argument constructors" when referring to constructors using default
arguments or parameter packs.

llvm-svn: 233702
2015-03-31 16:24:44 +00:00
Samuel Benzaquen 462501ee7e Force braces on the else branch if they are being added to the if branch.
Summary:
Force braces on the else branch if they are being added to the if branch.
This ensures consistency in the transformed code.

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D8708

llvm-svn: 233697
2015-03-31 13:53:03 +00:00
Samuel Benzaquen 3199b9a8b5 Fix false positive on anonymous namespaces in headers.
Summary:
Anynoumous namespaces inject a using directive into the AST to import
the names into the containing namespace.
We should not have them in headers, but there is another warning for
that.

Reviewers: djasper

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D8443

llvm-svn: 233087
2015-03-24 15:21:45 +00:00
Eli Bendersky 735e87ea75 Fix clang-tidy to not assume wrong source locations for defaulted members.
Followup to http://reviews.llvm.org/D8465, which would break a test in
clang-tidy. clang-tidy previously assumes that source locations of
defaulted/deleted members are (incorrectly) not including the '= ...' part.

Differential Revision: http://reviews.llvm.org/D8466

llvm-svn: 233032
2015-03-23 22:14:08 +00:00
Benjamin Kramer e71037123b Make helpers static. clang-tools edition.
Also purge dead code found by it. NFC.

llvm-svn: 232948
2015-03-23 12:49:15 +00:00
Alexander Kornienko c5bc68e7ab [clang-tidy] Move google-readability-function check to readability-named-parameter.
Summary: The relevant style rule is going to be removed, thus the check is no longer needed in the Google module. Leaving the check in readability/ in case someone needs it.

Reviewers: djasper

Reviewed By: djasper

Subscribers: curdeius, cfe-commits

Differential Revision: http://reviews.llvm.org/D8261

llvm-svn: 232431
2015-03-16 22:31:16 +00:00
Alexander Kornienko 57a5c6b56c Move remove-cstr-calls from a standalone executable to a clang-tidy check readability-redundant-string-cstr
http://reviews.llvm.org/D7318

Patch by Richard Thomson!

llvm-svn: 232338
2015-03-16 00:32:25 +00:00
Alexander Kornienko 1c4af5edf4 [clang-tidy] Fix false positives in the misc-static-assert check http://llvm.org/PR22880
The misc-static-assert check will not warn on assert(false), assert(False),
assert(FALSE); where false / False / FALSE are macros expanding to the false or
0 literals.

Also added corresponding test cases.

http://reviews.llvm.org/D8328

Patch by Szabolcs Sipos!

llvm-svn: 232306
2015-03-15 02:19:37 +00:00
NAKAMURA Takumi 0c1e8452cc Add clangBasic to libdeps according to r232051 since the interface of ASTMatchers was changed.
llvm-svn: 232138
2015-03-13 03:47:43 +00:00
Alexander Kornienko 8d6c3571b4 [clang-tidy] Remove an empty destructor.
llvm-svn: 232031
2015-03-12 12:30:10 +00:00
Gabor Horvath 343832181b [clang-tidy] Static Analyzer checker configuration options pass-through.
Reviewed by: Alexander Kornienko

Differential Revision: http://reviews.llvm.org/D8164

llvm-svn: 231941
2015-03-11 17:25:22 +00:00
Alexander Kornienko 4fa0305b72 [clang-tidy] Clean up misc-use-override warning. NFC
llvm-svn: 231938
2015-03-11 16:47:27 +00:00
Alexander Kornienko 6658055488 [clang-tidy] Fixed header guards using clang-tidy llvm-header-guard check. NFC.
The patch was generated using this command:
$ clang-tidy/tool/run-clang-tidy.py -header-filter=.*clang-tidy.* -fix \
    -checks=-*,llvm-header-guard clang-tidy.*
$ svn revert --recursive clangt-tidy/llvm/
(to revert a few buggy fixes)

llvm-svn: 231669
2015-03-09 16:52:33 +00:00
Alexander Kornienko 1b677dbd44 [clang-tidy] Refactor: Rename clang-tidy readability check files and classes to follow naming conventions
Classes are named WhateverCheck, files are WhateverCheck.cpp and`
WhateverCheck.h`

http://reviews.llvm.org/D8144

Patch by Richard Thomson!

llvm-svn: 231650
2015-03-09 12:18:39 +00:00
Alexander Kornienko 5b982e539d [clang-tidy] Refactor: Rename clang-tidy misc check files and classes to follow naming conventions
Classes are named WhateverCheck, files are named WhateverCheck.cpp and
WhateverCheck.h.

http://reviews.llvm.org/D8145

Patch by Richard Thomson!

llvm-svn: 231648
2015-03-09 11:48:54 +00:00
Alexander Kornienko b2ddb8ac4d [clang-tidy] Fix assertion when a dependent expression is used in an assert.
llvm-svn: 231620
2015-03-09 02:27:57 +00:00
Daniel Jasper 08201e394e Use std::string instead of StringRef to prevent use-after-free.
Discovered by asan.

llvm-svn: 231421
2015-03-05 23:17:32 +00:00
Alexander Kornienko da4ebb219b [clang-tidy] Replace unrecognized namespace ending comments.
Summary:
Replace unrecognized namespace ending comments. This will help in particular when a namespace ending comment is mistyped or doesn't fit the regexp for other reason, e.g.:

  namespace a {
  namespace b {
  namespace {
  } // anoynmous namespace
  } // b
  } // namesapce a

Reviewers: djasper

Reviewed By: djasper

Subscribers: curdeius, cfe-commits

Differential Revision: http://reviews.llvm.org/D8078

llvm-svn: 231369
2015-03-05 14:56:11 +00:00
Alexander Kornienko ed07a255da [clang-tidy] Fix diag message in clang-tidy misc-uniqueptr-reset-release if right side is rvalue
http://reviews.llvm.org/D8071

Patch by Alexey Sokolov!

llvm-svn: 231365
2015-03-05 13:53:21 +00:00
Alexander Kornienko ed824e0e4b [clang-tidy] Refactor: Move google clang-tidy checks to namespace clang::tidy::google
http://reviews.llvm.org/D7994

Patch by Richard Thomson!

llvm-svn: 231364
2015-03-05 13:46:14 +00:00
Alexander Kornienko df0ab6acdf [clang-tidy] Fix namespace comments. NFC.
llvm-svn: 231267
2015-03-04 18:01:10 +00:00
Alexander Kornienko 0a6ce9f4e1 [clang-tidy] Refactor: Move llvm clang-tidy checks to namespace clang::tidy::llvm
clang-tidy checks are organized into modules. This refactoring moves the llvm
module checks to clang::tidy::llvm

http://reviews.llvm.org/D7995

Patch by Richard Thomson!

llvm-svn: 230952
2015-03-02 12:39:18 +00:00
Alexander Kornienko 2b312420aa [clang-tidy] Refactor: Move misc clang-tidy checks to namespace clang::tidy::misc
clang-tidy checks are organized into modules. This refactoring moves the misc
module checks into the namespace clang::tidy::misc

http://reviews.llvm.org/D7996

Patch by Richard Thomson!

llvm-svn: 230950
2015-03-02 12:25:03 +00:00