-Wlto-type-mismatch with flexible array in struct

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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]






[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux