[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
Loading
Please sign in to comment