Commit Graph

1649 Commits

Author SHA1 Message Date
Etienne Bergeron 9cfd8cea6b [clang-tidy] Add more detection rules for redundant c_str calls.
Summary:
The string class contains methods which support receiving either a string literal or a string object.

For example, calls to append can receive either a char* or a string.
```
  string& append (const string& str);
  string& append (const char* s);
```

Which make these cases equivalent, and the .c_str() useless:
```
  std::string s = "123";
  str.append(s);
  str.append(s.c_str());
```

In these cases, removing .c_str()  doesn't provide any size or speed improvement.
It's only a readability issue.

If the string contains embedded NUL characters,  the string literal and the string
object won't produce the same semantic.

Reviewers: alexfh, sbenza

Subscribers: LegalizeAdulthood, aaron.ballman, chapuni, Eugene.Zelenko, cfe-commits

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

llvm-svn: 266463
2016-04-15 18:12:06 +00:00
Eugene Zelenko dca3812252 [Release Notes] mention Clang-tidy misc-multiple-statement-macro check.
llvm-svn: 266455
2016-04-15 17:32:19 +00:00
Etienne Bergeron 1f696b316c [clang-tidy] Add new checker for suspicious sizeof expressions
Summary:
This check is finding suspicious cases of sizeof expression.

Sizeof expression is returning the size (in bytes) of a type or an
expression. Programmers often abuse or misuse this expression.

This checker is adding common set of patterns to detect some
of these bad constructs.


Some examples found by this checker:

R/packages/ifultools/ifultools/src/fra_neig.c
```
        /* free buffer memory */
        (void) mutil_free( dist_buff, sizeof( ctr * sizeof( double ) ) );
        (void) mutil_free( nidx_buff, sizeof( ctr * sizeof( sint32 ) ) );
```


graphviz/v2_20_2/lib/common/utils.c
```
static Dtdisc_t mapDisc = {
    offsetof(item, p),
    sizeof(2 * sizeof(void *)),
    offsetof(item, link),
    (Dtmake_f) newItem,
    (Dtfree_f) freeItem,
    (Dtcompar_f) cmpItem,
    NIL(Dthash_f),
    NIL(Dtmemory_f),
    NIL(Dtevent_f)
};
```


mDNSResponder/mDNSShared/dnsextd.c
```
	context = ( TCPContext* ) malloc( sizeof( TCPContext ) );
	require_action( context, exit, err = mStatus_NoMemoryErr; LogErr( "AcceptTCPConnection", "malloc" ) );
	mDNSPlatformMemZero( context, sizeof( sizeof( TCPContext ) ) );
	context->d		 = self;
```

Reviewers: alexfh

Subscribers: malcolm.parsons, Eugene.Zelenko, cfe-commits

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

llvm-svn: 266451
2016-04-15 16:36:00 +00:00
Etienne Bergeron 3c5be6c9a7 [clang-tidy] Add checker for operations between integrals and pointers
Summary:
This check is finding suspicious operations involving pointers and integral types; which are most likely bugs.

Examples:
subversion/v1_6/subversion/libsvn_subr/utf.c
```
static const char *
fuzzy_escape(const char *src, apr_size_t len, apr_pool_t *pool)
{
  [...]
   while (src_orig < src_end)
    {
      if (! svn_ctype_isascii(*src_orig) || src_orig == '\0')   // Should be *src_orig
        {
```

apache2/v2_2_23/modules/metadata/mod_headers.c
```
static char *parse_format_tag(apr_pool_t *p, format_tag *tag, const char **sa)
{
  [...]
    tag->arg = '\0';   // ERROR: tag->arg has type char*

    /* grab the argument if there is one */
    if (*s == '{') {
        ++s;
        tag->arg = ap_getword(p,&s,'}');
    }
```

Reviewers: alexfh

Subscribers: Eugene.Zelenko, cfe-commits

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

llvm-svn: 266450
2016-04-15 16:31:15 +00:00
Samuel Benzaquen 4fa2d57c6d [clang-tidy] Add check misc-multiple-statement-macro
Summary:
The check detects multi-statement macros that are used in unbraced conditionals.
Only the first statement will be part of the conditionals and the rest will fall
outside of it and executed unconditionally.

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 266369
2016-04-14 21:15:57 +00:00
Aaron Ballman b602ee7d8f Add support for type aliases to modernize-redundant-void-arg.cpp
Patch by Clement Courbet.

llvm-svn: 266358
2016-04-14 19:28:13 +00:00
Etienne Bergeron 47205aa773 [clang-tidy] Fix documentation generation.
Summary: The patch is fixing the generation of clang-tidy documentation.

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 266333
2016-04-14 16:08:04 +00:00
NAKAMURA Takumi 42b5969862 clang-tools-extra/test/clang-tidy/readability-deleted-default.cpp: Add -fno-ms-compatibility.
llvm-svn: 266265
2016-04-13 23:50:45 +00:00
Alexander Kornienko 855d97e30c Complete support for C++ Core Guidelines Type.6: Always initialize a member variable.
Summary: Added the remaining features needed to satisfy C++ Core Guideline Type.6: Always initialize a member variable to cppcoreguidelines-pro-type-member-init. The check now flags all default-constructed uses of record types without user-provided default constructors that would leave their memory in an undefined state. The check suggests value initializing them instead.

Reviewers: flx, alexfh, aaron.ballman

Subscribers: klimek, aaron.ballman, LegalizeAdulthood, cfe-commits

Patch by Michael Miller!

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

llvm-svn: 266191
2016-04-13 11:35:47 +00:00
Alexander Kornienko 4191b90c75 [clang-tidy] Add a readability-deleted-default clang-tidy check.
Checks if constructors and assignment operators that are marked '= default' are
actually deleted by the compiler.

Patch by Alex Pilkiewicz!

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

llvm-svn: 266190
2016-04-13 11:33:40 +00:00
Alexander Kornienko 6110cca6ef [clang-tidy] add_new_check.py should fail if check name starts with the module name
+ updated formatting

llvm-svn: 266181
2016-04-13 08:46:32 +00:00
Matthias Gehre 018c1d4243 [clang-tidy] fix readability-avoid-const-params-in-decls creating invalid code in fix-its
Summary:
The Fix-Its for the added test cases were before:
-void F11(const unsigned int /*version*/);
+void F11(unsigned int int /*version*/);

-void F12(const bool b = true);
+void F12(_Bool true);

Reviewers: fowles, hokein, sbenza, alexfh

Subscribers: cfe-commits

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

llvm-svn: 266044
2016-04-12 05:45:13 +00:00
Eugene Zelenko 2f7ec9134d [Release Notes] Sort checks alphabetically.
llvm-svn: 265813
2016-04-08 17:21:27 +00:00
Alexander Kornienko 477e5d8d31 [clang-tidy] cppcoreguidelines-interfaces-global-init
Summary:
This check flags initializers of globals that access extern objects, and therefore can lead to order-of-initialization problems (this recommandation is part of CPP core guidelines).
Note that this only checks half of the guideline for now (it does not enforce using constexpr functions).

Reviewers: aaron.ballman, alexfh

Subscribers: aaron.ballman, etienneb, Eugene.Zelenko, cfe-commits

Patch by Clement Courbet!

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

llvm-svn: 265774
2016-04-08 09:51:06 +00:00
Eugene Zelenko b869289cf3 Mention readability-static-definition-in-anonymous-namespace in release notes.
Consistency in using ` and ``.

Differential revision: http://reviews.llvm.org/D18797

llvm-svn: 265698
2016-04-07 17:28:35 +00:00
Etienne Bergeron a5fd19ba1e [clang-tidy] add new checker for string literal with NUL character.
Summary:
This patch adds the support for detecting suspicious string
literals and their //incorrect// usage.

The following example shows a incorrect character escaping leading 
to an embedded NUL character. 
```
  std::string str = "\0x42";   // Should be "\x42".
