Commit Graph

548 Commits

Author SHA1 Message Date
Alexander Kornienko 3f36fbbeb5 [clang-tidy] Slightly clarified comments.
llvm-svn: 257600
2016-01-13 14:16:43 +00:00
Alexander Kornienko 98ba0813e6 Support virtual-near-miss check.
Summary: Virtual function override near miss detection. Function complete. Test complete. Do not conduct Fix for now.

Reviewers: alexfh

Subscribers: cfe-commits

Patch by Cong Liu!

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

llvm-svn: 257599
2016-01-13 14:16:35 +00:00
Aaron Ballman f5f9bf415c Add documentation redirects for clang-tidy checkers that are exposed under multiple checker names. Updates the Python script for adding checks to properly handle these aliases.
llvm-svn: 257347
2016-01-11 16:48:26 +00:00
Alexander Kornienko dcbe5a9d17 [clang-tidy] Fix a false positive in google-runtime-memset
google-runtime-memset no longer issues a warning if the fill char value
is known to be an invalid fill char count.

Namely, it no longer warns for these:

  memset(p, 0, 0);
  memset(p, -1, 0);

In both cases, swapping the last two args would either be useless (there is
no actual bug) or wrong (it would introduce a bug).

Patch by Matt Armstrong!

llvm-svn: 257320
2016-01-11 10:26:29 +00:00
Alexander Kornienko b816ba0fb3 [clang-tidy] Add non-inline function definition and variable definition check in header files.
Summary: The new check will find all functionand variable definitions which may violate cpp one definition rule in header file.

Reviewers: aaron.ballman, alexfh

Subscribers: aaron.ballman, cfe-commits

Patch by Haojian Wu!

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

llvm-svn: 257178
2016-01-08 16:37:11 +00:00
Aaron Ballman c00ad6c5fb Disable part of the misc-move-constructor-init checker when the check is enabled through cert-oop11-cpp. The CERT guideline does not cover moveable parameters as part of the OOP11-CPP recommendation, just copy construction from move constructors.
llvm-svn: 257177
2016-01-08 15:50:51 +00:00
Alexander Kornienko b1b2f87e37 [clang-tidy] Use proper capitalization and punctuation for diagnostic messages.
Use diagnostic parameters where possible instead of string concatenation.

llvm-svn: 257176
2016-01-08 15:21:40 +00:00
Aaron Ballman 1284f04aed Rename the CERT namespace to cert, and update some checkers to use this namespace consistently.
Patch thanks to Haojian Wu!

llvm-svn: 256756
2016-01-04 14:31:14 +00:00
Alexander Kornienko 1589071288 [clang-tidy] Don't use delegating constructors
llvm-svn: 256637
2015-12-30 11:39:30 +00:00
Alexander Kornienko 8d228dda41 [clang-tidy] Use hasLocalStorage() to identify unnecessary copy initializations to exclude static local variables.
Summary: Since local static variables can outlive other local variables exclude them from the unnecessary copy initialization check.

Reviewers: alexfh

Patch by Felix Berger!

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

llvm-svn: 256636
2015-12-30 11:35:50 +00:00
Alexander Kornienko 72a96c66b2 [clang-tidy] Add the missing Makefile
llvm-svn: 256634
2015-12-30 10:56:00 +00:00
Alexander Kornienko 34c2ab8388 [clang-tidy] Fix configure build
llvm-svn: 256633
2015-12-30 10:44:08 +00:00
Alexander Kornienko b959f4c338 [clang-tidy] Add UnnecessaryCopyInitialization check to new "performance" module in ClangTidy
Summary:
The patch adds a new ClangTidy check that detects when expensive-to-copy types are unnecessarily copy initialized from a const reference that has the same or are larger scope than the copy.

It currently only detects this when the copied variable is const qualified. But this will be extended to non const variables if they are only used in a const fashion.

Reviewers: alexfh

Subscribers: cfe-commits

Patch by Felix Berger!

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

