Commit Graph

357 Commits

Author SHA1 Message Date
Alexander Kornienko ebdfb9cf0c [Clang-tidy] check for malloc, realloc and free calls
Summary:
This checker flags the use of C-style memory management functionality and notes about modern alternatives.
In an earlier revision it tried to autofix some kind of patterns, but that was a bad idea. Since memory management can be so widespread in a program, manual updating is most likely necessary.
Maybe for special cases, there could be later additions to this basic checker.

This is the first checker I wrote and I never did something with clang (only compiling programs). So whenever I missed conventions or did plain retarded stuff, feel free to point it out! I am willing to fix them and write a better checker.

I hope the patch does work, I never did this either. On a testapply in my repository it did, but I am pretty unconfident in my patching skills :)

Reviewers: aaron.ballman, hokein, alexfh, malcolm.parsons

Subscribers: cfe-commits, JDevlieghere, nemanjai, Eugene.Zelenko, Prazek, mgorny, modocache

Tags: #clang-tools-extra

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

Patch by Jonas Toth!

llvm-svn: 289546
2016-12-13 16:38:18 +00:00
Malcolm Parsons e7be4a004b [clang-tidy] Add check for redundant function pointer dereferences
Reviewers: alexfh, aaron.ballman, hokein

Subscribers: mgorny, JDevlieghere, cfe-commits

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

llvm-svn: 289524
2016-12-13 08:04:11 +00:00
Malcolm Parsons 7636149f31 Add a blank line to make sphinx happy.
llvm-svn: 288384
2016-12-01 17:38:54 +00:00
Malcolm Parsons bcf23661d0 [clang-tidy] Rename modernize-use-default to modernize-use-equals-default
Reviewers: angelgarcia, aaron.ballman, alexfh

Subscribers: JDevlieghere, Prazek, mgorny, cfe-commits

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

llvm-svn: 288375
2016-12-01 17:24:42 +00:00
Jonas Devlieghere 7319184946 [clang-tidy] Make format style customizable
Summary: I came across an outstanding FIXME to make the format style customizable. Inspired by the include fixer, I added an new option `-style` to configure the fallback style in case no clang-format configuration file is found. The default remains "llvm". 

Reviewers: Prazek, aaron.ballman, hokein, alexfh

Subscribers: cfe-commits, malcolm.parsons

Tags: #clang-tools-extra

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

llvm-svn: 288258
2016-11-30 18:06:42 +00:00
Malcolm Parsons 5831a00634 [docs] Remove doubled spaces
Reviewers: aaron.ballman

Subscribers: nemanjai, cfe-commits

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

llvm-svn: 287226
2016-11-17 14:26:45 +00:00
Gabor Horvath 678dd8fc62 [clang-tidy] New check to prefer transparent functors to non-transparent ones.
llvm-svn: 287107
2016-11-16 14:42:10 +00:00
Malcolm Parsons e293eab46f [clang-tidy] Add modernize-use-equals-delete check
Summary: Fixes PR27872

Reviewers: klimek, hokein, alexfh, aaron.ballman

Subscribers: Prazek, Eugene.Zelenko, danielmarjamaki, cfe-commits, mgorny

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

llvm-svn: 286472
2016-11-10 16:46:59 +00:00
Malcolm Parsons d784f20c13 [clang-tidy] Add missing meta refresh for cert-msc30-c doc. NFC
llvm-svn: 286466
2016-11-10 16:19:17 +00:00
Alexander Kornienko a6a52b2d63 [clang-tidy docs] Minor formatting changes.
llvm-svn: 286404
2016-11-09 22:31:07 +00:00
Alexander Kornienko 967f753e10 [clang-tidy docs] Recommend using add_new_check.py more
llvm-svn: 286390
2016-11-09 20:03:30 +00:00
Alexander Kornienko ed999fe0b2 Remove mentions of clang-analyzer-alpha
llvm-svn: 286257
2016-11-08 18:12:56 +00:00
Malcolm Parsons 8b70e2631c [clang-tidy] Handle data() in readability-redundant-string-cstr
Summary:
std::string::data() and std::string::c_str() are equivalent.
Enhance the readability-redundant-string-cstr check to also handle
calls to data().

