diff --git a/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp --- a/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp +++ b/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()); diff --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp --- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp +++ b/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: