https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81439
Bug ID: 81439 Summary: -Wlto-type-mismatch with flexible array in struct Product: gcc Version: 6.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: lto Assignee: unassigned at gcc dot gnu.org Reporter: halbert at halwitz dot org CC: marxin at gcc dot gnu.org Target Milestone: --- Created attachment 41756 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41756&action=edit all example source files in description I'm getting a -Wlto-type-mismatch warning with a struct that ends with a flexible array, declared in one file and initialized in another. I do NOT get a warning with a simple flexible array in the same situation. Since the plain flexible array does not generate a warning, I think perhaps LTO should not generate a warning for the struct case either, since the idea of the flexible array is to allow it to be of any length when initialized. As a workaround, I've tried suppressing the warning with #pragmas in the source code, but I guess they don't pass through to LTO. (tested with arm-none-eabi-gcc 6.3.1, but I see the same issue with native gcc 6.3.0) HAS WARNING: ab_struct.h ----------- typedef struct { int i; int ints[]; } struct_t; a_struct.c ---------- #include "ab_struct.h" extern struct_t my_struct; int main() { return my_struct.ints[0]; } b_struct.c ---------- #include "ab_struct.h" struct_t my_struct = { 20, { 1, 2 } }; $ arm-none-eabi-gcc -flto -Wlto-type-mismatch a_struct.c b_struct.c -o foo a_struct.c:3:17: warning: size of 'my_struct' differ from the size of original declaration [-Wlto-type-mismatch] extern struct_t my_struct; ^ b_struct.c:3:10: note: 'my_struct' was previously declared here struct_t my_struct = { ----------------------------------------------------------------------------- NO WARNING with this plain flexible array, not in a struct: a_array.c --------- extern int ia[]; int main() { return ia[0]; } b_array.c --------- int ia[] = { 1, 2 }; $ arm-none-eabi-gcc -flto -Wlto-type-mismatch a_array.c b_array.c -o foo [no warning]