Reviewers: etienneb, alexfh, aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 285901
2016-11-03 12:56:48 +00:00
Eugene Zelenko 1867c6cd42 [Documentation] Fix Clang-tidy misc-use-after-move and cert-msc50-cpp style and misspelling.
llvm-svn: 285848
2016-11-02 18:23:52 +00:00
Martin Bohme 5d9d417a08 [clang-tidy] Extend misc-use-after-move to support unique_ptr and shared_ptr.
Summary:
As a unique_ptr or shared_ptr that has been moved from is guaranteed to be null,
we only warn if the pointer is dereferenced.

Reviewers: hokein, alexfh, aaron.ballman

Subscribers: Prazek, cfe-commits

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

llvm-svn: 285842
2016-11-02 17:34:47 +00:00
Aaron Ballman 7bfa685611 Add a new clang-tidy check for cert-msc50-cpp (and cert-msc30-c) that corresponds to the CERT C++ secure coding rule: https://www.securecoding.cert.org/confluence/display/cplusplus/MSC50-CPP.+Do+not+use+std%3A%3Arand%28%29+for+generating+pseudorandom+numbers
Patch by Benedek Kiss

llvm-svn: 285809
2016-11-02 14:16:36 +00:00
Eugene Zelenko ae8e12e79f [Documentation] Clang-tidy readability-redundant-declaration consistency.
Release notes checks order and consistent Clang-tidy readability-redundant-declaration description.

llvm-svn: 285778
2016-11-02 00:43:23 +00:00
Daniel Marjamaki 399a50cf35 [clang-tidy] Add check readability-redundant-declaration
Finds redundant variable and function declarations.

  extern int X;
  extern int X;  // <- redundant

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

llvm-svn: 285689
2016-11-01 13:26:15 +00:00
Malcolm Parsons 2792dccb36 [clang-tidy] Update cert-err58-cpp to match its new generalised form.
Summary:
Aaron modified cert-err58-cpp to include all exceptions thrown before main()
Update the check to match.

Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 285653
2016-10-31 22:47:04 +00:00
Eugene Zelenko 01fd221a29 [Release notes] Highlight reset() as language/library artifact.
llvm-svn: 285645
2016-10-31 22:05:45 +00:00
Malcolm Parsons 54c5a545be [clang-tidy] Enhance modernize-make-unique to handle unique_ptr.reset()
Summary:
Avoid naked new in unique_ptr.reset() by using make_unique

Fixes http://llvm.org/PR27383

Reviewers: alexfh, aaron.ballman

Subscribers: Prazek, cfe-commits

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

llvm-svn: 285589
2016-10-31 15:48:01 +00:00
Malcolm Parsons aa800837d3 Fix link to check
llvm-svn: 285581
2016-10-31 14:48:49 +00:00
Malcolm Parsons db04833fca [clang-tidy] Enhance modernize-use-auto to casts
Summary:
Extend modernize-use-auto to cases when a variable is assigned with a cast.

e.g.
Type *Ptr1 = dynamic_cast<Type*>(Ptr2);

http://llvm.org/PR25499

Reviewers: angelgarcia, aaron.ballman, klimek, Prazek, alexfh

Subscribers: Prazek, Eugene.Zelenko, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 285579
2016-10-31 14:43:37 +00:00
Eugene Zelenko 566b34d9b7 [Release notes] Mention removed Clang-tidy misc-pointer-and-integral-operation check
llvm-svn: 284894
2016-10-21 22:35:58 +00:00
Richard Smith 00c03c5de7 Remove 'misc-pointer-and-integral-operation' clang-tidy check. The only cases
it detects are ill-formed (some per C++ core issue 1512, others always have
been).

llvm-svn: 284888
2016-10-21 21:50:28 +00:00
Malcolm Parsons 5c24a1148d [clang-tidy] Add check 'readability-redundant-member-init'
Summary: The check emits a warning if a member-initializer calls the member's default constructor with no arguments.

Reviewers: sbenza, alexfh, aaron.ballman

Subscribers: modocache, mgorny, Eugene.Zelenko, etienneb, Prazek, hokein, cfe-commits, beanz

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

llvm-svn: 284742
2016-10-20 16:08:03 +00:00
Marek Kurdej 2cf1dc2add [clang-tidy] Add cert-err09-cpp check alias.
Summary: This adds cert-err09-cpp alias for completeness, similar to cert-err61-cpp.

Reviewers: alexfh, hokein

Subscribers: cfe-commits

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

