https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110878

--- Comment #6 from Taylor R Campbell <campbell+gcc-bugzilla at mumble dot net> 
---
Just to clarify, the issue is that the meaning of `void foo(unsigned
char p[static 16], unsigned n)` is that p must be an array of _at
least_ 16 elements, but gcc is treating it as if it says the argument
is an array of _at most_ 16 elements.

C99, Sec. 6.7.5.3 `Function declarators (including prototypes)',
paragraph 7, p. 119:

> If the keyword `static` also appears within the `[` and `]` of the
> array type derivation, then for each call to the function, the value
> of the corresponding actual argument shall provide access to the
> first element of an array with _at least_ as many elements as
> specified by the size expression.

(emphasis added; identical language in later versions like C23,
Sec. 6.7.6.3 `Function declarators', paragraph 6, p. 128)

The function in question requires _at least_ 16 bytes, and operates on
_exactly_ n bytes, but because n might be larger than 16, gcc raises a
bogus warning under the incorrect assumption that p must have _at most_
16 bytes.

(The somewhat weird reproducer in the original report is a
substantially reduced example isolated from real logic that requires
_at least_ 16 bytes (an AES block), and then takes a vectorized fast
path when n is determined at run-time to be _at least_ 128 bytes (eight
consecutive AES blocks).)

Reply via email to