llvm-svn: 256632
2015-12-30 10:24:40 +00:00
Alexander Kornienko 254825a356 [clang-tidy] Fix a use-after-free bug found by asan
llvm-svn: 256562
2015-12-29 16:14:38 +00:00
Alexander Kornienko 5de730ef47 [clang-tidy] Don't generate duplicated blank line in add_new_check.py script.
Reviewers: alexfh

Subscribers: cfe-commits

Patch by Haojian Wu!

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

llvm-svn: 256554
2015-12-29 11:05:35 +00:00
Gabor Horvath 1f30cf6b40 [clang-tidy] Fix a false positive case in ContainerSizeEmpty check.
llvm-svn: 256504
2015-12-28 17:20:33 +00:00
Alexander Kornienko 4f74ec0dd8 [clang-tidy] Preserve comments and preprocessor directives when simplifying boolean expressions
This changeset still emits the diagnostic that the expression could be simplified, but it doesn't generate any fix-its that would lose comments or preprocessor directives within the text that would be replaced.

Fixes PR25842

Reviewers: alexfh

Subscribers: xazax.hun, cfe-commits

Patch by Richard Thomson! (+a naming style fix)

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

llvm-svn: 256492
2015-12-28 13:21:22 +00:00
Aaron Ballman a6ab2efed2 Renaming CERT documentation files to use the CERT rule identifiers. This is for consistency with other checkers, where the documentation file name matches the checker name. NFC of the checkers.
llvm-svn: 256474
2015-12-27 19:14:55 +00:00
Alexander Kornienko 785e5223d3 [clang-tidy] Updates to documentation: formatting, titles, etc.
llvm-svn: 256259
2015-12-22 17:36:49 +00:00
Gabor Horvath c6ff9c349d Fix a false positive case in ContainerSizeEmpty check (PR25893).
llvm-svn: 256142
2015-12-21 09:43:52 +00:00
Alexander Kornienko 2a538309ac [clang-tidy] google-readability-namespace-comments: ignore stray semicolons
llvm-svn: 255772
2015-12-16 15:44:42 +00:00
Alexander Kornienko 821ca470bb [clang-tidy] Add namespace support to add_new_check.py
Summary: Without namespace you can not create checks with same name in different modules

Reviewers: alexfh

Subscribers: cfe-commits

Patch by Cong Liu!

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

llvm-svn: 255770
2015-12-16 15:05:27 +00:00
Alexander Kornienko d819364e81 [clang-tidy] Don't use diag() for debug output
llvm-svn: 255765
2015-12-16 13:19:08 +00:00
Alexander Kornienko 32032f5e64 [clang-tidy] Fix a crash in misc-new-delete-overloads
llvm-svn: 255758
2015-12-16 10:58:14 +00:00
Gabor Horvath 454564a2d9 [clang-tidy] Check for suspicious string assignments.
It is possible to assign arbitrary integer types to strings.
Sometimes it is the result of missing to_string call or apostrophes.

Reviewers: alexfh

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

llvm-svn: 255630
2015-12-15 08:47:20 +00:00
Matthias Gehre 37f10a0c25 [clang-tidy] add check cppcoreguidelines-pro-bounds-constant-array-index
Summary:
This is http://reviews.llvm.org/D13746 but instead of including <array>,
a stub is provided.
This check flags all array subscriptions on static arrays and
std::arrays that either have a non-compile-time-constant index or are
out of bounds.

Dynamic accesses into arrays are difficult for both tools and humans to
validate as safe. array_view is a bounds-checked, safe type for
accessing arrays of data. at() is another alternative that ensures
single accesses are bounds-checked. If iterators are needed to access an
array, use the iterators from an array_view constructed over the array.

This rule is part of the "Bounds safety" profile of the C++ Core
Guidelines, see
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-bounds2-only-index-into-arrays-using-constant-expressions

