[all-commits] [llvm/llvm-project] 006c49: Change behavior with zero-sized static array extents
Aaron Ballman via All-commits
all-commits at lists.llvm.org
Fri Jul 10 12:58:35 PDT 2020
Branch: refs/heads/master
Home: https://github.com/llvm/llvm-project
Commit: 006c49d890da633d1ce502117fc2a49863cd65b7
https://github.com/llvm/llvm-project/commit/006c49d890da633d1ce502117fc2a49863cd65b7
Author: Aaron Ballman <aaron at aaronballman.com>
Date: 2020-07-10 (Fri, 10 Jul 2020)
Changed paths:
M clang/include/clang/Basic/DiagnosticSemaKinds.td
M clang/lib/CodeGen/CGCall.cpp
M clang/lib/Sema/SemaType.cpp
M clang/test/CodeGen/vla.c
M clang/test/Sema/static-array.c
Log Message:
-----------
Change behavior with zero-sized static array extents
Currently, Clang previously diagnosed this code by default:
void f(int a[static 0]);
saying that "static has no effect on zero-length arrays", which was
accurate.
However, static array extents require that the caller of the function
pass a nonnull pointer to an array of *at least* that number of
elements, but it can pass more (see C17 6.7.6.3p6). Given that we allow
zero-sized arrays as a GNU extension and that it's valid to pass more
elements than specified by the static array extent, we now support
zero-sized static array extents with the usual semantics because it can
be useful in cases like:
void my_bzero(char p[static 0], int n);
my_bzero(&c+1, 0); //ok
my_bzero(t+k,n-k); //ok, pattern from actual code
More information about the All-commits
mailing list