[clang-tools-extra] [clang-tidy] Fix bugprone-bad-signal-to-kill-thread not working in clangd (PR #180711)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 10 02:39:41 PST 2026
================
@@ -33,14 +33,32 @@ void BadSignalToKillThreadCheck::check(const MatchFinder::MatchResult &Result) {
KeyValue.first->hasMacroDefinition();
};
const auto TryExpandAsInteger =
- [](Preprocessor::macro_iterator It) -> std::optional<unsigned> {
+ [&Result](Preprocessor::macro_iterator It) -> std::optional<unsigned> {
if (It == PP->macro_end())
return std::nullopt;
const MacroInfo *MI = PP->getMacroInfo(It->first);
const Token &T = MI->tokens().back();
- if (!T.isLiteral() || !T.getLiteralData())
+
+ if (!T.isLiteral())
return std::nullopt;
- const StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
+
+ StringRef ValueStr;
+ if (T.getLiteralData()) {
+ ValueStr = StringRef(T.getLiteralData(), T.getLength());
+ } else {
+ const SourceManager *SM = Result.SourceManager;
+ const SourceLocation Loc = T.getLocation();
+ if (Loc.isInvalid())
+ return std::nullopt;
+ std::optional<StringRef> Buffer =
+ SM->getBufferDataOrNone(SM->getFileID(Loc));
+ if (!Buffer)
+ return std::nullopt;
+ const unsigned Offset = SM->getFileOffset(Loc);
+ if (Offset + T.getLength() > Buffer->size())
+ return std::nullopt;
+ ValueStr = Buffer->substr(Offset, T.getLength());
----------------
zeyi2 wrote:
Nit: can we use `Lexer::getSpelling` for this?
https://github.com/llvm/llvm-project/pull/180711
More information about the cfe-commits
mailing list