This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: -Wlto-type-mismatch with flexible array in struct


On 07/12/2017 07:39 PM, Dan Halbert wrote:
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.

My Bugzilla searches for "flexible" in the lto component didn't
return any relevant bugs about it.  I would recommend opening
a new bug for it and letting the LTO experts comment on it (they
may not be reading gcc-help).

Martin



(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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]