[Sema] Recognize format argument indicated by format attribute inside blocks
authorFélix Cloutier <fcloutier@apple.com>
Wed, 27 Oct 2021 22:38:31 +0000 (15:38 -0700)
committerFélix Cloutier <fcloutier@apple.com>
Wed, 27 Oct 2021 22:48:35 +0000 (15:48 -0700)
commitd378a0febc7e13aae7853b2e8733626f61140e55
tree99cd046b1231b87094317fcbbcff57daa8a07d02
parente6a4ba3aa603e542e6e0f7f7d9aca3cfa7c3f03f
[Sema] Recognize format argument indicated by format attribute inside blocks

- `[[format(archetype, fmt-idx, ellipsis)]]` specifies that a function accepts a
  format string and arguments according to `archetype`. This is how Clang
  type-checks `printf` arguments based on the format string.
- Clang has a `-Wformat-nonliteral` warning that is triggered when a function
  with the `format` attribute is called with a format string that is not
  inspectable because it isn't constant. This warning is suppressed if the
  caller has the `format` attribute itself and the format argument to the callee
  is the caller's own format parameter.
- When using the `format` attribute on a block, Clang wouldn't recognize its
  format parameter when calling another function with the format attribute. This
  would cause unsuppressed -Wformat-nonliteral warnings for no supported reason.

Reviewed By: ahatanak

Differential Revision: https://reviews.llvm.org/D112569

Radar-Id: rdar://84603673
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/format-strings.c