[Bug lto/81440] -Wlto-type-mismatch warning with flexible array in struct

2018-01-22 Thread halbert at halwitz dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81440

--- Comment #4 from Dan Halbert  ---
There's movement on bug 83954, which seems related but is a different
manifestation. Will a fix there fix this also? (I see your "I've got a patch"
comment, but that was a while ago).

[Bug lto/81440] -Wlto-type-mismatch warning with flexible array in struct

2017-07-13 Thread halbert at halwitz dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81440

--- Comment #1 from Dan Halbert  ---
*** Bug 81439 has been marked as a duplicate of this bug. ***

[Bug lto/81439] -Wlto-type-mismatch with flexible array in struct

2017-07-13 Thread halbert at halwitz dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81439

Dan Halbert  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |DUPLICATE

--- Comment #1 from Dan Halbert  ---
Inadvertent double submission due to bugzilla timeout when submitting bug the
first time. Second submission slightly clearer.

*** This bug has been marked as a duplicate of bug 81440 ***

[Bug lto/81440] New: -Wlto-type-mismatch warning with flexible array in struct

2017-07-13 Thread halbert at halwitz dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81440

Bug ID: 81440
   Summary: -Wlto-type-mismatch warning 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 41757
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41757&action=edit
all example source files in description

I'm getting a -Wlto-type-mismatch size 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.

I think LTO should treat the struct with a flex array similarly to the plain
flex array, and not try to match the sizes.


(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]

[Bug lto/81439] New: -Wlto-type-mismatch with flexible array in struct

2017-07-13 Thread halbert at halwitz dot org
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]