Reviewers: alexfh, sbenza, bkramer, aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 255470
2015-12-13 22:08:26 +00:00
Gabor Horvath a4e35ecce5 [clang-tidy] Fix PR25812.
llvm-svn: 255431
2015-12-12 11:31:25 +00:00
Aaron Ballman ce6c534beb Add a license clarification for use of links and titles of CERT secure coding guidelines.
llvm-svn: 255248
2015-12-10 13:53:36 +00:00
Alexander Kornienko a396143a28 [clang-tidy] Sort includes case-sensitively.
The motivation is:
  1. consistency with clang-format, vim :sort etc.
  2. we don't want the tools to depend on the current locale to do the include
     sorting

llvm-svn: 255243
2015-12-10 12:24:19 +00:00
Mike Aizatsky 5b55df4096 clang-tidy readability identifiers: better diagnostic location
Summary:
With this change the error reported is on the identifier location
itself. It was declaration location before.

Reviewers: alexfh

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

llvm-svn: 254766
2015-12-04 20:57:03 +00:00
Aaron Ballman c5a6da0ed1 Replace the custom AST matcher for nothrow functions with the canonical AST matcher from r254516.
llvm-svn: 254517
2015-12-02 15:24:47 +00:00
Aaron Ballman 43aef4cb9b Add a new checker, cert-err58-cpp, that checks for static or thread_local objects that use a throwing constructor.
This check corresponds to the CERT secure coding rule: https://www.securecoding.cert.org/confluence/display/cplusplus/ERR58-CPP.+Constructors+of+objects+with+static+or+thread+storage+duration+must+not+throw+exceptions

llvm-svn: 254415
2015-12-01 14:05:39 +00:00
Alexander Kornienko 5eb134cc20 [clang-tidy] google-explicit-constructor: improve the warning message
Also switch some more tests to %check_clang_tidy.

llvm-svn: 254216
2015-11-28 02:25:02 +00:00
Matthias Gehre 4241cedb68 [clang-tidy] cppcoreguidelines-pro-bounds-pointer-arithmetic: ignore generated pointer arithmetic
Summary:
Inside a range-based for-loop over an array, the compiler
generates pointer arithmetic (end = array + size). Don't flag this.

Reviewers: alexfh, sbenza, bkramer, aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 254182
2015-11-26 22:32:11 +00:00
Eugene Zelenko f59fb9c7ef Fix problem with Clang-tidy parallel configure build.
Differential revision: http://reviews.llvm.org/D14964

llvm-svn: 254081
2015-11-25 19:16:34 +00:00
Alexander Kornienko 7bca3db8b9 [clang-tidy] Fix a typo in my latest commit.
llvm-svn: 254074
2015-11-25 16:38:22 +00:00
Alexander Kornienko e4ac60d7bc [clang-tidy] Const std::move() argument ClangTidy check
ClangTidy check for finding cases when std::move() is called with const or
trivially copyable arguments, that doesn't lead to any move or argument but it
makes copy. FixIt generates patch for removing call of std::move().

Patch by Vadym Doroshenko! (+ a couple of minor fixes)

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

llvm-svn: 254070
2015-11-25 15:56:11 +00:00
Daniel Marjamaki 8ade8d2efd [clang-tidy] code cleanup using isAssignmentOp()
llvm-svn: 254066
2015-11-25 11:30:00 +00:00
Aaron Ballman f71c9661df Test to ensure the function does not have an unresolved or unevaluated exception specification before testing whether the function throws or not. Fixes PR25574.
llvm-svn: 253598
2015-11-19 20:45:35 +00:00
Craig Topper 506dad8e55 Replace a dyn_cast with isa where the result was only being used as a boolean. NFC.
llvm-svn: 253442
2015-11-18 07:08:11 +00:00
NAKAMURA Takumi 67361cc2e1 Revert r253401, "[clang-tidy] add check cppcoreguidelines-pro-bounds-constant-array-index"
cppcoreguidelines-pro-bounds-constant-array-index.cpp is failing in several hosts.

