According to
https://wiki.sei.cmu.edu/confluence/display/cplusplus/CON54-CPP.+Wrap+functions+that+can+spuriously+wake+up+in+a+loop
and
https://wiki.sei.cmu.edu/confluence/display/c/CON36-C.+Wrap+functions+that+can+spuriously+wake+up+in+a+loop
misc-spuriously-wake-up-functions check is created. The check finds
cnd_wait or wait function calls in an IfStmt and warns the user to
replace it with a WhileStmt or use it with a lambda parameter.
Details
Diff Detail
- Repository
- rCTE Clang Tools Extra
Event Timeline
I don't think that misc module should be used when checks belong to cert
clang-tools-extra/clang-tidy/misc/SpuriouslyWakeUpFunctionsCheck.cpp | ||
---|---|---|
77 ↗ | (On Diff #231616) | Unnecessary empty line. |
clang-tools-extra/docs/ReleaseNotes.rst | ||
70 | Please move into aliases section (in alphabetical order). Same below. | |
135 | Please use alphabetical order. | |
138 | Please synchronize with first statement in documentation. | |
clang-tools-extra/test/clang-tidy/misc-spuriously-wake-up-functions.cpp | ||
1 ↗ | (On Diff #231616) | What will happen if libcxx is not part build/source tree? |
clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp | ||
---|---|---|
45–46 ↗ | (On Diff #231616) | If we want to expose this check outside of the CERT module, I think it should go into bugprone rather than misc. |
clang-tools-extra/clang-tidy/misc/SpuriouslyWakeUpFunctionsCheck.cpp | ||
62 ↗ | (On Diff #231616) | What about cnd_timedwait? |
clang-tools-extra/clang-tidy/misc/SpuriouslyWakeUpFunctionsCheck.h | ||
19 ↗ | (On Diff #231616) | WhileStm -> WhileStmt |
clang-tools-extra/test/clang-tidy/misc-spuriously-wake-up-functions.cpp | ||
1 ↗ | (On Diff #231616) | Also, there are no tests for the C functionality yet. |
Checker is moved to bugprone section, tests added. C checker is improved, and documentations are synchronised.
clang-tools-extra/docs/clang-tidy/checks/bugprone-spuriously-wake-up-functions.rst | ||
---|---|---|
5 | Please make length same as in title. |
The checks.rst has recently been updated to show "normal" (main entry) checks and "aliases" in different tables in D36051. Please register the alias-ness accordingly.
clang-tools-extra/docs/clang-tidy/checks/list.rst | ||
---|---|---|
12 | Could you try to evaluate the severity? :) |
clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp | ||
---|---|---|
23 | These should all use ::std::whatever to guard against pathological code that uses std inside of another namespace. | |
81 | This should be simplified into: const auto *MatchedWait = Result.Nodes.getNodeAs<CallExpr>("wait"); StringRef WaitName = MatchedWait->getDirectCallee()->getName(); diag(MatchedWait->getExprLoc(), "'%0' should be placed inside a while statement %select{|or used with a conditional parameter}1") << WaitName << (WaitName != "cnd_wait" && WaitName != cnd_timedwait); | |
clang-tools-extra/docs/clang-tidy/checks/bugprone-spuriously-wake-up-functions.rst | ||
7 | Missing cnd_timedwait | |
clang-tools-extra/test/clang-tidy/Inputs/bugprone-spuriously-wake-up-functions/chrono.h | ||
49 ↗ | (On Diff #235232) | Please add a newline to the end of the file. |
clang-tools-extra/test/clang-tidy/Inputs/bugprone-spuriously-wake-up-functions/condition_variable.h | ||
41 ↗ | (On Diff #235232) | Please add a newline to the end of the file. |
clang-tools-extra/test/clang-tidy/Inputs/bugprone-spuriously-wake-up-functions/cstdint.h | ||
4 ↗ | (On Diff #235232) | Please add a newline to the end of the file. |
clang-tools-extra/test/clang-tidy/Inputs/bugprone-spuriously-wake-up-functions/mutex.h | ||
20 ↗ | (On Diff #235232) | Please add a newline to the end of the file. |
clang-tools-extra/test/clang-tidy/Inputs/bugprone-spuriously-wake-up-functions/ratio.h | ||
29 ↗ | (On Diff #235232) | Please add a newline to the end of the file. |
clang-tools-extra/test/clang-tidy/bugprone-spuriously-wake-up-functions.cpp | ||
3 | Are you planning to use these declarations in multiple test files? If not, then we typically put all of the header code into the test file rather than added as explicit files. | |
100 | You are missing test cases that use other kinds of loops, like a do..while or for loop. |
clang-tools-extra/test/clang-tidy/bugprone-spuriously-wake-up-functions.cpp | ||
---|---|---|
3 | I'm not sure yet, so I move it into the test file. |
Checker fixes, updates test file adding test cases for doWhile and for statements, test headers deleted.
clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp | ||
---|---|---|
61 | Sorry for not noticing this earlier, but I think you can make two calls to addMatcher(), one for the C check and one for the C++ check. Then you can register only the matcher needed for the language mode you are currently in. e.g., if (getLangOpts().CPlusPlus) // Check for CON54-CPP else // Check for CON36-C This should make the check slightly more efficient because of the mutually exclusive nature of these APIs without changing the behavior. | |
clang-tools-extra/docs/clang-tidy/checks/list.rst | ||
12 | Given that these are essentially CERT rules, I'd go with the CERT severity for them -- however, I say that only because I'm not certain what approach is supposed to be taken for these severity markings. CERT marks these two rules as having a low severity, FWIW. |
clang-tools-extra/docs/clang-tidy/checks/list.rst | ||
---|---|---|
300–301 | In case the checker does not offer automatic fixes, remove "Yes" from the given table entries. |
LGTM aside from a test coverage request.
clang-tools-extra/test/clang-tidy/bugprone-spuriously-wake-up-functions.c | ||
---|---|---|
26–30 | Can you add a test case to demonstrate the behavior when there's not a compound statement involved? And another one for a slightly more complex if predicate? e.g., if (list_c.next == NULL) if (0 != cnd_wait(&condition_c, &lock)) ; if (list_c.next == NULL && 0 != cnd_wait(&condition_c, &lock)) ; Both of these should be flagged similar to the form with the compound statement. |
LGTM, do you need me to commit on your behalf?
clang-tools-extra/test/clang-tidy/bugprone-spuriously-wake-up-functions.c | ||
---|---|---|
87 | Please add a newline to the end of the file. |
These should all use ::std::whatever to guard against pathological code that uses std inside of another namespace.