[clang] [clang] Implement __attribute__((format_matches)) (PR #116708)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 6 08:59:47 PST 2025
=?utf-8?q?Félix?= Cloutier <fcloutier at apple.com>,
=?utf-8?q?Félix?= Cloutier <fcloutier at apple.com>,
=?utf-8?q?Félix?= Cloutier <fcloutier at apple.com>,
=?utf-8?q?Félix?= Cloutier <fcloutier at apple.com>,
=?utf-8?q?Félix?= Cloutier <fcloutier at apple.com>,
=?utf-8?q?Félix?= Cloutier <fcloutier at apple.com>,
=?utf-8?q?Félix?= Cloutier <fcloutier at apple.com>,
=?utf-8?q?Félix?= Cloutier <fcloutier at apple.com>,
=?utf-8?q?Félix?= Cloutier <fcloutier at apple.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/116708 at github.com>
================
@@ -8664,6 +8664,39 @@ bool Sema::CheckFormatStringsCompatible(
return false;
}
+bool Sema::ValidateFormatString(FormatStringType Type,
+ const StringLiteral *Str) {
+ if (Type != Sema::FST_Printf && Type != Sema::FST_NSString &&
+ Type != Sema::FST_Kprintf && Type != Sema::FST_FreeBSDKPrintf &&
+ Type != Sema::FST_OSLog && Type != Sema::FST_OSTrace &&
+ Type != Sema::FST_Syslog)
+ return true;
+
+ FormatStringLiteral RefLit = Str;
+ llvm::SmallVector<EquatableFormatArgument, 9> Args;
+ bool IsObjC = Type == Sema::FST_NSString || Type == Sema::FST_OSTrace;
+ if (!DecomposePrintfHandler::GetSpecifiers(*this, &RefLit, Str, Type, IsObjC,
+ true, Args))
+ return false;
+
+ // If positional arguments are used multiple times in the same format string,
+ // ensure that they are used in compatible ways.
+ bool HadError = false;
+ auto Iter = Args.begin();
+ auto End = Args.end();
+ while (Iter != End) {
----------------
apple-fcloutier wrote:
(FWIW, this is the same thing as the other place you commented, but I moved it around between two commits)
https://github.com/llvm/llvm-project/pull/116708
More information about the cfe-commits
mailing list