[PATCH] D85417: [clangd] Fix crash in bugprone-bad-signal-to-kill-thread clang-tidy check.
Aleksandr Platonov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 6 11:46:41 PDT 2020
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9f24148b2126: [clangd] Fix crash in bugprone-bad-signal-to-kill-thread clang-tidy check. (authored by ArcsinX).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D85417/new/
https://reviews.llvm.org/D85417
Files:
clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -438,6 +438,21 @@
EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre());
}
+TEST(DiagnosticTest, ClangTidyNoLiteralDataInMacroToken) {
+ Annotations Main(R"cpp(
+ #define SIGTERM 15
+ using pthread_t = int;
+ int pthread_kill(pthread_t thread, int sig);
+ int func() {
+ pthread_t thread;
+ return pthread_kill(thread, 0);
+ }
+ )cpp");
+ TestTU TU = TestTU::withCode(Main.code());
+ TU.ClangTidyChecks = "-*,bugprone-bad-signal-to-kill-thread";
+ EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre()); // no-crash
+}
+
TEST(DiagnosticsTest, Preprocessor) {
// This looks like a preamble, but there's an #else in the middle!
// Check that:
Index: clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp
@@ -39,7 +39,7 @@
return llvm::None;
const MacroInfo *MI = PP->getMacroInfo(It->first);
const Token &T = MI->tokens().back();
- if (!T.isLiteral())
+ if (!T.isLiteral() || !T.getLiteralData())
return llvm::None;
StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85417.283690.patch
Type: text/x-patch
Size: 1565 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200806/15e96bcc/attachment.bin>
More information about the cfe-commits
mailing list