[PATCH] D137603: [Clang][Sema] Fix attribute((format)) bug on non-variadic functions
FĂ©lix Cloutier via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 7 19:49:50 PST 2022
fcloutier created this revision.
fcloutier added reviewers: ahatanak, dcoughlin, aaron.ballman.
fcloutier added a project: clang.
Herald added a project: All.
fcloutier requested review of this revision.
Herald added a subscriber: cfe-commits.
The initial implementation <https://reviews.llvm.org/D112579> of `__attribute__((format))` on non-variadic functions accidentally only accepted //one// data argument. This worked:
__attribute__((format(printf, 1, 2)))
void f(const char *, int);
but this didn't:
__attribute__((format(printf, 1, 2)))
void f(const char *, int, int);
This is due to an oversight in changing the way diagnostics are emitted for attribute((format)), and to a coincidence in the handling of the variadic case. Test cases only covered the case that worked by coincidence.
Before the previous change, using `__attribute__((format))` on a non-variadic function at all was an error and clang bailed out. After that change, it only generates a GCC compatibility warning. However, as execution falls through, it hits a second diagnostic when the first data argument is neither 0 nor the last parameter of the function.
This change updates that check to allow any parameter after the format string to be the first data argument when the function is non-variadic. When the function is variadic, it still needs to be the index of the `...` "parameter". Attribute documentation is updated to reflect the change and new tests are added to verify that it works with //two// data parameters.
rdar://102069446
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D137603
Files:
clang/include/clang/Basic/AttrDocs.td
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Sema/attr-format.c
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137603.473860.patch
Type: text/x-patch
Size: 5191 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221108/dacbda8e/attachment.bin>
More information about the cfe-commits
mailing list