[clang] [Clang] Fix __is_array returning true for zero-sized arrays (PR #86652)

Kees Cook via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 28 14:46:37 PDT 2024


kees wrote:

> My natural inclination is that it is array-like, but... that just makes me want `__is_array` to return `true` for it all the more.

Yes. An array is an array, regardless of its size. The size is just a storage characteristic. It'd almost be like arguing that `NaN` isn't a float.

> I wonder if we should be considering making zero-length arrays into a non-conforming extension behind a flag?

It was never as simple as zero-length arrays. It was also _trailing arrays of any size_ in structures. Those extensions create huge problems with being able to reason about the characteristics of arrays, and we do have a flag for this: `-fstrict-flex-arrays=3`. It is designed to disable all of the "treat it like a flexible array" logic for the old "fake flexible array" objects. But a flexible array is _still an array_. And also note that its size can _change at runtime_ (see the `counted_by` attribute), which even more clearly argues that you can't claim a flexible array isn't an array.

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


More information about the cfe-commits mailing list