[Bug c/109828] [13/14 Regression] C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE

2023-05-12 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109828

--- Comment #6 from Andrew Pinski  ---
here is another example where we output a bogus `.zero` (though it does not
ICE):
struct s { int i; char c[]; };
const struct s *t = &(struct s) { .c = {'2','\0'}, };

We get:
.size   __compound_literal.0, 4
__compound_literal.0:
.long   1
.byte   50
.byte   0
.zero   18446744073709551613 ;; -3
.zero   1

[Bug c/109828] [13/14 Regression] C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE

2023-05-12 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109828

--- Comment #5 from Andrew Pinski  ---
(In reply to Yann Droneaud from comment #4)
> I'm still playing with this, for example https://godbolt.org/z/dfjr8veh5,
> and I've noticed the size of the compound_initializer is incorrect too:
> Maybe it's the result of computing the size as 3 + -3 + 1, but it's far
> fetched.

Yes the .size is wrong. But it does not matter much as the ICE on the trunk is
definitely showing there are more issues.

Also yes the ICE is due to checking being enabled:
  gcc_checking_assert (check_string_literal (exp, size));

static bool
check_string_literal (tree string, unsigned HOST_WIDE_INT size)
{
  tree type = TREE_TYPE (string);
  tree eltype = TREE_TYPE (type);
  unsigned HOST_WIDE_INT elts = tree_to_uhwi (TYPE_SIZE_UNIT (eltype));
  unsigned HOST_WIDE_INT mem_size = tree_to_uhwi (TYPE_SIZE_UNIT (type));


The ICE is in that last tree_to_uhwi .

[Bug c/109828] [13/14 Regression] C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE

2023-05-12 Thread yann at droneaud dot fr via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109828

--- Comment #4 from Yann Droneaud  ---
I'm still playing with this, for example https://godbolt.org/z/dfjr8veh5, and
I've noticed the size of the compound_initializer is incorrect too:

struct s { char i; char c[]; };
const struct s *const s = &(static const struct s) { .c = "1", };

Compile too:

.quad   __compound_literal.4
.type   __compound_literal.4, @object
.size   __compound_literal.4, 1
__compound_literal.4:
.zero   1
.string "1"
.zero   18446744073709551613
.zero   1

I would have have expected .size to be 3, not 1.

Maybe it's the result of computing the size as 3 + -3 + 1, but it's far
fetched.

[Bug c/109828] [13/14 Regression] C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE

2023-05-12 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109828

Andrew Pinski  changed:

   What|Removed |Added

 Ever confirmed|0   |1
Summary|C2x:static compound literal |[13/14 Regression]
   |(with flexible array) in|C2x:static compound literal
   |initializer leads to|(with flexible array) in
   |invalid size and ICE|initializer leads to
   ||invalid size and ICE
   Last reconfirmed||2023-05-12
 Status|UNCONFIRMED |NEW

--- Comment #3 from Andrew Pinski  ---
With:
```
struct s { int i; char c[]; };
const struct s *t = &(struct s) { .c = "2", };
```
GCC 12 used to reject it:
:3:44: error: non-static initialization of a flexible array member
3 | const struct s *t = &(struct s) { .c = "2", };
  |^~~
:3:44: note: (near initialization for '(anonymous)')


Note I think the ICE would happen in GCC 13 with checking enabled too.