Commit Graph

1403 Commits

Author SHA1 Message Date
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