According to
https://wiki.sei.cmu.edu/confluence/display/c/POS44-C.+Do+not+use+signals+to+terminate+threads
misc-signal-terminated-thread check is created. The check warn if
pthread_kill function is called with SIGTERM signal.
Details
- Reviewers
aaron.ballman alexfh hokein jfb
Diff Detail
- Repository
- rCTE Clang Tools Extra
Event Timeline
clang-tools-extra/clang-tidy/misc/BadSignalToKillThreadCheck.cpp | ||
---|---|---|
28 ↗ | (On Diff #225641) | static is enough, no need for anonymous namespace. |
33 ↗ | (On Diff #225641) | Unnecessary empty line. |
37 ↗ | (On Diff #225641) | Please don't use auto unless type is spelled in same statement or iterator. |
67 ↗ | (On Diff #225641) | Please add new line. |
clang-tools-extra/clang-tidy/misc/BadSignalToKillThreadCheck.h | ||
40 ↗ | (On Diff #225641) | Please add new line. |
clang-tools-extra/docs/ReleaseNotes.rst | ||
82 | Please keep alphabetical order in new checks list. | |
85 | Please synchronize with first sentence in documentation. Link belongs to documentation. | |
clang-tools-extra/docs/clang-tidy/checks/misc-bad-signal-to-kill-thread.rst | ||
8 ↗ | (On Diff #225641) | Please separate with empty line. |
11 ↗ | (On Diff #225641) | Please add new line. |
clang-tools-extra/test/clang-tidy/misc-bad-signal-to-kill-thread.cpp | ||
31 ↗ | (On Diff #225641) | Please add new line. |
clang-tools-extra/clang-tidy/misc/BadSignalToKillThreadCheck.cpp | ||
---|---|---|
34–48 ↗ | (On Diff #225641) | I think using while loop here makes this less readable compared to using an algorithm like llvm::find_if. I think a more declarative approach would help here.
Like.: const auto IsSigterm = [](const auto &KeyValue) -> bool { return KeyValue.first->getName() == "SIGTERM"; }; const auto TryExpandAsInteger = [PP = PP](Preprocessor::macro_iterator It) -> Optional<unsigned> { if (It == PP->macro_end()) return llvm::None; const MacroInfo *MI = PP->getMacroInfo(It->first); const Token &T = MI->tokens().back(); StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength()); llvm::APInt IntValue; constexpr unsigned AutoSenseRadix = 0; if (ValueStr.getAsInteger(AutoSenseRadix, IntValue)) return llvm::None; return IntValue.getZExtValue(); }; const auto SigtermMacro = llvm::find_if(PP->macros(), IsSigterm); if (!SigtermValue && !(SigtermValue = TryExpandAsInteger(SigtermMacro))) return; |
55 ↗ | (On Diff #225641) | I think it would be valuable to mention the name of the signal. |
clang-tools-extra/docs/ReleaseNotes.rst | ||
82–83 | Your checker's name is different from these. Could you check these two lines please? | |
clang-tools-extra/docs/clang-tidy/checks/misc-bad-signal-to-kill-thread.rst | ||
7 ↗ | (On Diff #225641) | It would be kind to offer a compliant solution for fixing the warning. |
clang-tools-extra/test/clang-tidy/misc-bad-signal-to-kill-thread.cpp | ||
26 ↗ | (On Diff #225641) | Maybe worth to note here that this would be the compliant solution. Also check if it doesn't warn for different signals, but warns for the pthread_kill(thread, 0xF)) |
Auto types replaced on checker files. New lines added when necessary.
Reordered ReleaseNotes by alphabetical order. Checker name is
updated on ReleaseNotes, compliant solution is wrote to the
documentation. Another two test is written.
clang-tools-extra/clang-tidy/misc/BadSignalToKillThreadCheck.cpp | ||
---|---|---|
31 ↗ | (On Diff #225769) | In this case auto is reasonable, because this is iterator. |
clang-tools-extra/docs/ReleaseNotes.rst | ||
127 | Please synchronize with first statement in documentation. | |
129 | Please move this statement at the end of documentation. |
Header documentation and Release Notes synchronised. Documentation of
checker updated. Type changed to auto type when necessary.
clang-tools-extra/docs/clang-tidy/checks/misc-bad-signal-to-kill-thread.rst | ||
---|---|---|
9 ↗ | (On Diff #225784) | Usually links to documentation are located at the end of documentation. See other checks documentation as examples. |
Thank you for this! I don't think that the check should live in misc. It should have an alias in the CERT module, but maybe we want to have this live in a posix module? If not, this should probably live in bugprone.
clang-tools-extra/clang-tidy/misc/BadSignalToKillThreadCheck.cpp | ||
---|---|---|
31 ↗ | (On Diff #225834) | You can drop the trailing return type on the lambda. |
35 ↗ | (On Diff #225834) | This lambda capture looks suspicious -- why do you need to initialize the capture? |
59 ↗ | (On Diff #225834) | Clang-tidy diagnostics are not supposed to be grammatically correct. I think a better way to phrase it might be something like: thread should not be terminated by raising the 'SIGTERM' signal |
clang-tools-extra/docs/clang-tidy/checks/misc-bad-signal-to-kill-thread.rst | ||
6 ↗ | (On Diff #225834) | when thread is terminated by -> when a thread is terminated by raising the |
8 ↗ | (On Diff #225834) | Why does the check not look for SIGKILL as well as SIGTERM? |
clang-tools-extra/clang-tidy/misc/BadSignalToKillThreadCheck.cpp | ||
---|---|---|
28 ↗ | (On Diff #225834) | Can't we place this PP variable to the checker class? |
35 ↗ | (On Diff #225834) | You are right, I forgot that PP is a global variable when I offered this solution. |
Checker moved to bugprone module, cert alias added. Small fixes in checker
file, warning message updated.
clang-tools-extra/docs/clang-tidy/checks/misc-bad-signal-to-kill-thread.rst | ||
---|---|---|
8 ↗ | (On Diff #225834) | In my opinion SIGKILL is used only in cases when the programmer wants the entire process to terminate. I updated the docs not mentioning SIGKILL. |
clang-tools-extra/docs/clang-tidy/checks/bugprone-bad-signal-to-kill-thread.rst | ||
---|---|---|
4 | Please make same length as title above. |
Will be good idea to mention alias in Release Notes too (in aliases section, in alphabetical order).
Forgotten amend of commit message. Commited as:
https://github.com/llvm/llvm-project/commit/8d288a0668a574863d52784084ff565c89f7366e
Please keep alphabetical order in new checks list.