This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] add checks to bugprone-posix-return
ClosedPublic

Authored by jcai19 on Aug 22 2019, 5:56 PM.

Details

Summary

This check now also checks if any calls to pthread_* functions expect negative return values. These functions return either 0 on success or an errno on failure, which is positive only.

Event Timeline

jcai19 created this revision.Aug 22 2019, 5:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 22 2019, 5:56 PM
Eugene.Zelenko added inline comments.
clang-tools-extra/clang-tidy/bugprone/PthreadReturnCheck.cpp
1 ↗(On Diff #216748)

Please make it single line, 80 characters long.

23 ↗(On Diff #216748)

You could use const auto * here, because type is spelled in same statement.

clang-tools-extra/clang-tidy/bugprone/PthreadReturnCheck.h
1 ↗(On Diff #216748)

Please make line 80 characters long.

clang-tools-extra/docs/ReleaseNotes.rst
88

Please keep new checks list sorted alphabetically.

jcai19 updated this revision to Diff 216765.Aug 22 2019, 9:16 PM

Fix format.

Eugene.Zelenko added inline comments.Aug 22 2019, 9:54 PM
clang-tools-extra/clang-tidy/bugprone/PthreadReturnCheck.cpp
1 ↗(On Diff #216765)

Please put space after clang-tidy. Same in header.

2 ↗(On Diff #216765)

Please remove this line.

jcai19 updated this revision to Diff 216768.Aug 22 2019, 10:01 PM

Fix typos.

jcai19 marked 7 inline comments as done.Aug 22 2019, 10:04 PM
jcai19 added inline comments.
clang-tools-extra/clang-tidy/bugprone/PthreadReturnCheck.cpp
2 ↗(On Diff #216765)

Good catch! Thanks.

Thanks for the contribution! In abstract, I think it is a good checker, however, the implementation largely duplicates clang-tidy/bugprone/PosixReturnCheck.cpp -- do you think you could factor out the common parts? I see at least two ways:

  • Factor out a library, use it in both checkers.
  • Put everything into one checker, if necessary, add configuration options to turn on/off POSIX and PThread parts. However, I don't even think configuration options would be necessary -- it is unlikely that someone would want one but not the other -- or is there a use case?
clang-tools-extra/test/clang-tidy/bugprone-pthread-return.cpp
101 ↗(On Diff #216768)

It does not seem like most of these functions are used in the test below. Could you leave only representative functions for each case in the code?

jcai19 marked an inline comment as done.Aug 26 2019, 10:28 AM

Thanks for the contribution! In abstract, I think it is a good checker, however, the implementation largely duplicates clang-tidy/bugprone/PosixReturnCheck.cpp -- do you think you could factor out the common parts? I see at least two ways:

  • Factor out a library, use it in both checkers.
  • Put everything into one checker, if necessary, add configuration options to turn on/off POSIX and PThread parts. However, I don't even think configuration options would be necessary -- it is unlikely that someone would want one but not the other -- or is there a use case?

That's a good suggestion. I will try to combine it with POSIX check. Thanks!

jcai19 updated this revision to Diff 217231.Aug 26 2019, 1:34 PM

Add pthread function calls return values check to bugprone-posix-return.

jcai19 retitled this revision from [clang-tidy] new check: bugprone-pthread-return to [clang-tidy] add checks to bugprone-posix-return.Aug 26 2019, 1:35 PM
jcai19 edited the summary of this revision. (Show Details)

It'll be reasonable to mention changes in Release Notes and check documentation.

jcai19 updated this revision to Diff 217236.Aug 26 2019, 1:58 PM

Update Release Notes and check documentation.

jcai19 edited the summary of this revision. (Show Details)Aug 26 2019, 1:59 PM
Eugene.Zelenko added inline comments.Aug 26 2019, 2:05 PM
clang-tools-extra/docs/ReleaseNotes.rst
70

Check is not new, just modified. Such check should be after new checks.

71

Please insert empty line below.

72

Please omit This check. Please enclose pthread_* in double back-ticks.

clang-tools-extra/docs/clang-tidy/checks/bugprone-posix-return.rst
6–8

Please enclose pthread_* and posix_* in double back-ticks.

gribozavr accepted this revision.Aug 27 2019, 4:05 AM

LGTM with all comments addressed.

clang-tools-extra/test/clang-tidy/bugprone-posix-return.cpp
169

Maybe pick a simpler function for this test, like pthread_yield?

191

Ditto, pthread_yield would be simpler to declare.

This revision is now accepted and ready to land.Aug 27 2019, 4:05 AM
jcai19 updated this revision to Diff 217532.Aug 27 2019, 4:49 PM

Fix format and test cases.

jcai19 marked 3 inline comments as done.Aug 27 2019, 4:50 PM
jcai19 added inline comments.
clang-tools-extra/docs/ReleaseNotes.rst
70

Is Modified the right keyword for modification? Thanks

gribozavr accepted this revision.Aug 28 2019, 1:13 AM
gribozavr added inline comments.
clang-tools-extra/docs/ReleaseNotes.rst
70

I'd say "improved" instead of modified.

jcai19 updated this revision to Diff 220393.Sep 16 2019, 2:40 PM

Thanks for the confirmation!

jcai19 closed this revision.Sep 16 2019, 3:29 PM