[clang-tools-extra] [clang-tidy] Only expand <inttypes.h> macros in modernize-use-std-format/print (PR #97911)
Piotr Zegar via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 8 10:01:45 PDT 2024
================
@@ -230,6 +241,37 @@ FormatStringConverter::FormatStringConverter(ASTContext *ContextIn,
finalizeFormatText();
}
+std::optional<StringRef>
+FormatStringConverter::formatStringContainsUnreplaceableMacro(
+ const StringLiteral *FormatExpr, SourceManager &SM, Preprocessor &PP) {
+ for (auto I = FormatExpr->tokloc_begin(), E = FormatExpr->tokloc_end();
+ I != E; ++I) {
+ const SourceLocation &TokenLoc = *I;
+ if (TokenLoc.isMacroID()) {
+ const StringRef MacroName =
+ Lexer::getImmediateMacroName(TokenLoc, SM, PP.getLangOpts());
+
+ // glibc uses __PRI64_PREFIX and __PRIPTR_PREFIX to define the prefixes
+ // for types that change size so we must look for multiple prefixes.
+ if (!MacroName.starts_with("PRI") && !MacroName.starts_with("__PRI"))
+ return MacroName;
+
+ const SourceLocation TokenSpellingLoc = SM.getSpellingLoc(TokenLoc);
----------------
PiotrZSL wrote:
add checking here if location is valid.
https://github.com/llvm/llvm-project/pull/97911
More information about the cfe-commits
mailing list