llvm-svn: 284596
2016-10-19 14:28:19 +00:00
Malcolm Parsons f156079921 Fix typo in documentation
llvm-svn: 283865
2016-10-11 09:42:13 +00:00
Haojian Wu eaf77911b2 [clang-tidy] Add a whitelist option in google-runtime-references.
Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 283777
2016-10-10 16:38:11 +00:00
Haojian Wu 0e1a50e9c4 Overhaul clang-include-fixer.el
General overhaul to fix many coding bugs, simplify the code, and improve readability.

* Clarify documentation strings of user options.
* Say that clang-include-fixer-executable is a file to have auto completion.
* Allow user to select available options for clang-include-fixer-input-format. Turn it into a symbol as it's not a free-form string.
* Remove clang-include-fixer-query-mode. This option was apparently used to select between two different operation modes, which is not a typical use case for user options. Provide two separate commands instead.
* Add a face for the overlay highlighting so that users can customize it.
Move user commands to the front so that readers of the code aren't buried in internal functions.
* Make process calls asynchronous. This is possible here because clang-include-fixer doesn't change files in place. This means input is no longer blocked while clang-include-fixer is running.
* Factor out logic in helper functions to keep functions short.
* Add comments where appropriate.
* Provide an alternative buffer replacement strategy for the case that a single line was inserted (the normal case in the case of clang-include-fixer). This keeps point, markers, and other buffer information intact.
* Use let-alist and association lists instead of property lists to shorten the code.
* Instead of highlighting only the first occurrence of a symbol, highlight all occurrences and move point to the closest one.
* Detect qualified names at point.
* Use filepos-to-bufferpos if available.
* Formatting.

Patch by Philipp Stephani!

llvm-svn: 283306
2016-10-05 10:04:13 +00:00
Haojian Wu 54f8efaa26 [include-fixer] Add customized editor settings documents.
Reviewers: bkramer

Subscribers: cfe-commits

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

llvm-svn: 282480
2016-09-27 10:43:38 +00:00
Haojian Wu e5555e217c [clang-tidy] Add doc for `explain-config` option.
llvm-svn: 282158
2016-09-22 14:36:43 +00:00
Kirill Bobyrev e5e7e153b5 [clang-rename] Merge rename-{at|all} & optimise.
Having both rename-at and rename-all both seems confusing and introduces
unneeded difficulties. After merging rename-at and rename-all maintaining main
function wrappers and custom help becomes redundant while CLI becomes less
confusing.

D24224 (which was the original patch causing buildbot failures) wasn't aware of
bugs caused by passing both -offset and -qualified-name. After D24224 was landed
it caused buildbot failures and therefor I just reverted it.

Two things that make this patch different from D24224 are:

* unittests/clang-rename was deleted, because it is unmaintained and doesn't do
much.
* Passing both `-offset` and `-qualified-name` isn't allowed anymore for the
sake of preventing bugs.

This patch is a trivial enhancement of accepted D24224 revision.

Tested with `ninja check-all`.

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

llvm-svn: 281710
2016-09-16 08:45:19 +00:00
Eugene Zelenko a8c46ce608 [Release notes] Mention readability-container-size-empty improvements.
Differential revision: https://reviews.llvm.org/D24526

llvm-svn: 281510
2016-09-14 17:41:51 +00:00
Kirill Bobyrev 8d78af4bb4 reverting r281456
llvm-svn: 281459
2016-09-14 13:23:14 +00:00
Kirill Bobyrev c2ed91fc4e [clang-rename] Merge rename-{at|all} & optimize.
Having both rename-at and rename-all both seems confusing and introduces
unneeded difficulties. Allowing to use both -qualified-name and -offset at once
while performing efficient renamings seems like a feature, too. Maintaining main
function wrappers and custom help becomes redundant while CLI becomes less
confusing.

Reviewers: alexfh

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

llvm-svn: 281456
2016-09-14 13:00:36 +00:00
Martin Bohme 42d3839bc5 [clang-tidy] Add check 'misc-use-after-move'
Summary:
The check warns if an object is used after it has been moved, without an
intervening reinitialization.

See user-facing documentation for details.

Reviewers: sbenza, Prazek, alexfh

Subscribers: beanz, mgorny, shadeware, omtcyfz, Eugene.Zelenko, Prazek, fowles, ioeric, cfe-commits

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

