[PATCH] D126864: [clang] Introduce -fstrict-flex-arrays for stricter handling of flexible arrays
Kees Cook via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 8 11:31:57 PDT 2022
kees added a comment.
In D126864#3564519 <https://reviews.llvm.org/D126864#3564519>, @efriedma wrote:
> Do we want some builtin define so headers can check if we're in -fstrict-flex-arrays mode? It might be hard to mess with the definitions otherwise.
Hm, maybe? It wonder if that's more confusing, as code would need to do really careful management of allocation sizes.
struct foo {
u32 len;
#ifndef STRICT_FLEX_ARRAYS
u32 array[14];
#else
u32 array[];
#endif
};
`sizeof(struct foo)` will change. Or, even more ugly:
struct foo {
union {
struct {
u32 len_old;
u32 array_old[14];
};
struct {
u32 len;
u32 array[];
};
};
};
But then `sizeof(struct foo)` stays the same.
(FWIW, the kernel is effectively doing the latter without any define.)
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D126864/new/
https://reviews.llvm.org/D126864
More information about the cfe-commits
mailing list