This is an archive of the discontinued LLVM Phabricator instance.

Extend the check to detect patterns like 'ptr.get() == nullptr'
ClosedPublic

Authored by sbenza on Apr 4 2014, 1:07 PM.

Details

Summary

Extend the check to detect patterns like 'ptr.get() == nullptr'
It detects == and != when any argument is a ptr.get() and the other is a
nullptr.
Only supports standard smart pointer types std::unique_ptr and std::shared_ptr.
Does not support the case 'ptr.get() == other.get()' yet.

Diff Detail

Event Timeline

klimek added inline comments.Apr 5 2014, 11:27 AM
clang-tidy/misc/RedundantSmartptrGet.cpp
60

There might be a missing test here (s/shard/shared/)

klimek added inline comments.Apr 5 2014, 11:46 AM
clang-tidy/misc/RedundantSmartptrGet.cpp
60

Trying again to see whether the mail gets through...

klimek added inline comments.Apr 5 2014, 11:54 AM
clang-tidy/misc/RedundantSmartptrGet.cpp
60

And trying again...

klimek added inline comments.Apr 5 2014, 12:36 PM
clang-tidy/misc/RedundantSmartptrGet.cpp
60

Yet another try...

klimek added inline comments.Apr 5 2014, 12:41 PM
clang-tidy/misc/RedundantSmartptrGet.cpp
60

And again...

klimek added inline comments.Apr 5 2014, 12:43 PM
clang-tidy/misc/RedundantSmartptrGet.cpp
60

And finally...

Ok, very sorry for having hijacked this thread... It should all work now, and I'll let you be... :)

sbenza updated this revision to Unknown Object (????).Apr 7 2014, 9:29 AM

Fixed the typo on shared_ptr and added a shared_ptr to the test.

Fixed the -fix.cpp test to actually check the output.
FileCheck can match the CHECK: lines with themselves if you don't remove them from the input.

sbenza updated this revision to Unknown Object (????).Apr 7 2014, 2:38 PM

Move the checking logic into shell scripts.
The test will now have one only RUN: line calling the appropriate script.

djasper accepted this revision.Apr 8 2014, 1:49 AM

Two minor comments, otherwise looks good!

clang-tidy/misc/RedundantSmartptrGet.cpp
81

Always add a line break after the "if (...)" in LLVM style.

test/clang-tidy/check_clang_tidy_fix.sh
4

I think with this we can get rid of the unit tests entirely. (I will prepare a follow up patch).

Nice!

test/clang-tidy/check_clang_tidy_output.sh
12

Also set --disable_checks=''.

And same in the other wrapper script.

(I think we might also want to change how those flags behave, but until then, this is the right thing to do..)

djasper added inline comments.Apr 8 2014, 2:00 AM
test/clang-tidy/check_clang_tidy_output.sh
12

-disable-checks that is..

alexfh added a comment.Apr 8 2014, 6:28 AM

Another couple of notes, otherwise looks good!

test/clang-tidy/check_clang_tidy_output.sh
11

Why not use static compilation database instead of generating compile_commands.json?

clang-tidy -checks=${CHECK_TO_RUN} ${INPUT_FILE} -- -std=c++11 | FileCheck ${INPUT_FILE}
13

This being on a line of its own without indentation looks confusing. Could you put the whole pipeline on a single line or use indentation here (and put the pipe on the next line)?

clang-tidy ... \
  | FileCheck ...
sbenza updated this revision to Unknown Object (????).Apr 8 2014, 6:56 AM

Simplify testing scripts.

test/clang-tidy/check_clang_tidy_fix.sh
4

?!?

test/clang-tidy/check_clang_tidy_output.sh
11

Even better. I got rid of that script.

13

Fixed.
Where is sh-format when you need it? =)

alexfh added a comment.Apr 8 2014, 7:20 AM

Thanks! Another couple of comments, though.

test/clang-tidy/check_clang_tidy_fix.sh
10

I'd leave the grep as it was in the test, so that it filters out RUN: lines as well, and it only filters out comments:

grep -Ev "// *[A-Z-]+:" ...

We'll have some checks for comments, so filtering out special comments can be important there.

test/clang-tidy/check_clang_tidy_output.sh
9

nit: I'd format this still a bit differently (where's my sh-format? ;), four spaces on the continuation line, and each pipe component from a new line with 2 spaces indentation:

clang-tidy --checks=${CHECK_TO_RUN} --disable-checks="" ${INPUT_FILE} \
    -- --std=c++11 \
  | FileCheck ${INPUT_FILE}
sbenza updated this revision to Unknown Object (????).Apr 8 2014, 8:48 AM

Minor fix on scripts.

test/clang-tidy/check_clang_tidy_fix.sh
10

Done.

test/clang-tidy/check_clang_tidy_output.sh
9

Done.

sbenza closed this revision.Apr 17 2014, 7:26 AM

Submitted as rL205854