llvm-svn: 281453
2016-09-14 10:29:32 +00:00
Kirill Bobyrev acb6b35b56 [clang-tidy] Extend readability-container-size-empty to arbitrary class with size() and empty()
This patch extends readability-container-size-empty check allowing it to produce
warnings not only for STL containers, but also for containers, which provide two
functions matching following signatures:

* `size_type size() const;`
* `bool empty() const;`

Where `size_type` can be any kind of integer type.

This functionality was proposed in https://llvm.org/bugs/show_bug.cgi?id=26823
by Eugene Zelenko.

Approval: alexfh

Reviewers: alexfh, aaron.ballman, Eugene.Zelenko

Subscribers: etienneb, Prazek, hokein, xazax.hun, cfe-commits

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

llvm-svn: 281307
2016-09-13 08:58:11 +00:00
Daniel Marjamaki 03ea468a1c [clang-tidy] readability-misplaced-array-index: add new check that warns when array index is misplaced.
Reviewers: alexfh

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

llvm-svn: 281206
2016-09-12 12:04:13 +00:00
Eugene Zelenko 31c9621320 [Release notes] Fix links.
Differential revision: https://reviews.llvm.org/D24201

llvm-svn: 280725
2016-09-06 17:52:44 +00:00
Hans Wennborg 5a39e2b0a5 Remove link to clang's release notes; keeping it up-to-date is hard
llvm-svn: 280539
2016-09-02 20:39:46 +00:00
Haojian Wu 997c31e54b [clang-tidy docs] Add missing option docs.
Reviewers: alexfh, Eugene.Zelenko, aaron.ballman

Subscribers: aaron.ballman, cfe-commits

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

llvm-svn: 280236
2016-08-31 13:21:18 +00:00
Haojian Wu 544a8d03ab [docs] Fix docs build error.
llvm-svn: 280235
2016-08-31 13:17:48 +00:00
Piotr Padlewski d57be707b8 [clang-tidy] modernize-make-{smart_ptr} private ctor bugfix
Summary:
Bugfix for 27321. When the constructor of stored pointer
type is private then it is invalid to change it to
make_shared or make_unique.

Reviewers: alexfh, aaron.ballman, hokein

Subscribers: cfe-commits

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

llvm-svn: 280180
2016-08-31 00:06:55 +00:00
Eugene Zelenko 8899d52c18 [Release notes] Fix highlighting.
llvm-svn: 280119
2016-08-30 17:47:07 +00:00
Haojian Wu 2c5ee4454d [clang-tidy docs] Fix build errors on Sphinx 1.4.6
llvm-svn: 280095
2016-08-30 14:29:36 +00:00
Martin Bohme b1ce6c6d57 [clang-tidy] Add check 'misc-move-forwarding-reference'
Summary:
The check emits a warning if std::move() is applied to a forwarding reference, i.e. an rvalue reference of a function template argument type.

If a developer is unaware of the special rules for template argument deduction on forwarding references, it will seem reasonable to apply std::move() to the forwarding reference, in the same way that this would be done for a "normal" rvalue reference.

This has a consequence that is usually unwanted and possibly surprising: If the function that takes the forwarding reference as its parameter is called with an lvalue, that lvalue will be moved from (and hence placed into an indeterminate state) even though no std::move() was applied to the lvalue at the callsite.

As a fix, the check will suggest replacing the std::move() with a std::forward().

This patch requires D23004 to be submitted before it.

Reviewers: sbenza, aaron.ballman

Subscribers: klimek, etienneb, alexfh, aaron.ballman, Prazek, Eugene.Zelenko, mgehre, cfe-commits

Projects: #clang-tools-extra

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

llvm-svn: 280077
2016-08-30 12:11:12 +00:00
Sylvestre Ledru 24b481370a Fix some typos in the doc
llvm-svn: 279944
2016-08-28 20:33:42 +00:00
Eugene Zelenko 8e8fa78821 [Clang-tidy] Fix some checks documentation style.
Differential revision: https://reviews.llvm.org/D23894

llvm-svn: 279846
2016-08-26 17:46:51 +00:00
Haojian Wu 0a1986790c [clang-tidy] Some tweaks on header guard checks.
* Implement missing storeOption interfaces.
* Remove unnecessary parameter copy in isHeaderFileExtension.
* Fix doc style.

llvm-svn: 279814
2016-08-26 11:15:38 +00:00