[clang-tools-extra] 216ad2d - [clang-tidy] Fix bugprone-bad-signal-to-kill-thread crash when `SIGTERM` is not a literal.
Aleksandr Platonov via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 6 01:00:12 PDT 2020
Author: Aleksandr Platonov
Date: 2020-08-06T10:32:03+03:00
New Revision: 216ad2da74f0e952af8f1c8ac84e19146d739ff2
URL: https://github.com/llvm/llvm-project/commit/216ad2da74f0e952af8f1c8ac84e19146d739ff2
DIFF: https://github.com/llvm/llvm-project/commit/216ad2da74f0e952af8f1c8ac84e19146d739ff2.diff
LOG: [clang-tidy] Fix bugprone-bad-signal-to-kill-thread crash when `SIGTERM` is not a literal.
If `SIGTERM` is not a literal (e.g. `#define SIGTERM ((unsigned)15)`) bugprone-bad-signal-to-kill-thread check crashes.
Stack dump:
```
#0 0x000000000217d15a llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/llvm-project/build/bin/clang-tidy+0x217d15a)
#1 0x000000000217b17c llvm::sys::RunSignalHandlers() (/llvm-project/build/bin/clang-tidy+0x217b17c)
#2 0x000000000217b2e3 SignalHandler(int) (/llvm-project/build/bin/clang-tidy+0x217b2e3)
#3 0x00007f6a7efb1390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
#4 0x000000000212ac9b llvm::StringRef::getAsInteger(unsigned int, llvm::APInt&) const (/llvm-project/build/bin/clang-tidy+0x212ac9b)
#5 0x0000000000593501 clang::tidy::bugprone::BadSignalToKillThreadCheck::check(clang::ast_matchers::MatchFinder::MatchResult const&) (/llvm-project/build/bin/clang-tidy+0x593501)
```
Reviewed By: hokein
Differential Revision: https://reviews.llvm.org/D85398
Added:
clang-tools-extra/test/clang-tidy/checkers/bugprone-bad-signal-to-kill-thread-sigterm-not-a-literal.cpp
Modified:
clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp
index 2c7b7b9faa9b..0720c7e689a1 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp
@@ -39,6 +39,8 @@ void BadSignalToKillThreadCheck::check(const MatchFinder::MatchResult &Result) {
return llvm::None;
const MacroInfo *MI = PP->getMacroInfo(It->first);
const Token &T = MI->tokens().back();
+ if (!T.isLiteral())
+ return llvm::None;
StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
llvm::APInt IntValue;
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone-bad-signal-to-kill-thread-sigterm-not-a-literal.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone-bad-signal-to-kill-thread-sigterm-not-a-literal.cpp
new file mode 100644
index 000000000000..f96f270dbf29
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-bad-signal-to-kill-thread-sigterm-not-a-literal.cpp
@@ -0,0 +1,10 @@
+// RUN: clang-tidy %s --checks=-*,bugprone-bad-signal-to-kill-thread -- | count 0
+
+#define SIGTERM ((unsigned)15) // no-crash
+using pthread_t = int;
+int pthread_kill(pthread_t thread, int sig);
+
+int func() {
+ pthread_t thread;
+ return pthread_kill(thread, 0);
+}
More information about the cfe-commits
mailing list