This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
-Wlto-type-mismatch with flexible array in struct
- From: "Dan Halbert" <halbert at halwitz dot org>
- To: gcc-help at gcc dot gnu dot org
- Date: Wed, 12 Jul 2017 21:39:21 -0400 (EDT)
- Subject: -Wlto-type-mismatch with flexible array in struct
- Authentication-results: sourceware.org; auth=none
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.
Is this an LTO bug I should report, or is this a limitation of LTO? Thanks.
(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]