Граф коммитов

679 Коммитов

Автор SHA1 Сообщение Дата
Etienne Bergeron ca213c19ef [clang-tidy] New checker to detect suspicious string constructor.
Summary:
Checker to validate string constructor parameters.

A common mistake is to swap parameter for the fill-constructor.
```
  std::string str('x', 4);
  std::string str('4', x);
```

Reviewers: alexfh

Subscribers: cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@267011 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-21 17:28:08 +00:00
Etienne Bergeron ce3ece373a [clang-tidy] Add new checker for comparison with runtime string functions.
Summary:
This checker is validating suspicious usage of string compare functions.

Example:
```
  if (strcmp(...))       // Implicitly compare to zero
  if (!strcmp(...))      // Won't warn
  if (strcmp(...) != 0)  // Won't warn
```

This patch was checked over large amount of code.
There is three checks:
  [*] Implicit comparator to zero (coding-style, many warnings found),
  [*] Suspicious implicit cast to non-integral (bugs!?, almost none found),
  [*] Comparison to suspicious constant (bugs!?, found two cases),

Example:
[[https://github.com/kylepjohnson/sigma/blob/master/sigma/native-installers/debian/dependencies/files/opt/sigma/E/HEURISTICS/che_to_precgen.c |
https://github.com/kylepjohnson/sigma/blob/master/sigma/native-installers/debian/dependencies/files/opt/sigma/E/HEURISTICS/che_to_precgen.c]]

```
      else if(strcmp(id, "select") == 0)
      {
         array->array[i].key1 = 25;
      }
      else if(strcmp(id, "sk") == 28)      // BUG!?
      {
         array->array[i].key1 = 20;
      }
```

Reviewers: alexfh

Subscribers: Eugene.Zelenko, cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@267009 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-21 17:19:36 +00:00
Alexander Kornienko d1f3b6cd34 [Clang-tidy] Fix for crash in modernize-raw-string-literal check
Summary:
Clang-tidy modernize-raw-string-literal check crashes on run-time assert while it is evaluating compiler predefined identifiers such as
- __FUNCTION__
- __func__
- __PRETTY_FUNCTION__

Check is asserting because it cannot find opening quote for such string literal. It occurs only on debug build config.
I think that it would be good to prune such cases by crossing off predefined expressions - there is no need to evaluate such matches.

Reviewers: LegalizeAdulthood, alexfh

Subscribers: cfe-commits

Patch by Marek Jenda!

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


git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@266992 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-21 14:39:12 +00:00
Daniel Jasper 92463f0dfd clang-tidy: [misc-unused-using-decls] Support template types.
This fixes llvm.org/PR27429.

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@266866 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-20 09:48:56 +00:00
Daniel Jasper a2a9da6a86 clang-tidy: [misc-unused-using-decls] Always use the canonical decl to
identify things.

This fixes llvm.org/PR27430.

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@266864 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-20 08:58:27 +00:00
Haojian Wu 633d674362 Fix a crash in cppcoreguidelines-pro-type-member-init related to missing constructor bodies.
Summary: Fixes a crash in cppcoreguidelines-pro-type-member-init when checking some record types with a constructor without a body. We now check to make sure the constructor has a body before looking for missing members and base initializers.

Patch by Michael Miller!

Reviewers: aaron.ballman, alexfh, hokein

Subscribers: cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@266862 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-20 08:29:08 +00:00
Daniel Jasper 8180dc9d49 Initial version of misc-unused-using-decl check.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@266735 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-19 13:48:39 +00:00
Gabor Horvath 9bd1811d94 [clang-tidy] readability-container-size-empty fixes
Summary: This patch fixes PR27410 and adds std::basic_string support.

Reviewers: Eugene.Zelenko, hokein

Subscribers: cfe-commits, o.gyorgy

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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@266734 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-19 13:29:05 +00:00
Alex Denisov 5778510702 Replace hardcoded comment at 'lit.site.cfg.in'
At the moment almost every lit.site.cfg.in contains two lines comment:

  ## Autogenerated by LLVM/Clang configuration.
  # Do not edit!

The patch adds variable LIT_SITE_CFG_IN_HEADER, that is replaced from
configure_lit_site_cfg with the note and some useful information.



git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@266518 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-16 07:01:42 +00:00
Etienne Bergeron 23b204f158 [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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@266463 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-15 18:12:06 +00:00
Etienne Bergeron d6190242c5 [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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@266451 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-15 16:36:00 +00:00
Etienne Bergeron 711e3726a2 [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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@266450 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-15 16:31:15 +00:00
Samuel Benzaquen 655a621d59 [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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@266369 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-14 21:15:57 +00:00
Aaron Ballman 077a73a808 Add support for type aliases to modernize-redundant-void-arg.cpp
Patch by Clement Courbet.

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@266358 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-14 19:28:13 +00:00
NAKAMURA Takumi 4b3c21a4b2 clang-tools-extra/test/clang-tidy/readability-deleted-default.cpp: Add -fno-ms-compatibility.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@266265 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-13 23:50:45 +00:00
Alexander Kornienko 9c1474b46a 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


git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@266191 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-13 11:35:47 +00:00
Alexander Kornienko d6f8bcc515 [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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@266190 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-13 11:33:40 +00:00
Matthias Gehre 75181d5ed0 [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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@266044 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-12 05:45:13 +00:00
Alexander Kornienko a919b26e5b [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


git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@265774 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-08 09:51:06 +00:00
Etienne Bergeron 56faca0155 [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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@265691 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-07 16:16:36 +00:00
Etienne Bergeron b71a7415f3 [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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@265681 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-07 14:58:13 +00:00
Benjamin Kramer 4504868168 [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.

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@265680 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-07 14:55:25 +00:00
Etienne Bergeron d374c078bb [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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@265671 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-07 14:18:53 +00:00
Gabor Horvath 8eff102854 [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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@265532 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-06 12:04:51 +00:00
Haojian Wu f290123d76 [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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@265384 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-05 11:42:08 +00:00
Etienne Bergeron 623c3e8671 [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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@265303 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-04 15:46:38 +00:00
Alexander Kornienko 92258c7d86 [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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@265298 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-04 14:31:36 +00:00
Alexander Kornienko a1c0200a84 [clang-tidy] Update an example. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@265210 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-02 03:44:23 +00:00
Haojian Wu 87fb19b74e [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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@265117 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-01 07:57:30 +00:00
Etienne Bergeron 5e64620bd6 [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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@265033 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-31 18:12:23 +00:00
Alexander Kornienko a1f0b8e1a7 [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


git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@264856 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-30 11:31:33 +00:00
Samuel Benzaquen 2f39d0198a [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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@264759 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-29 18:02:26 +00:00
Felix Berger 4e74ed232a [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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@264694 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-29 02:42:38 +00:00
Richard Thomson 3b802fd369 clang-tidy: Fix broken buildbot
VS 2013 does not support char16_t or char32_t


git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@264563 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-28 04:15:41 +00:00
Richard Thomson 84d0739c7f clang-tidy: Add check modernize-raw-string-literal
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@264539 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-27 16:43:44 +00:00
NAKAMURA Takumi fe52e10c17 3rd attempt of fixup with -std=c++11
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@264367 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-25 00:24:35 +00:00
NAKAMURA Takumi 07d1d87aa6 Fixup -- "-target x86_64-unknown -fno-ms-compatibility" didn't work as expected.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@264365 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-25 00:16:13 +00:00
NAKAMURA Takumi 37a03dbab7 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.

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@264362 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-25 00:05:33 +00:00
Etienne Bergeron 18c46d063a [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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@264325 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-24 19:42:36 +00:00
Gabor Horvath df5cd1802d [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


git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@264251 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-24 10:12:08 +00:00
Haojian Wu 82eed71a11 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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@264146 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-23 09:33:07 +00:00
Etienne Bergeron 6e4459e075 [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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@264080 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-22 18:21:17 +00:00
Etienne Bergeron 6fdb0e65ca [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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@264075 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-22 18:00:13 +00:00
Etienne Bergeron 091a31e221 [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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@264073 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-22 17:51:27 +00:00
Etienne Bergeron e013eabc87 [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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@264069 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-22 17:39:36 +00:00
Aaron Ballman 732f733733 Moving files that were placed in the wrong directory from r264049.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@264050 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-22 13:44:36 +00:00
John Thompson 345b712b47 Fixed some cases in the modularize assistant mode where header file names didn't translate to valid module names.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@264001 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-21 23:05:14 +00:00
Samuel Benzaquen 9c31a56df6 [clang-tidy] Fix check broken in rL263822.
Add names missing from rL263822 and add tests to prevent future omissions.

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@263963 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-21 18:00:43 +00:00
Haojian Wu b0ef8495f2 [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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@263426 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-14 12:41:24 +00:00
Haojian Wu 2320d4372a [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

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@263221 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-11 11:40:08 +00:00