[all-commits] [llvm/llvm-project] c71011: [clang] Implement __attribute__((format_matches)) ...
apple-fcloutier via All-commits
all-commits at lists.llvm.org
Mon Feb 24 18:59:21 PST 2025
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: c7101188fb3f17176e9152b1d733da6d7199d317
https://github.com/llvm/llvm-project/commit/c7101188fb3f17176e9152b1d733da6d7199d317
Author: apple-fcloutier <75502309+apple-fcloutier at users.noreply.github.com>
Date: 2025-02-24 (Mon, 24 Feb 2025)
Changed paths:
M clang/docs/ReleaseNotes.rst
M clang/include/clang/AST/FormatString.h
M clang/include/clang/Basic/Attr.td
M clang/include/clang/Basic/AttrDocs.td
M clang/include/clang/Basic/DiagnosticSemaKinds.td
M clang/include/clang/Sema/Sema.h
M clang/lib/AST/AttrImpl.cpp
M clang/lib/AST/FormatString.cpp
M clang/lib/Sema/SemaChecking.cpp
M clang/lib/Sema/SemaDecl.cpp
M clang/lib/Sema/SemaDeclAttr.cpp
M clang/lib/Sema/SemaObjC.cpp
A clang/test/Sema/format-string-matches.c
M clang/test/Sema/format-strings.c
Log Message:
-----------
[clang] Implement __attribute__((format_matches)) (#116708)
This implements ``__attribute__((format_matches))``, as described in the
RFC:
https://discourse.llvm.org/t/rfc-format-attribute-attribute-format-like/83076
The ``format`` attribute only allows the compiler to check that a format
string matches its arguments. If the format string is passed
independently of its arguments, there is no way to have the compiler
check it. ``format_matches(flavor, fmtidx, example)`` allows the
compiler to check format strings against the ``example`` format string
instead of against format arguments. See the changes to AttrDocs.td in
this diff for more information.
Implementation-wise, this change subclasses CheckPrintfHandler and
CheckScanfHandler to allow them to collect specifiers into arrays, and
implements comparing that two specifiers are equivalent.
`checkFormatStringExpr` gets a new `ReferenceFormatString` argument that
is piped down when calling a function with the `format_matches`
attribute (and is `nullptr` otherwise); this is the string that the
actual format string is compared against.
Although this change does not enable -Wformat-nonliteral by default,
IMO, all the pieces are now in place such that it could be.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list