[clang] [clang] Implement __attribute__((format_matches)) (PR #116708)

via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 5 08:06:48 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>,
=?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>


bgra8 wrote:

@apple-fcloutier it seems this patch breaks code that declares functions with multiple different `__attibute__((__format__))` specifications.

One such example is the `util-linux` library (https://www.kernel.org/pub/linux/utils/util-linux/v2.41/) which has such a declaration:

```
int ul_path_scanff(struct path_cxt *pc, const char *path, va_list ap, const char *fmt, ...)
				__attribute__ ((__format__ (__printf__, 2, 0)))
				__attribute__ ((__format__ (__scanf__, 4, 5)));
```

The intention is to specify that `path` is a `printf` format and `fmt` is a `scanf` format. 

With the current patch, the compilers wrongfully errors when `fmt` is passed to `vfscanf` in the function implementation with the message:
```
path.c:734:18: error: passing 'printf' format string where 'scanf' format string is expected [-Werror,-Wformat]
  734 |         rc = vfscanf(f, fmt, fmt_ap);
```

So it looks like the compiler does not correctly identify each `format` attribute in the function declaration.

Is this intended?


https://github.com/llvm/llvm-project/pull/116708


More information about the cfe-commits mailing list