```

The patch also add detection of truncated literal when a literal
is passed to a string constructor.

Reviewers: hokein, alexfh

Subscribers: LegalizeAdulthood, bcraig, Eugene.Zelenko, bkramer, cfe-commits

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

llvm-svn: 265691
2016-04-07 16:16:36 +00:00
Etienne Bergeron 2c82ebe813 [clang-tidy] fix a crash with -fdelayed-template-parsing in UnnecessaryValueParamCheck.
Summary:
This is the same kind of bug than [[ http://reviews.llvm.org/D18238 | D18238 ]].

Fix crashes caused by deferencing null pointer when declarations parsing may be delayed.
The body of the declarations may be null.

The crashes were observed with a Windows build of clang-tidy and the following command-line.
```
command-line switches: -fms-compatibility-version=19 -fms-compatibility
```

Reviewers: alexfh

Subscribers: kimgr, LegalizeAdulthood, cfe-commits

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

llvm-svn: 265681
2016-04-07 14:58:13 +00:00
Benjamin Kramer a62e223281 [clang-tidy] Remove unnecessary getName() on Decls and Types feeding into a DiagnosticBuilder
Going through a string removes some of the smarts of the diagnosic printer
and makes the code more complicated. This change has some cosmetic impact
on the output but that's mostly minor.

llvm-svn: 265680
2016-04-07 14:55:25 +00:00
Etienne Bergeron 53f7c0ea8e [clang-tidy] Fix infinite loop in MisplacedWideningCastCheck.
Summary:
In Release mode, the check was infinite looping over chromium code base.

It seems there is something strange with the creation of the Maps.
I believe the compiler is making some assumption with the implicit conversion from enum <-> int.

By moving the map to a standard switch/cases, we no longer allocate memory and we can keep the same behavior. For a small amount of elements, this is fine.

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 265679
2016-04-07 14:52:52 +00:00
Etienne Bergeron f6660dab02 [clang-tidy] Fix FP with readability-redundant-string-init for default arguments
Summary:
Clang-tidy is reporting a warning of redundant string initialisation
on a string parameter initialized with empty string.

See bug: 27087

The reported example is:
```
#include <string>
void fn(std::string a = "");
```

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 265671
2016-04-07 14:18:53 +00:00
Alexander Kornienko b5485b8ade [docs] Update version (http://llvm.org/PR27253)
llvm-svn: 265655
2016-04-07 10:17:23 +00:00
Gabor Horvath 0dbd37543c [clang-tidy] Assertion fix in misc-misplaced-widening-cast check.
llvm-svn: 265544
2016-04-06 14:49:15 +00:00
Etienne Bergeron 4eaeacec6d [clang-tidy] filter plugins and plugin arguments of the command-line
Summary:
This patch remove the plugin argument from the command-line.

Loading plugins was making clang-tidy to fail when running over chromium (linux).

Example of a command-line executed when running clang-tidy over chromium (from the compilation database).

```
../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF obj/third_party/WebKit/Source/core/fetch/webcore_shared.Resource.o.d -DV8_DEPRECATION_WARNINGS -DCLD_VERSION=2 -D_FILE_OFFSET_BITS=64 -DCHROMIUM_BUILD -DCR_CLANG_REVISION=264915-1 -DCOMPONENT_BUILD -DUI_COMPOSITOR_IMAGE_TRANSPORT -DUSE_AURA=1 -DUSE_PANGO=1 -DUSE_CAIRO=1 -DUSE_DEFAULT_RENDER_THEME=1 -DUSE_LIBJPEG_TURBO=1 -DUSE_X11=1 -DUSE_CLIPBOARD_AURAX11=1 -DENABLE_WEBRTC=1 -DENABLE_MEDIA_ROUTER=1 -DENABLE_PEPPER_CDMS -DENABLE_NOTIFICATIONS -DENABLE_TOPCHROME_MD=1 -DUSE_UDEV -DFIELDTRIAL_TESTING_ENABLED -DENABLE_TASK_MANAGER=1 -DENABLE_EXTENSIONS=1 -DENABLE_PDF=1 -DENABLE_PLUGINS=1 -DENABLE_SESSION_SERVICE=1 -DENABLE_THEMES=1 -DENABLE_AUTOFILL_DIALOG=1 -DENABLE_PRINTING=1 -DENABLE_BASIC_PRINTING=1 -DENABLE_PRINT_PREVIEW=1 -DENABLE_SPELLCHECK=1 -DENABLE_CAPTIVE_PORTAL_DETECTION=1 -DENABLE_APP_LIST=1 -DENABLE_SETTINGS_APP=1 -DENABLE_SUPERVISED_USERS=1 -DENABLE_MDNS=1 -DENABLE_SERVICE_DISCOVERY=1 -DV8_USE_EXTERNAL_STARTUP_DATA -DFULL_SAFE_BROWSING -DSAFE_BROWSING_CSD -DSAFE_BROWSING_DB_LOCAL -DBLINK_CORE_IMPLEMENTATION=1 -DBLINK_IMPLEMENTATION=1 -DINSIDE_BLINK -DGL_GLEXT_PROTOTYPES -DMOJO_USE_SYSTEM_IMPL -DCHROME_PNG_WRITE_SUPPORT -DPNG_USER_CONFIG -DENABLE_LAYOUT_UNIT_IN_INLINE_BOXES=0 -DENABLE_OILPAN=1 -DWTF_USE_CONCATENATED_IMPULSE_RESPONSES=1 -DENABLE_INPUT_MULTIPLE_FIELDS_UI=1 -DWTF_USE_ICCJPEG=1 -DWTF_USE_QCMSLIB=1 -DWTF_USE_WEBAUDIO_FFMPEG=1 -DWTF_USE_DEFAULT_RENDER_THEME=1 -DU_USING_ICU_NAMESPACE=0 -DU_ENABLE_DYLOAD=0 -DU_NOEXCEPT= -DSKIA_DLL -DGR_GL_IGNORE_ES3_MSAA=0 -DSK_SUPPORT_GPU=1 -DSK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS -DLIBXML_STATIC -DLIBXSLT_STATIC -DV8_SHARED -DUSING_V8_SHARED -DUSE_LIBPCI=1 -DUSE_OPENSSL=1 -DUSE_GLIB=1 -DUSE_NSS_CERTS=1 -DUSE_NSS_VERIFIER=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DWTF_USE_DYNAMIC_ANNOTATIONS=1 -D_DEBUG -D_GLIBCXX_DEBUG=1 -Igen -I../../third_party/WebKit/Source -Igen/blink -I../../third_party/WebKit -I../../third_party/WebKit/Source/core/testing -I../../third_party/WebKit/Source/core/testing/v8 -I../.. -I../../skia/config -I../../third_party/khronos -I../../gpu -Igen/angle -I../../third_party/angle/include -I../../third_party/ffmpeg -Igen/third_party/WebKit -I../../third_party/iccjpeg -I../../third_party/libpng -I../../third_party/libwebp -I../../third_party/ots/include -I../../third_party/zlib -I../../third_party/libjpeg_turbo -I../../third_party/icu/source/i18n -I../../third_party/icu/source/common -I../../skia/ext -I../../third_party/skia/include/core -I../../third_party/skia/include/effects -I../../third_party/skia/include/pdf -I../../third_party/skia/include/gpu -I../../third_party/skia/include/lazy -I../../third_party/skia/include/pathops -I../../third_party/skia/include/pipe -I../../third_party/skia/include/ports -I../../third_party/skia/include/utils -I../../third_party/libxml/linux/include -I../../third_party/libxml/src/include -I../../third_party/libxslt -I../../third_party/npapi -I../../third_party/npapi/bindings -I../../third_party/qcms/src -I../../third_party/snappy/linux -I../../third_party/snappy/src -I../../v8/include -fstack-protector --param=ssp-buffer-size=4 -Werror -pthread -fno-strict-aliasing -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -fvisibility=hidden -pipe -fPIC -Xclang -load -Xclang /home/etienneb/chromium/src/third_party/llvm-build/Release+Asserts/lib/libFindBadConstructs.so -Xclang -add-plugin -Xclang find-bad-constructs -Xclang -plugin-arg-find-bad-constructs -Xclang check-templates -Xclang -plugin-arg-find-bad-constructs -Xclang follow-macro-expansion -fcolor-diagnostics -B/home/etienneb/chromium/src/third_party/binutils/Linux_x64/Release/bin -Wheader-hygiene -Wno-char-subscripts -Wno-unneeded-internal-declaration -Wno-covered-switch-default -Wstring-conversion -Wno-c++11-narrowing -Wno-deprecated-register -Wno-inconsistent-missing-override -Wno-shift-negative-value -Wglobal-constructors -Wexit-time-destructors -fno-strict-aliasing -Xclang -load -Xclang /home/etienneb/chromium/src/third_party/llvm-build/Release+Asserts/lib/libBlinkGCPlugin.so -Xclang -add-plugin -Xclang blink-gc-plugin -Xclang -plugin-arg-blink-gc-plugin -Xclang enable-oilpan -Xclang -plugin-arg-blink-gc-plugin -Xclang warn-raw-ptr -pthread -I/home/etienneb/chromium/src/build/linux/debian_wheezy_amd64-sysroot/usr/include/glib-2.0 -I/home/etienneb/chromium/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib/x86_64-linux-gnu/glib-2.0/include -m64 -march=x86-64 --sysroot=/home/etienneb/chromium/src/build/linux/debian_wheezy_amd64-sysroot -O0 -g -funwind-tables -gsplit-dwarf -g0 -fno-exceptions -fno-rtti -fno-threadsafe-statics -fvisibility-inlines-hidden -std=gnu++11  -c ../../third_party/WebKit/Source/core/fetch/Resource.cpp -o obj/third_party/WebKit/Source/core/fetch/webcore_shared.Resource.o
```

The plugins are added with the following arguments:
```
-Xclang -load -Xclang /home/etienneb/chromium/src/third_party/llvm-build/Release+Asserts/lib/libFindBadConstructs.so -Xclang -add-plugin -Xclang find-bad-constructs -Xclang -plugin-arg-find-bad-constructs -Xclang check-templates -Xclang -plugin-arg-find-bad-constructs -Xclang follow-macro-expansion
```

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 265542
2016-04-06 14:07:51 +00:00
Etienne Bergeron 500846c283 [clang-tidy] fix building clang-tidy documentation.
Summary:
The clang-tidy documentation can't be generated because of broken links.

```
Warning, treated as error:
/home/etienneb/llvm/llvm/tools/clang/tools/extra/docs/clang-tidy/checks/google-readability-function-size.rst:: WARNING: document isn't included in any toctree
```

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 265539
2016-04-06 13:57:22 +00:00
Gabor Horvath 5273f615c4 [clang-tidy] Extension of checker misc-misplaced-widening-cast
Summary:
Existing checker misc-misplaced-widening-cast was extended:
- New use cases: casted expression as lhs or rhs of a logical comparison or function argument
- New types: beside int, long and long long various char types, short and int128 added
- New option to check implicit casts: forgetting a cast is at least as common and as dangerous as misplacing it. This option can be disabled.

This patch depends on AST Matcher patches D17986 and D18243 and also contains fix for checker misc-bool-pointer-implicit-conversion needed because of the fix in the AST Matcher patch.

Reviewers: hokein, alexfh

Subscribers: o.gyorgy, xazax.hun, cfe-commits

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

llvm-svn: 265532
2016-04-06 12:04:51 +00:00
Haojian Wu c253f8b06b [clang-tidy] Add a check to detect static definitions in anonymous namespace.
Summary: Fixes PR26595

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 265384
2016-04-05 11:42:08 +00:00
Etienne Bergeron 009ec085db [clang-tidy] Fix documentation of misc-suspicious-missing-comma
Summary:
The clang-tidy documentation generation was broken since commit : http://reviews.llvm.org/D18457

I ran locally the documentation generation and I fixed errors related to that specific check.

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 265375
2016-04-05 01:41:02 +00:00
Etienne Bergeron 1eec3f01f0 [clang-tidy] Reduce false-positive ratio in misc-suspicious-missing-comma check.
Summary:
This patch is adding detection of common string literal patterns
that should not trigger warnings.

  [*] Add a limit on the number of concatenated token,
  [*] Add support for parenthese sequence of tokens,
  [*] Add detection of valid indentation.

As an example, this code will no longer trigger a warning:
```
const char* Array[] = {
  "first literal"
    "indented literal"
    "indented literal",
  "second literal",
  [...]
```

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 265303
2016-04-04 15:46:38 +00:00
Alexander Kornienko 09464e63d8 [clang-tidy] fix a couple of modernize-use-override bugs
Fix for __declspec attributes and const=0 without space

This patch is to address 2 problems I found with Clang-tidy:modernize-use-override.

1: missing spaces on pure function decls.

Orig:
void pure() const=0
Problem:
void pure() constoverride =0
Fixed:
void pure() const override =0

2: This is ms-extension specific, but possibly applies to other attribute types. The override is placed before the attribute which doesn’t work well with declspec as this attribute can be inherited or placed before the method identifier.

Orig:
class __declspec(dllexport) X : public Y

{
void p();
};
Problem:
class override __declspec(dllexport) class X : public Y

{
void p();
};
Fixed:
class __declspec(dllexport) class X : public Y

{
void p() override;
};

Patch by Robert Bolter!

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

llvm-svn: 265298
2016-04-04 14:31:36 +00:00
Alexander Kornienko c2822bd3d1 [clang-tidy] Update an example. NFC.
llvm-svn: 265210
2016-04-02 03:44:23 +00:00
Eugene Zelenko 71d175b429 [Clang-tidy] Improve checks documentation consistency.
Differential revision: http://reviews.llvm.org/D18717

llvm-svn: 265205
2016-04-02 01:07:18 +00:00
Haojian Wu 7d15853c9f [clang-tidy] Don't delete unused parameter in class override method in anonymous namespace.
Summary: Fixes PR26740.

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 265117
2016-04-01 07:57:30 +00:00
Eugene Zelenko ba539dbad2 Update release notes with list of checks added since 3.8.
Fix some checks documentation style.

Differential revision: http://reviews.llvm.org/D18582

llvm-svn: 265072
2016-03-31 23:09:42 +00:00
Etienne Bergeron 3e4adf1762 [clang-tidy] Add a new checker to detect missing comma in initializer list.
Summary:
This checker is able to detect missing comma in 
an array of string literals.

```
  const char* A[] = {
    "abc",
    "def"   // missing comma (no compiler warnings)
    "ghi",
  };
```

The ratio of false-positive is reduced by restricting the
size of the array considered and the ratio of missing
comma.

To validate the quantity of false positive, the checker
was tried over LLVM and chromium code and detected these
cases:

[[ http://reviews.llvm.org/D18454 | http://reviews.llvm.org/D18454 ]]
[[https://codereview.chromium.org/1807753002/ | https://codereview.chromium.org/1807753002/]]
[[https://codereview.chromium.org/1826193002/ | https://codereview.chromium.org/1826193002/]]
[[https://codereview.chromium.org/1805713002/ | https://codereview.chromium.org/1805713002/]]

Reviewers: alexfh

Subscribers: LegalizeAdulthood, szdominik, xazax.hun, cfe-commits

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

llvm-svn: 265033
2016-03-31 18:12:23 +00:00
Alexander Kornienko f85a69bb6f [docs] Fix a typo, change the style of the clang-tidy release notes a bit.
llvm-svn: 265008
2016-03-31 12:06:54 +00:00
Alexander Kornienko 259ce38315 note for top-level consts in function decls tidy
Summary: Add missing release note

Reviewers: alexfh

Subscribers: LegalizeAdulthood, cfe-commits

Patch by Matt Kulukundis!

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

llvm-svn: 265007
2016-03-31 12:06:47 +00:00
Paul Robinson ac6b1ce21a Update copyright year to 2016.
llvm-svn: 264947
2016-03-30 22:38:47 +00:00
Alexander Kornienko b014596047 [clang-tidy] Fix MSVC build.
llvm-svn: 264862
2016-03-30 12:35:05 +00:00
Gabor Horvath 349c828bea [clang-tidy] Adjust dangling references check to ASTMatcher changes.
llvm-svn: 264859
2016-03-30 12:16:09 +00:00
Alexander Kornienko dbe0a1fd92 [docs] Added 3.8 clang-tidy release notes, fixed formatting.
llvm-svn: 264858
2016-03-30 12:05:33 +00:00
Alexander Kornienko e3ae0c6f19 [clang-tidy] readability check for const params in declarations
Summary: Adds a clang-tidy warning for top-level consts in function declarations.

Reviewers: hokein, sbenza, alexfh

Subscribers: cfe-commits

Patch by Matt Kulukundis!

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

llvm-svn: 264856
2016-03-30 11:31:33 +00:00
Samuel Benzaquen b2ccba5257 [clang-tidy] Add check to detect dangling references in value handlers.
Summary:
Add check misc-dangling-handle to detect dangling references in value
handlers like std::experimental::string_view.
It provides a configuration option to specify other handle types that
should also be checked.

Right now it detects:
 - Construction from temporaries.
 - Assignment from temporaries.
 - Return statements from temporaries or locals.
 - Insertion into containers from temporaries.

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 264759
2016-03-29 18:02:26 +00:00
Felix Berger 3c8edde141 [clang-tidy] Add performance check to flag function parameters of expensive to copy types that can be safely converted to const references.
Reviewers: alexfh

Subscribers: fowles, cfe-commits

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

llvm-svn: 264694
2016-03-29 02:42:38 +00:00
Richard Thomson 17d5b81f79 clang-tidy: Fix broken buildbot
VS 2013 does not support char16_t or char32_t

llvm-svn: 264563
2016-03-28 04:15:41 +00:00
Richard Thomson 8930aab886 clang-tidy: Add check modernize-raw-string-literal
llvm-svn: 264539
2016-03-27 16:43:44 +00:00
Richard Thomson f95aa56c79 Add clang-tools-extra release notes
llvm-svn: 264531
2016-03-27 05:06:57 +00:00
NAKAMURA Takumi 6517fb4ff9 3rd attempt of fixup with -std=c++11
llvm-svn: 264367
2016-03-25 00:24:35 +00:00
NAKAMURA Takumi 9f7e2d7657 Fixup -- "-target x86_64-unknown -fno-ms-compatibility" didn't work as expected.
llvm-svn: 264365
2016-03-25 00:16:13 +00:00
NAKAMURA Takumi e0451c9378 clang-tools-extra/test/clang-tidy/readability-redundant-string-cstr.cpp: Appease MS targets with -fno-ms-compatibility.
FIXME: Add a test with  -fms-compatibility.
llvm-svn: 264362
2016-03-25 00:05:33 +00:00
Etienne Bergeron cb7ce98486 [clang-tidy] Add support for different char-types for the readability-redundant-string-cstr checker.
Summary:
The current checker is able to recognize std::string but does not recognize other string variants.
This patch is adding the support for any string defined with basic_string without considering the
the underlying char type.

The most common variant is: 'std::wstring' based on 'wchar_t'.

There are also other string variants added to the standard: u16string, u32string, etc...

Reviewers: alexfh

Subscribers: mamai, dblaikie, cfe-commits

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

llvm-svn: 264325
2016-03-24 19:42:36 +00:00
Gabor Horvath 4530b52a23 [clang-tidy] misc-assign-operator-signature checker checks return value of all assign operators
The return value of every assign operator should be Type&, not only for copy and move assign operators. 

Patch by Adam Balogh!

Reviewers: hokein, alexfh

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

llvm-svn: 264251
2016-03-24 10:12:08 +00:00
Haojian Wu 6ccb1dd9f0 Add check for unneeded copies of locals
Summary: Extends the UnnecessaryCopyInitialization to detect copies of local variables and parameters that are unneeded.

Patch by Matt Kulukundis!

Reviewers: alexfh, hokein

Subscribers: cfe-commits

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

llvm-svn: 264146
2016-03-23 09:33:07 +00:00
Etienne Bergeron e409e688a3 [clang-tidy] Fix broken test with redundant string init (msvc).
Summary:
There is a silly bug that got introduced after fixing incorrect paths with this patch:
http://reviews.llvm.org/D18293

The tests was present twice in the file.

Reviewers: alexfh, rnk

Subscribers: cfe-commits

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

llvm-svn: 264080
2016-03-22 18:21:17 +00:00
Etienne Bergeron 4c3b55cfce [clang-tidy] Fix redundant-string-cstr check with msvc 14 headers.
Summary:
The string constructors are not defined using optional parameters and are not recognize by the checker.

The constructor defined in the MSVC header is defined with 1 parameter. Therefore, patterns are not recognized by the checker.
The current patch add support to accept constructor with only one parameter.

Repro on a Visual Studio 14 installation with the following code:
```
void f1(const std::string &s) {
  f1(s.c_str());
}
```

In the xstring.h header, the constructors are defined this way:
```
basic_string(const _Myt& _Right) [...]
basic_string(const _Myt& _Right, const _Alloc& _Al) [...]
```

The CXXConstructExpr to recognize only contains 1 parameter.
```
CXXConstructExpr 0x3f1a070 <C:\src\llvm\examples\test.cc:6:6, col:14> 'const std::string':'const class std::basic_string<char, struct std::char_traits<char>, class
 std::allocator<char> >' 'void (const char *) __attribute__((thiscall))'
`-CXXMemberCallExpr 0x3f1a008 <col:6, col:14> 'const char *'
  `-MemberExpr 0x3f19fe0 <col:6, col:8> '<bound member function type>' .c_str 0x3cc22f8
    `-DeclRefExpr 0x3f19fc8 <col:6> 'const std::string':'const class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char> >' lvalue ParmVar 0x3f19c80 's' 'const std::string &'
```

Reviewers: aaron.ballman, alexfh

Subscribers: aemerson

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

llvm-svn: 264075
2016-03-22 18:00:13 +00:00
Etienne Bergeron 6feeb6554e [clang-tidy] Skip reporting of not applicable fixes.
Summary:
Invalid source location are causing clang-tidy to crash when manipulating an invalid file.

Macro definitions on the command line have locations in a virtual buffer and therefore
don't have a corresponding valid FilePath.

A recent patch added path conversion to absolute path. As the FilePath may now be empty,
the result of makeAbsolutePath may incorrectly be the folder WorkingDir.  The crash occurs
in getLocation which is not able to find the appropriate FileEntry (null pointer).

```
          SmallString<128> FixAbsoluteFilePath = Fix.getFilePath();
          Files.makeAbsolutePath(FixAbsoluteFilePath);
          FixLoc = getLocation(FixAbsoluteFilePath, Fix.getOffset());
```

With relative path, the code was not crashing because getLocation was skipping empty path.



Example of code:

```
int main() { return X; }
```

With the given command-line:

```
clang-tidy test.cc --checks=misc-macro-*  --  -DX=0+0
```

Reviewers: alexfh, aaron.ballman

Subscribers: aaron.ballman, cfe-commits

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

llvm-svn: 264073
2016-03-22 17:51:27 +00:00
Etienne Bergeron 1329b986d2 [clang-tidy] Fix redundant-string-init check with msvc 14 headers.
Summary:
The string constructors are not defined using optional parameters and are not recognized by the redundant-string-init checker.

The following patch fixes the redundant-string-init checker for the Visual Studio 14 headers file.
The matcher now accept both variant (with 1 and 2 parameters).

Also added new unittests.

Similar issue than: [[ http://reviews.llvm.org/D18285 | review ]]

In the xstring.h header, the constructors are defined this way:
```
basic_string(const _Myt& _Right) [...]
basic_string(const _Myt& _Right, const _Alloc& _Al) [...]
```

Reviewers: alexfh, hokein

Subscribers: cfe-commits

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

llvm-svn: 264069
2016-03-22 17:39:36 +00:00
Aaron Ballman 4c9c07414e Moving files that were placed in the wrong directory from r264049.
llvm-svn: 264050
2016-03-22 13:44:36 +00:00
Aaron Ballman 73a7bd3616 Fix crashes from delayed template parsing code that assumed getBody() would return non-null.
Patch by Etienne Bergeron.

llvm-svn: 264049
2016-03-22 13:37:44 +00:00
John Thompson 1c158c192a Fixed some cases in the modularize assistant mode where header file names didn't translate to valid module names.
llvm-svn: 264001
2016-03-21 23:05:14 +00:00
Samuel Benzaquen bd6a74e1fa [clang-tidy] Fix check broken in rL263822.
Add names missing from rL263822 and add tests to prevent future omissions.

llvm-svn: 263963
2016-03-21 18:00:43 +00:00
Benjamin Kramer 74e4d55dcc [clang-tidy] Update check for API change in r263895.
for range stmts now have split begin and ends, just apply OR to the
condition. Should unbreak the build.

llvm-svn: 263900
2016-03-20 14:24:49 +00:00
Samuel Benzaquen d7f2e34e04 [clang-tidy] Use hasAnyName() instead of matchesName().
matchesName() uses regular expressions and it is very slow.
hasAnyName() gives the same result and it is much faster.
A benchmark (with all the checks enabled) shows a ~5% speed up of
clang-tidy.

llvm-svn: 263822
2016-03-18 20:14:35 +00:00
Eugene Zelenko 05f7e6ae0d Fix Clang-tidy modernize-deprecated-headers warnings; other minor fixes.
Differential revision: http://reviews.llvm.org/D18231

llvm-svn: 263726
2016-03-17 17:02:25 +00:00
Haojian Wu e641cb4807 [clang-tidy] Fix "Name is not a simple identifier" assertion in `modernize-loop-convert` check.
Summary:
Fix assertion failure: "Name is not a simple identifier".

`Decl::GetName` assumes the name should be an identifier. When the check
processes the function calling statement with speciail key name like
'it.operator->()', it will trigger the assert in `GetName`.

Rather than using `Decl::GetName`, we use `getNameAsString` which works
with special key names in C++.

Reviewers: bkramer

Subscribers: cfe-commits

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

llvm-svn: 263426
2016-03-14 12:41:24 +00:00
Haojian Wu 0519744343 [clang-tidy] Make 'modernize-use-nullptr' check ignores NULL marcos used in other macros.
Reviewers: bkramer, alexfh

Subscribers: cfe-commits

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

llvm-svn: 263221
2016-03-11 11:40:08 +00:00
Alexander Kornienko 32effa1974 [docs] Clean up doxygen comments a bit.
llvm-svn: 262787
2016-03-06 04:05:59 +00:00
Felix Berger adfdc14832 [clang-tidy] Extend UnnecessaryCopyInitialization check to trigger on non-const copies that can be safely converted to const references.
Summary:
Move code shared between UnnecessaryCopyInitialization and ForRangeCopyCheck into utilities files.
Add more test cases for UnnecessaryCopyInitialization and disable fixes inside of macros.

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 262781
2016-03-05 21:17:58 +00:00
Haojian Wu 678f65a9b4 [clang-tidy] Make 'modernize-use-nullptr' check work on multiple nested implicit cast expressions.
Summary:
For some test cases like:

```
 int func(int, void*, void*);
(double)func(0, 0, 0);
```

The AST contains several `ImplicitCastExpr`s, so we should not only check on the first sub expression.

```
 `-CStyleCastExpr 0x7fe43a088938 <line:6:3, col:24> 'double' <NoOp>
      `-ImplicitCastExpr 0x7fe43a088920 <col:11, col:24> 'double' <IntegralToFloating>
        `-CallExpr 0x7fe43a0888a0 <col:11, col:24> 'int'
          |-ImplicitCastExpr 0x7fe43a088888 <col:11> 'int (*)(int, void *, void *)' <FunctionToPointerDecay>
          | `-DeclRefExpr 0x7fe43a0887d8 <col:11> 'int (int, void *, void *)' lvalue Function 0x7fe43a0886f0 'func1' 'int (int, void *, void *)'
          |-IntegerLiteral 0x7fe43a088800 <col:17> 'int' 0
          |-ImplicitCastExpr 0x7fe43a0888e0 <col:20> 'void *' <NullToPointer>
          | `-IntegerLiteral 0x7fe43a088820 <col:20> 'int' 0
          `-ImplicitCastExpr 0x7fe43a0888f8 <col:23> 'void *' <NullToPointer>
            `-IntegerLiteral 0x7fe43a088840 <col:23> 'int' 0
```

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 262698
2016-03-04 08:55:54 +00:00
Sylvestre Ledru 0b027eab7a fix some minor typos in the doc
llvm-svn: 262655
2016-03-03 20:57:16 +00:00
Sylvestre Ledru 4098de4062 Fix two minor syntax issues in the documentation
llvm-svn: 262654
2016-03-03 20:54:26 +00:00
Gabor Horvath 65c02ec837 [clang-tidy] Improve the robustness of a test.
llvm-svn: 262618
2016-03-03 13:43:23 +00:00
Gabor Horvath f4336ac9eb [clang-tidy] Do not emit warnings from misc-suspicious-semicolon when the compilation fails.
llvm-svn: 262615
2016-03-03 13:08:11 +00:00
Alexander Kornienko c1f7f1a31f [docs] Fix docs to work with doxygen 1.8.11
llvm-svn: 262605
2016-03-03 10:45:59 +00:00
Gabor Horvath 577ad5f8b8 [clang-tidy] Documentation fixes.
llvm-svn: 262601
2016-03-03 10:27:32 +00:00
Benjamin Kramer 8f5eb56df3 [clang-tidy] Add "clang-tidy as a clang plugin" skeleton.
This doesn't really do much at the moment. You can load it via libclang
and set the -checks via an extra command line argument as illustrated in
the test case. Support for other options (including headers check) is
currently missing. Also when using this with libclang some checks may
not work with the precompiled preamble in place.

This can be used to easily show clang-tidy warnings in an editor
integration as all that's needed is adding command line flags that are
passed into libclang. Warnings and FixIts are exposed via the existing
CXDiagnostic machinery.

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

llvm-svn: 262595
2016-03-03 08:58:12 +00:00
Haojian Wu 7d08ba2749 [clang-tidy] Fix an assertion failure of "SLocEntry::getExpansion()" when IncludeInserter handles macro header file.
Summary: Also Fixes PR24749.

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 262484
2016-03-02 14:12:17 +00:00
Haojian Wu 1b5b0fd174 [clang-tidy] Make 'modernize-pass-by-value' fix work on header files.
Reviewers: alexfh

Subscribers: jbcoe, cfe-commits

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

llvm-svn: 262470
2016-03-02 09:01:25 +00:00
Hans Wennborg 53bd9f3d7a IdentifierNamingCheck.cpp: try to fix MSVC build
It was failing to build with:

clang-tidy\readability\IdentifierNamingCheck.cpp(640):
error C2882: 'format' : illegal use of namespace identifier in expression

llvm-svn: 262257
2016-02-29 21:17:39 +00:00
Haojian Wu 0d5e9d3135 [clang-tidy] Fix an assertion failure in `modernize-use-nullptr` check.
Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 262024
2016-02-26 15:34:35 +00:00
Alexander Kornienko 5d84978251 [clang-tidy] Minor change in the doc
llvm-svn: 261998
2016-02-26 10:24:29 +00:00
Haojian Wu f7692a2792 [clang-tidy] Fix a crash issue when clang-tidy runs with compilation database.
Summary:
The clang-tidy will trigger an assertion if it's not in the building directory.

TEST:
cd <llvm-repo>/
./build/bin/clang-tidy --checks=-*,modernize-use-nullptr -p build tools/clang/tools/extra/clang-tidy/ClangTidy.cpp

The crash issue is gone after applying this patch.

Fixes PR24834, PR26241

Reviewers: bkramer, alexfh

Subscribers: rizsotto.mailinglist, cfe-commits

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

llvm-svn: 261991
2016-02-26 09:19:33 +00:00
Alexander Kornienko 274220cda2 Remove a blank line at EOF. NFC
llvm-svn: 261940
2016-02-25 23:57:30 +00:00
Alexander Kornienko 1612fa07d3 Add a new check, readability-redundant-string-init, that checks unnecessary string initializations.
Reviewers: hokein, alexfh

Subscribers: cfe-commits

Patch by Shuai Wang!

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

llvm-svn: 261939
2016-02-25 23:57:23 +00:00
NAKAMURA Takumi be16bbc925 Revert r261814, "check-clang-tools: Introduce the feature target-headers", corresponding to r261893.
llvm-svn: 261897
2016-02-25 16:59:59 +00:00
Alexander Kornienko f9c1e2c812 [clang-tidy] Adding headers needed in modernize-deprecated-headers tests
llvm-svn: 261893
2016-02-25 16:46:54 +00:00
Haojian Wu bd63972cff [clang-tidy] update links to Google Code Style in docs
Summary: Because of the recent Google Code shutdown links to the Google Code Style up there are no longer relevant.

Reviewers: alexfh, hokein

Subscribers: cfe-commits

Patch by Kirill Bobyrev!

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

llvm-svn: 261868
2016-02-25 14:31:10 +00:00
NAKAMURA Takumi 8ef4887b15 check-clang-tools: Introduce the feature "target-headers".
For now, it just detects that host is non-Windows and target is msvc.

FIXME: It should be probable for cross compilations. Detect whether target's headers would be available.
llvm-svn: 261814
2016-02-25 01:12:57 +00:00
Alexander Kornienko 4f933376cf [clang-tidy] Another attempt to fix MSVC build
llvm-svn: 261811
2016-02-25 00:39:11 +00:00
Alexander Kornienko 4432e12918 Trying to fix MSVC build
llvm-svn: 261806
2016-02-24 23:48:24 +00:00
Alexander Kornienko e4a75fd896 [clang-tidy] introduce modernize-deprecated-headers check
Summary:
This patch introduces the modernize-deprecated-headers check, which is supposed to replace deprecated C library headers with the C++ STL-ones.

For information see documentation; for exmaples see the test cases.

Reviewers: Eugene.Zelenko, LegalizeAdulthood, alexfh

Subscribers: cfe-commits

Patch by Kirill Bobyrev!

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

llvm-svn: 261738
2016-02-24 13:36:34 +00:00
Alexander Kornienko ea9fd99215 [clang-tidy] Added a check for forward declaration in the potentially wrong namespace
Adds a new check "misc-forward-declaration-namespace".
In check, A forward declaration is considerred in a potentially wrong namespace
if there is any definition/declaration with the same name exists in a different
namespace.

Reviewers: akuegel, hokein, alexfh

Patch by Eric Liu!

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

llvm-svn: 261737
2016-02-24 13:35:32 +00:00
Alexander Kornienko 6bb4b88216 [clang-tidy] Updated docs on testing clang-tidy checks.
llvm-svn: 261622
2016-02-23 09:30:20 +00:00
Aaron Ballman 527a420550 Add a new check, cert-env33-c, that diagnoses uses of system(), popen(), and _popen() to execute a command processor. This check corresponds to the CERT secure coding rule: https://www.securecoding.cert.org/confluence/pages/viewpage.action?pageId=2130132
llvm-svn: 261530
2016-02-22 16:01:06 +00:00
Alexander Kornienko 10f3cf54cb [clang-tidy] Describe modules, link to LLVM development docs, other minor updates
llvm-svn: 261431
2016-02-20 11:42:13 +00:00
Aaron Ballman 611d2e4ee6 Add a new check, cert-flp30-c, that diagnoses loop induction expressions of floating-point type. This check corresponds to the CERT secure coding rule: https://www.securecoding.cert.org/confluence/display/c/FLP30-C.+Do+not+use+floating-point+variables+as+loop+counters
llvm-svn: 261324
2016-02-19 14:03:20 +00:00
Samuel Benzaquen 1fb8bc7a30 [clang-tidy] Match the type against the get() method we are calling,
instead of a get() method we find in the class.

The duck typed smart pointer class could have overloaded get() methods
and we should only skip the one that matches.

llvm-svn: 261102
2016-02-17 16:13:14 +00:00
Haojian Wu 6b4c0b5b66 [clang-tidy] Fix an assert failure in `modernize-loop-convert`.
Summary:
The test code will trigger following an assert failure:

assert.h assertion failed at LoopConvertUtils.cpp:560 in
bool clang::tidy::modernize::ForLoopIndexUseVisitor::TraverseMemberExpr(clang::MemberExpr*): ExprType->isPointerType() && "Operator-> returned non-pointer type"

Reviewers: alexfh

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

llvm-svn: 260953
2016-02-16 10:36:51 +00:00
Haojian Wu 67f880641c [clang-tidy] Fix an assert failure of ForStmt in `readability-braces-around-statements` check.
Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 260952
2016-02-16 10:31:33 +00:00
Alexander Kornienko f8bb8c5891 [clang-tidy] Enhance modernize-redundant-void-arg check to apply fixes to header files
Fixes http://llvm.org/PR25894

Patch by Richard Thomson!

Differential revision: http://reviews.llvm.org/D16953

llvm-svn: 260948
2016-02-16 09:49:05 +00:00
NAKAMURA Takumi 2c2c461e2a clang-tools-extra/test/Unit/lit.site.cfg.in: Prune on_clone. I guess it has been unused since r188006.
llvm-svn: 260944
2016-02-16 08:13:36 +00:00
Sylvestre Ledru 4e89611168 fix an indent issue in the doc which causes sphinx to fail with some versions
llvm-svn: 260912
2016-02-15 20:38:54 +00:00
Felix Berger ffae543b39 [clang-tidy] ClangTidy check to flag uninitialized builtin and pointer fields.
Summary:
This patch is a continuation of http://reviews.llvm.org/D10553 by Jonathan B Coe.

The main additions are:

1. For C++11 the check suggests in-class field initialization as fix. This
makes the fields future proof towards the addition of new constructors.
2 For older language versions the fields are added in the right position
in the initializer list with more tests.
3. User documentation.

Reviewers: alexfh, jbcoe

Subscribers: cfe-commits

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

llvm-svn: 260873
2016-02-15 04:27:56 +00:00
Felix Berger f4fdc8aba0 [clang-tidy] Only invoke ForRangeCopyCheck on expensive-to-copy types.
Summary:
Fix oversight not checking the value of the Optional<bool> returned by
isExpensiveToCopy().

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 260870
2016-02-15 03:36:23 +00:00
Felix Berger 1429412fe3 Improve documentation
llvm-svn: 260869
2016-02-15 03:27:54 +00:00
Samuel Benzaquen 51e1523d70 [clang-tidy] Add check performance-faster-string-find
Summary:
Add check performance-faster-string-find.
It replaces single character string literals to character literals in calls to string::find and friends.

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 260712
2016-02-12 19:28:14 +00:00
Aaron Ballman f034a8c7d7 Reapply r260096.
Expand the simplify boolean expression check to handle implicit conversion of integral types to bool and improve the handling of implicit conversion of member pointers to bool.

Implicit conversion of member pointers are replaced with explicit comparisons to nullptr.

Implicit conversions of integral types are replaced with explicit comparisons to 0.

Patch by Richard Thomson.

llvm-svn: 260681
2016-02-12 15:09:05 +00:00
Daniel Marjamaki 1fba76a3b9 [clang-tidy] Fix failure in 'misc-misplaced-widening-cast' test.
I added portability warnings when int results are casted to long. I forgot to handle uint, ulong and ulonglong.

Tested on x86 and powerpc targets, hope it works now on all buildbots.

llvm-svn: 260667
2016-02-12 09:38:38 +00:00
Daniel Marjamaki 79355776e3 [clang-tidy] improve misc-misplaced-widening-cast so it also detects portability problems.
Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 260665
2016-02-12 07:51:10 +00:00
Alexander Kornienko cf0f0069e7 [clang-tidy] google-runtime-int: fix a false positive in implicit code.
llvm-svn: 260535
2016-02-11 16:22:58 +00:00
Cong Liu fbd0176d6c Merge branch 'arcpatch-D16922'
llvm-svn: 260532
2016-02-11 16:03:27 +00:00
Haojian Wu 60c9316d62 [clang-tidy] Fix an assert failure in 'readability-braces-around-statements' check.
Summary:
The check will trigger a assert failure("CondEndLoc.isValid") when
checking the IfStmt whose condition expression is not parsed.

In this case, we should ignore that.

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 260505
2016-02-11 09:57:55 +00:00
Gabor Horvath 8b6434e56e [clang-tidy] Add a check to find unintended semicolons that changes the semantics.
Reviewers: hokein, alexfh

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

llvm-svn: 260503
2016-02-11 09:23:33 +00:00
Daniel Marjamaki 4d228679df [clang-tidy] Add -target in misc-misplaced-widening-cast test so it will work on various bots
llvm-svn: 260225
2016-02-09 15:43:05 +00:00
Daniel Marjamaki ad3293744a [clang-tidy] Add 'misc-misplaced-widening-cast' check.
Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 260223
2016-02-09 14:08:49 +00:00
Gabor Horvath f7c39d56b6 [clang-tidy] Make readability-container-size-empty work with inline namespaces. Fix PR25812.
llvm-svn: 260217
2016-02-09 10:20:48 +00:00
Gabor Horvath a4fd3beaa2 [clang-tidy] Replace a custom ASTMatcher with a built-in one.
llvm-svn: 260212
2016-02-09 09:26:11 +00:00
Haojian Wu 3d1d076f79 [clang-tidy] Some improvements in 'misc-definitions-in-headers' check.
Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 260108
2016-02-08 16:05:39 +00:00
Haojian Wu 1e3c32b38a [clang-tidy] Fix assertion failure on `at` function in modernize-loop-convert.
Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 260107
2016-02-08 15:59:42 +00:00
Haojian Wu 7a7614757c [clang-tidy] Correct IncorrectRoundings namespace.
Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 260105
2016-02-08 15:54:30 +00:00
Alexander Kornienko c1587dcf4d [clang-tidy] Reshuffled paragraphs a bit, added contents.
llvm-svn: 260100
2016-02-08 15:09:39 +00:00
Alexander Kornienko 7193d9fa95 [clang-tidy] Fix an error in .rst
llvm-svn: 260099
2016-02-08 15:09:34 +00:00
Alexander Kornienko a7faa5b92a [clang-tidy] Update documentation
Summary: We have 2 scripts add_new_check.py and rename_check.py to bootstrap a new check creation. There is also clang-query to aid with the matcher creation. These were not mentioned in the current document, add them so it's available to the masses.

Reviewers: alexfh

Patch by Deniz Türkoglu!

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

llvm-svn: 260098
2016-02-08 15:09:28 +00:00
Aaron Ballman 54391c8ca6 Reverting r260096; it causes build bot failures:
http://bb.pgr.jp/builders/cmake-clang-tools-x86_64-linux/builds/23351
http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/492

llvm-svn: 260097
2016-02-08 14:37:56 +00:00
Aaron Ballman f4490cab0d Expand the simplify boolean expression check to handle implicit conversion of integral types to bool and improve the handling of implicit conversion of member pointers to bool.
Implicit conversion of member pointers are replaced with explicit comparisons to nullptr.

Implicit conversions of integral types are replaced with explicit comparisons to 0.

Patch by Richard Thomson.

llvm-svn: 260096
2016-02-08 14:25:25 +00:00
Haojian Wu 25779e404b [clang-tidy] Move incorrect-roundings to upstream.
Summary: This is originally implemented by Jacques Pienaar.

Reviewers: alexfh

Subscribers: cfe-commits, jpienaar

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

llvm-svn: 260084
2016-02-08 10:16:13 +00:00
Alexander Kornienko f1d54eb222 [clang-tidy] Reformatted docs + minor updates
llvm-svn: 260065
2016-02-08 00:19:29 +00:00
Paul Robinson f868d0b238 Add qualifiers that are about to be necessary. NFC
llvm-svn: 259949
2016-02-05 23:20:02 +00:00
Benjamin Kramer 38b54b82e4 Unbreak the cmake shared build.
llvm-svn: 259880
2016-02-05 11:38:50 +00:00
Haojian Wu c2d7577cc5 [clang-tdiy] Add header file extension configuration support.
Summary: * Add a `HeaderFileExtensions` check option in misc-definitions-in-headers, google-build-namespaces and google-global-names-in-headers.

Reviewers: aaron.ballman, alexfh

Subscribers: cfe-commits

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

llvm-svn: 259879
2016-02-05 11:23:59 +00:00
Haojian Wu 4d67ec3f8c [clang-tidy] More friendly warning in "google-runtime-references" when meeting an unnamed function parameter.
Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 259787
2016-02-04 14:06:49 +00:00
Haojian Wu bbff538e9d [clang-tidy] Fix a crash issue on misc-virtual-near-miss check.
Summary:
The crash is caused by triggering a Assertion failed in DeclCXX.h when the
check detects non-defined class return type in a class method declaration.

Reviewers: congliu, alexfh

Subscribers: cfe-commits

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

llvm-svn: 259668
2016-02-03 17:21:44 +00:00
Haojian Wu 29634fe676 [clang-tidy] bug fix: Don't warn on partial template specialization in `misc-definitions-in-headers` check.
Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 259643
2016-02-03 12:10:27 +00:00
Daniel Jasper 3a6e81c2c1 clang-tidy: [misc-unused-parameters] Ignore template instantiations.
No functional changes intended as we should already do the
corresponding fixes when visiting the primary template. There are
existing tests that verify that we do change unused parameters of
templated functions.

llvm-svn: 259640
2016-02-03 11:33:18 +00:00
Alexander Kornienko abf22eb544 [clang-tidy] Removed unnecessary parameters in the test
llvm-svn: 259531
2016-02-02 17:27:08 +00:00
Alexander Kornienko 26e46d8fae [clang-tidy] Add non-constant references in function parameters check.
Summary: This is implemented originally by Alexander Kornienko.

Reviewers: alexfh

Subscribers: cfe-commits


Patch by Haojian Wu!

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

llvm-svn: 259530
2016-02-02 17:27:01 +00:00
Matthias Braun 48c8426fa2 Fix build problem by lower SmallSet<N> to a reasonable value
llvm-svn: 259424
2016-02-01 22:18:58 +00:00
Eugene Zelenko dde3cd0347 Sort checks alphabetically in ReadabilityTidyModule.cpp.
llvm-svn: 259393
2016-02-01 19:47:24 +00:00
Aaron Ballman c3975b7d6a Add a new check, readability-redundant-control-flow, that check for some forms of redundant control flow statements. Currently checks for return statements at the end of a function with a void return type and continue statements at the end of looping statements.
Patch by Richard Thomson.

llvm-svn: 259362
2016-02-01 15:31:15 +00:00
NAKAMURA Takumi 622f3dcd1d test/clang-tidy/performance-for-range-copy.cpp: Appease for targeting ms mode.
llvm-svn: 259289
2016-01-30 02:15:19 +00:00
Alexander Kornienko d0d8878fb6 [clang-tidy] Don't use delegating constructors, since they are not supported by MSVC 2013
llvm-svn: 259214
2016-01-29 17:35:53 +00:00
Alexander Kornienko 5aebfe2e4a [clang-tidy] ForRangeCopyCheck that warns on and fixes unnecessary copies of loop variables.
Patch by Felix Berger!

Differential revision: http://reviews.llvm.org/D13849

llvm-svn: 259199
2016-01-29 15:54:26 +00:00
Alexander Kornienko bfee5f7352 [clang-tidy] Fix minor style issues. NFC
llvm-svn: 259198
2016-01-29 15:22:20 +00:00
Alexander Kornienko 8ac20a8439 Fixed function params comparison. Updated docs and tests.
Summary: "checkParamTypes" may fail if the the type of some parameter is not canonical. Fixed it by comparing canonical types. And added "getCanonicalType()" and "getCanonicalDecl()" on more places to prevent potential fail.

Reviewers: alexfh

Subscribers: cfe-commits

Patch by Cong Liu!

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

llvm-svn: 259197
2016-01-29 15:22:10 +00:00
Alexander Kornienko 42e8cf4a70 [clang-tidy] Fix style issues. NFC
llvm-svn: 259196
2016-01-29 15:21:43 +00:00
Alexander Kornienko 40d307d120 [clang-tidy] Move implicit-cast-in-loop check to upstream.
Summary: This is implemented originally by Alex Pilkiewicz (pilki@google.com).

Reviewers: alexfh

Subscribers: cfe-commits

Patch by Haojian Wu!

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

llvm-svn: 259195
2016-01-29 15:21:32 +00:00
Hans Wennborg 14bf877e6b docs/conf.py: update copyright year
llvm-svn: 258960
2016-01-27 18:29:16 +00:00
Alexander Kornienko 1b290adc43 [clang-tidy] Fix documentation.
Fixed broken links to cppcoreguidelines (anchors specified in the .md file
should be used, not automatic anchors generated by github).

Fixed formatting, array_view -> span, fixed sphinx errors in
misc-definitions-in-headers.rst.

llvm-svn: 258926
2016-01-27 11:37:19 +00:00
Alexander Kornienko e267dafc13 [clang-tidy] Use relative URL for redirection.
llvm-svn: 258925
2016-01-27 11:37:12 +00:00
Alexander Kornienko ad166f5dcc Add clang-tools-extra documentation to the CMake build.
llvm-svn: 258924
2016-01-27 11:37:08 +00:00
Eugene Zelenko 7da47b8ef5 Fix Clang-tidy modernize-use-override warning in unittests/clang-tidy/IncludeInserterTest.cpp; other minor fixes.
Differential revision: http://reviews.llvm.org/D16566

llvm-svn: 258870
2016-01-26 22:32:24 +00:00
Chris Bieneman 2cc7fec76a Remove autoconf support
Summary:
This patch is provided in preparation for removing autoconf on 1/26. The proposal to remove autoconf on 1/26 was discussed on the llvm-dev thread here: http://lists.llvm.org/pipermail/llvm-dev/2016-January/093875.html

"Now I am become Death, the destroyer of worlds."
-J. Robert Oppenheimer

Reviewers: chandlerc, grosbach, bob.wilson, echristo

Subscribers: cfe-commits, klimek

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

llvm-svn: 258864
2016-01-26 21:31:36 +00:00
Jonathan Coe 2c8592a80f Test commit. Fix typo in comment.
llvm-svn: 258835
2016-01-26 18:55:55 +00:00
Alexander Kornienko dc84150e4f Fix crashing on user-defined conversion.
Summary: Fix the assertion failure for the user-defined conversion method. e.g.: operator bool()

Reviewers: alexfh, aaron.ballman

Subscribers: aaron.ballman, cfe-commits

Patch by Cong Liu!

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

llvm-svn: 258801
2016-01-26 10:56:27 +00:00
Aaron Ballman a5d55a4617 Add support to the misc-assert-side-effect check for MSVC-style assert macros, which use !! instead of an if statement or a conditional operator.
llvm-svn: 258714
2016-01-25 20:00:53 +00:00
Gabor Horvath 93bc576ec9 [clang-tidy] Handle decayed types and other improvements in VirtualNearMiss check.
Handle decayed types, ignore qualifiers and accessibility when considering a
method as a possible overload.

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

llvm-svn: 258562
2016-01-22 21:45:51 +00:00
Aaron Ballman b61829887d Make modernize-use-default tolerant of delayed template parsing; this code was previously causing failed assertions because dyn_cast was being passed a null pointer due to the delay-parsed body.
llvm-svn: 258356
2016-01-20 22:14:10 +00:00
Dimitry Andric d325ab8cb8 Ensure the lit.site.cfg and Unit/lit.site.cfg make targets do not use
the same temporary file, otherwise there is a race condition when using
parallel make jobs.

llvm-svn: 258327
2016-01-20 18:53:44 +00:00
Alexander Kornienko e04dd2525c [clang-tidy] Python scripts shebang fixes
Summary:
This patch fixes shebang lines in Python script files.

Most Python scripts in LLVM & Clang are using this shebang line.

[[ https://mail.python.org/pipermail/tutor/2007-June/054816.html | Here]] is an explanaiton of why such line should be used instead of what is currently in these few files.

Reviewers: klimek, alexfh

Subscribers: cfe-commits

Patch by Kirill Bobyrev!

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

llvm-svn: 258133
2016-01-19 16:10:39 +00:00
Alexander Kornienko 3c95377eb1 [clang-tidy] Fixed wording ("clang-tidy check", not "clang-tidy checker")
llvm-svn: 258098
2016-01-18 22:51:09 +00:00
Alexander Kornienko 33c2494b69 [clang-tidy] Fix a copy-paste error.
llvm-svn: 257900
2016-01-15 16:16:47 +00:00
Jonathan Roelofs d60388a985 Teach clang-tidy how to upgrade warnings into errors.
Similar in format to the `-checks=` argument, this new `-warnings-as-errors=`
argument upgrades any warnings emitted by the former to errors.

http://reviews.llvm.org/D15528

llvm-svn: 257642
2016-01-13 17:36:41 +00:00
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 1b47f38fd5 Add extra tests for handling throw() and noexcept() specifiers.
Patch by Adrian Zgorzałek

llvm-svn: 257522
2016-01-12 21:08:27 +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
Eugene Zelenko 2f5baba613 Fix typo.
llvm-svn: 256780
2016-01-04 21:25:10 +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 1daf4cbc74 [clang-tidy] Fix capitalization of the message in the example
llvm-svn: 256559
2015-12-29 13:28:10 +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
Aaron Ballman 5910a00039 Orphaning these RST files; each one is retained only for link backwards compatibility.
llvm-svn: 256517
2015-12-28 19:59:15 +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 ef064f8ace [clang-tidy] Added documentation for modernize-redundant-void-arg
llvm-svn: 256261
2015-12-22 18:13:00 +00:00
Alexander Kornienko 785e5223d3 [clang-tidy] Updates to documentation: formatting, titles, etc.
llvm-svn: 256259
2015-12-22 17:36:49 +00:00
Alexander Kornienko 677f3fb215 Updated year (2014-2015).
llvm-svn: 256254
2015-12-22 17:10:34 +00:00
Alexander Kornienko b60d291d79 [clang-tools-extra] Text formatting
llvm-svn: 256253
2015-12-22 17:08:57 +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
NAKAMURA Takumi ecba4c3d0b check-clang-tools requires clang-headers due to test/clang-tidy.
clang-modernize provided clang-headers but it was removed.

llvm-svn: 256133
2015-12-21 01:35:28 +00:00
Alexander Kornienko 23f04fd469 Remove clang-modernize.
Summary:
clang-modernize transforms have moved to clang-tidy. Removing
the old tool now.

Reviewers: klimek

Subscribers: cfe-commits

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

llvm-svn: 255886
2015-12-17 11:49:19 +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
NAKAMURA Takumi 7da4299ef3 clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index*.cpp: Don't assume size_t were unsigned int.
llvm-svn: 255475
2015-12-13 22:49:37 +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
John Thompson 442f1b2795 There were problems if a relative path is used for an include path, the path will be normalized to ./xxx. I don't know how to test this in a way that will work in a separated source/output environment, but it seems reasonable to assume that -I options won't be for provate directories.
llvm-svn: 255199
2015-12-10 01:33:09 +00:00
John Thompson b3eef01eda Added coverage check for extensionless headers, and exclude hidden dot directoryies.
llvm-svn: 254785
2015-12-04 22:42:18 +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
John Thompson e557308fb9 Backing out 254635 until I have a good workaround and test case.
llvm-svn: 254756
2015-12-04 19:44:03 +00:00
John Thompson e753fc97ec Fixed header determination logic. Was missing extensionless headers in coverage check.
llvm-svn: 254635
2015-12-03 19:20:43 +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
Matthias Braun 75fe1f0238 Force test to a target that supports thread_local
This should fix darwin bots.

llvm-svn: 254477
2015-12-02 01:12:06 +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
Daniel Jasper 5a59152fd0 Fix test failure introduced by r253859. I believe that the new behavior
in r253859 makes sense in many cases and thus, I have fixed the
implementation of calculateChangedRanges instead. It had a FIXME anyway
saying that it was unecessarily using shiftedCodePosition which
resulted in O(N^2) runtime.

llvm-svn: 253929
2015-11-23 22:28:56 +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
Saleem Abdulrasool 9dc1b0f29d modularize: add install rule
This allows modularize to be installed.  Previously, no install rule would be
created for it.

llvm-svn: 253310
2015-11-17 05:09:18 +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
Aaron Ballman e8607ef204 Rewording some of this documentation to describe the check instead of try to rationalize the behavior of the check. The links already provide sufficient rationale.
llvm-svn: 252496
2015-11-09 18:04:34 +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
Matthias Gehre eeb71758cc [clang-tidy] add new check cppcoreguidelines-pro-type-cstyle-cast
Summary:
This check flags all use of c-style casts that perform a static_cast
downcast, const_cast, or reinterpret_cast.

Use of these casts can violate type safety and cause the program to
access a
variable that is actually of type X to be accessed as if it were of an
unrelated type Z. Note that a C-style (T)expression cast means to
perform
the first of the following that is possible: a const_cast, a
static_cast, a
static_cast followed by a const_cast, a reinterpret_cast, or a
reinterpret_cast followed by a const_cast. This rule bans (T)expression
only when used to perform an unsafe cast.

This rule is part of the "Type safety" profile of the C++ Core
Guidelines, see
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-type4-dont-use-c-style-texpression-casts-that-would-perform-a-static_cast-downcast-const_cast-or-reinterpret_cast.

Reviewers: alexfh, sbenza, bkramer, aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 252425
2015-11-08 21:10:39 +00:00
Angel Garcia Gomez 2c19d4cee3 Allow the alias to be of a different type.
Summary: Consider a declaration an alias even if it doesn't have the same unqualified type than the container element, as long as one can be converted to the other using only implicit casts.

Reviewers: klimek

Subscribers: alexfh, cfe-commits

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

llvm-svn: 252315
2015-11-06 15:47:04 +00:00
Angel Garcia Gomez 7056f7488f Use the old index identifier by default, instead of 'elem'.
Summary: Use the old index name in the cases where the check would come up with an invented name.

Reviewers: klimek

Subscribers: cfe-commits

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

llvm-svn: 252308
2015-11-06 15:03:14 +00:00
Angel Garcia Gomez 7e1d4ae937 Avoid naming conflicts with the old index in modernize-loop-convert.
Summary: The old index declaration is going to be removed anyway, so we can reuse its name if it is the best candidate for the new index.

Reviewers: klimek

Subscribers: cfe-commits, alexfh

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

llvm-svn: 252303
2015-11-06 14:04:12 +00:00
Angel Garcia Gomez 7856ad0bcc Fix another case where loop-convert wasn't handling correctly data members.
Summary:
If the container expression was obtained from the point where "size" (which usually is a const method) is invoked, then the topmost node in this expression may be an implicit cast to const.

When the container is a data member, the check was trying to obtain the member expression directly and was failing in the case mentioned above. This is solved by ignoring implicit casts.

Reviewers: klimek

Subscribers: cfe-commits, alexfh

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

llvm-svn: 252278
2015-11-06 09:59:14 +00:00
Alexander Kornienko 272397b42e [clang-tidy] readability-named-parameter: don't complain about implicit parameters
Fixes http://llvm.org/PR24464.

llvm-svn: 252248
2015-11-06 00:19:21 +00:00
Alexander Kornienko 3b7df53d04 Refactor: Simplify boolean conditional return statements in clang-apply-replacements
Differential revision: http://reviews.llvm.org/D10025

Patch by Richard Thomson!

llvm-svn: 252207
2015-11-05 20:59:17 +00:00
Alexander Kornienko 0caf6dadce Accommodate interface change in r252134.
llvm-svn: 252138
2015-11-05 02:30:21 +00:00
Angel Garcia Gomez 3d7d922832 Improve modernize-make-unique matcher.
Summary: "std::unique_ptr<int>" is not the same type as "std::unique_ptr<int, std::default_delete<int>>", unless we insert a "hasCanonicalType" in the middle. Probably it also happens in other cases related to default template argument.

Reviewers: klimek

Subscribers: alexfh, cfe-commits

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

llvm-svn: 252041
2015-11-04 10:27:51 +00:00
Angel Garcia Gomez 432ff5e205 Handle correctly containers that are data members in modernize-loop-convert.
Summary:
I recently found that the variable naming wasn't working as expected with containers that are data members. The new index always received the name "Elem" (or equivalent) regardless of the container's name.
The check was assuming that the container's declaration was a VarDecl, which cannot be converted to a FieldDecl (a data member), and then it could never retrieve its name.

This also fixes some cases where the check failed to find the container at all (so it didn't do any fix) because of the same reason.

Reviewers: klimek

Subscribers: cfe-commits, alexfh

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

llvm-svn: 251943
2015-11-03 16:38:31 +00:00
Angel Garcia Gomez 5b5c94ba2c Improve more the const-detection in modernize-loop-convert.
Summary: The previous change was focused in detecting when a non-const object was used in a constant way. Looks like I forgot the most important and trivial case: when the object is already constant. Failing to detect this cases results in compile errors, due to trying to bind a constant object to a non-const reference in the range-for statement. This change should fix that.

Reviewers: klimek

Subscribers: alexfh, cfe-commits

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

llvm-svn: 251940
2015-11-03 16:31:36 +00:00
Angel Garcia Gomez 5daa9b231f Make the modernize-loop-convert's const-detection smarter.
Summary:
Now, it detects that several kinds of usages are can't modify the elements. Examples:
-When an usage is a call to a const member function or operator of the element.
-If the element is used as an argument to a function or constructor that takes a const-reference or a value.
-LValue to RValue conversion, if the element is a fundamental type (which allows the use of most of the builtin operators).

Reviewers: klimek

Subscribers: cfe-commits, alexfh

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

llvm-svn: 251808
2015-11-02 17:02:52 +00:00
Angel Garcia Gomez ff11a44fe0 Fix another crash in the redundant-void-arg check.
Summary: The check was assuming that a definition of a function always has a body, but a declaration that explicitly defaults or deletes a function is a definition too.

Reviewers: alexfh

Subscribers: klimek, cfe-commits

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

llvm-svn: 251807
2015-11-02 16:18:23 +00:00
Angel Garcia Gomez dc39f313e2 Remove unreachable that was reached in modernize-use-nullptr.
Summary: When traversing the parent map, the check assumed that all the nodes would be either Stmt or Decl. After r251101, this is no longer true: there can be TypeLoc and NestedNameSpecifierLoc nodes.

Reviewers: alexfh

Subscribers: klimek, cfe-commits

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

llvm-svn: 251803
2015-11-02 15:28:06 +00:00
Angel Garcia Gomez dd4ed3af98 Fix crash in redundant-void-arg check.
Summary:
When applying this check to the unit tests, it would hit an assertion:
llvm/tools/clang/lib/Lex/Lexer.cpp:1056: clang::SourceLocation clang::Lexer::getSourceLocation(const char*, unsigned int) const: Assertion `PP && "This doesn't work on raw lexers"' failed.

Reviewers: klimek, LegalizeAdulthood, alexfh

Subscribers: cfe-commits, alexfh

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

llvm-svn: 251792
2015-11-02 11:39:17 +00:00
Angel Garcia Gomez 184864adc6 Try to fix buildbots failure.
Summary: Add -fexceptions flag to enable exceptions.

Subscribers: cfe-commits

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

llvm-svn: 251790
2015-11-02 10:54:50 +00:00
Angel Garcia Gomez f2bc2f001a modernize-use-default supports copy constructor and copy-assignment operator.
Summary: the check will now warn when the user provided definitions of this functions is equivalent to the explicitly defaulted ones.

Reviewers: klimek

Subscribers: klimek, cfe-commits, alexfh

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

llvm-svn: 251788
2015-11-02 10:34:19 +00:00
Angel Garcia Gomez 68175a02fb Only copy small types in modernize-loop-convert.
Summary: If the size of the type is above a certain bound, we'll take a const reference. This bound can be set as an option. For now, the default value is 16 bytes.

Reviewers: klimek

Subscribers: alexfh, cfe-commits

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

llvm-svn: 251694
2015-10-30 09:37:57 +00:00
Daniel Jasper 15cffc00b3 Change test to just define NULL instead of #including stddef.h. In some
test environments, even that builtin header isn't available. Also, this
makes it more consistent with the C++ version of this test.

llvm-svn: 251520
2015-10-28 14:51:09 +00:00
NAKAMURA Takumi 257fc92826 clang-tools-extra/test/clang-tidy/modernize-redundant-void-arg.c: Use <stddef.h> provided by clang, instead of <stdio.h>.
llvm-svn: 251503
2015-10-28 09:22:21 +00:00
Benjamin Kramer e18da83bcc [tidy] Remove stray iostream include from test.
It is unused and we cannot rely on standard headers being present while
executing tests.

llvm-svn: 251499
2015-10-28 05:16:37 +00:00