[all-commits] [llvm/llvm-project] cd95d7: [Clang][Sema] Fix attribute((format)) bug on non-v...
apple-fcloutier via All-commits
all-commits at lists.llvm.org
Tue Dec 6 13:09:07 PST 2022
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: cd95d7998c1dd30c6353aeca2686697287cb0443
https://github.com/llvm/llvm-project/commit/cd95d7998c1dd30c6353aeca2686697287cb0443
Author: FĂ©lix Cloutier <fcloutier at apple.com>
Date: 2022-12-06 (Tue, 06 Dec 2022)
Changed paths:
M clang/docs/ReleaseNotes.rst
M clang/include/clang/Basic/AttrDocs.td
M clang/lib/Sema/SemaDeclAttr.cpp
A clang/test/FixIt/attr-format.c
M clang/test/Sema/attr-format.c
Log Message:
-----------
[Clang][Sema] Fix attribute((format)) bug on non-variadic functions
The [initial implementation][1] of __attribute__((format)) on non-variadic functions
accidentally only accepted one data argument. This worked:
```c
__attribute__((format(printf, 1, 2)))
void f(const char *, int);
```
but this didn't:
```c
__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.
[1]: https://reviews.llvm.org/D112579
Radar-Id: rdar://102069446
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D137603
More information about the All-commits
mailing list