llvm-svn: 253428
2015-11-18 02:14:35 +00:00
Matthias Gehre 55020566ed [clang-tidy] add check cppcoreguidelines-pro-bounds-constant-array-index
Summary:
This check flags all array subscriptions on static arrays and
std::arrays that either have a non-compile-time-constant index or are
out of bounds.

Dynamic accesses into arrays are difficult for both tools and humans to
validate as safe. array_view is a bounds-checked, safe type for
accessing arrays of data. at() is another alternative that ensures
single accesses are bounds-checked. If iterators are needed to access an
array, use the iterators from an array_view constructed over the array.

This rule is part of the "Bounds safety" profile of the C++ Core
Guidelines, see
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-bounds2-only-index-into-arrays-using-constant-expressions

Reviewers: alexfh, sbenza, bkramer, aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 253401
2015-11-17 23:43:20 +00:00
Matthias Gehre 4722f1921a Fix bug 25362 "cppcoreguidelines-pro-bounds-array-to-pointer-decay does not consider const"
Summary:
The current matcher is
  implicitCastExpr(unless(hasParent(explicitCastExpr())))
but the AST in the bug is
  `-CXXStaticCastExpr 0x2bb64f8 <col:21, col:55> 'void *const *'
static_cast<void *const *> <NoOp>
    `-ImplicitCastExpr 0x2bb64e0 <col:47> 'void *const *' <NoOp>
      `-ImplicitCastExpr 0x2bb64c8 <col:47> 'void **'
<ArrayToPointerDecay>
        `-DeclRefExpr 0x2bb6458 <col:47> 'void *[2]' lvalue Var
0x2bb59d0 'addrlist' 'void *[2]'
i.e. an ImplicitCastExpr (const cast) between decay and explicit cast.

Reviewers: alexfh, sbenza, bkramer, aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 253399
2015-11-17 23:35:39 +00:00
Aaron Ballman 5a786ddf4c Add a new clang-tidy checker that flags throw expressions whose thrown type is not nothrow copy constructible. While the compiler is free to elide copy constructor calls in some cases, it is under no obligation to do so, which makes the code a portability concern as well as a security concern.
This checker corresponds to the CERT secure coding rule: https://www.securecoding.cert.org/confluence/display/cplusplus/ERR60-CPP.+Exception+objects+must+be+nothrow+copy+constructible

llvm-svn: 253246
2015-11-16 19:17:43 +00:00
Alexander Kornienko 58fe57a92b [clang-tidy] Test commit (playing with git-svn)
llvm-svn: 253203
2015-11-16 13:06:15 +00:00
Alexander Kornienko 11297349ea [clang-tidy] Remove unused #includes.
Summary: Testing Phab with git-svn

Reviewers: alexfh

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

llvm-svn: 253036
2015-11-13 12:16:10 +00:00
Samuel Benzaquen b43962768a Fix bug in suggested fix that truncated variable names to 1 character.
Summary:
Fix bug in suggested fix that truncated variable names to 1 character.
Also, rework the suggested fix to try to remove unnecessary whitespace.

Reviewers: alexfh, aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 252773
2015-11-11 18:40:36 +00:00
Daniel Marjamaki 1e9ef81187 [clang-tidy] misc-macro-parentheses: fix fp when using object member pointers
Fixes http://llvm.org/PR25208.

llvm-svn: 252608
2015-11-10 14:32:25 +00:00
Alexander Kornienko 64956b5e9a Add ExtraArgs and ExtraArgsBefore options to enable clang warnings via configuration files.
Summary: This patch depends on http://reviews.llvm.org/D14191

Reviewers: djasper, klimek

Subscribers: cfe-commits

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

llvm-svn: 252485
2015-11-09 16:28:11 +00:00
Alexander Kornienko 301130ef7c [clang-tidy] Fix message style (capitalization, trailing period).
llvm-svn: 252471
2015-11-09 15:53:28 +00:00