* [Bug c/109828] C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE
2023-05-12 12:42 [Bug c/109828] New: C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE yann at droneaud dot fr
@ 2023-05-12 12:54 ` yann at droneaud dot fr
2023-05-12 14:32 ` yann at droneaud dot fr
` (12 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: yann at droneaud dot fr @ 2023-05-12 12:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109828
Yann Droneaud <yann at droneaud dot fr> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |yann at droneaud dot fr
--- Comment #1 from Yann Droneaud <yann at droneaud dot fr> ---
I should mention GCC trunk (gcc 14.0.0 20230510 on godbolt.org) is experiencing
ICE without the need to call __builtin_object_size().
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/109828] C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE
2023-05-12 12:42 [Bug c/109828] New: C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE yann at droneaud dot fr
2023-05-12 12:54 ` [Bug c/109828] " yann at droneaud dot fr
@ 2023-05-12 14:32 ` yann at droneaud dot fr
2023-05-12 18:41 ` [Bug c/109828] [13/14 Regression] " pinskia at gcc dot gnu.org
` (11 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: yann at droneaud dot fr @ 2023-05-12 14:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109828
--- Comment #2 from Yann Droneaud <yann at droneaud dot fr> ---
(In reply to Yann Droneaud from comment #0)
> The following code is badly compiled by GCC 13.1:
>
> struct s { int i; char c[]; };
>
> const struct s s = { .c = "0", };
> const struct s *r = &(constexpr struct s) { .c = "1", };
> const struct s *t = &(static struct s) { .c = "2", };
>
> Targetting x86-64 / amd64, compiling this with gcc -std=gnu2x -S, produces
> surprising large .zero directive:
>
> s:
> .zero 4
> .string "0"
> __compound_literal.0:
> .zero 4
> .string "1"
> .zero 18446744073709551613
> .zero 1
> r:
> .quad __compound_literal.0
> __compound_literal.1:
> .zero 4
> .string "2"
> .zero 18446744073709551613
> .zero 1
> t:
> .quad __compound_literal.1
>
>
When asked to assemble that, binutils' as complains:
$ gcc -std=gnu2x nice.c -c
/tmp/ccZEWv73.s: Assembler messages:
/tmp/ccZEWv73.s:17: Warning: .space repeat count is zero, ignored
/tmp/ccZEWv73.s:32: Warning: .space repeat count is zero, ignored
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/109828] [13/14 Regression] C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE
2023-05-12 12:42 [Bug c/109828] New: C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE yann at droneaud dot fr
2023-05-12 12:54 ` [Bug c/109828] " yann at droneaud dot fr
2023-05-12 14:32 ` yann at droneaud dot fr
@ 2023-05-12 18:41 ` pinskia at gcc dot gnu.org
2023-05-12 19:10 ` yann at droneaud dot fr
` (10 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-12 18:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109828
Andrew Pinski <pinskia at gcc dot gnu.org> 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 <pinskia at gcc dot gnu.org> ---
With:
```
struct s { int i; char c[]; };
const struct s *t = &(struct s) { .c = "2", };
```
GCC 12 used to reject it:
<source>:3:44: error: non-static initialization of a flexible array member
3 | const struct s *t = &(struct s) { .c = "2", };
| ^~~
<source>:3:44: note: (near initialization for '(anonymous)')
Note I think the ICE would happen in GCC 13 with checking enabled too.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/109828] [13/14 Regression] C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE
2023-05-12 12:42 [Bug c/109828] New: C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE yann at droneaud dot fr
` (2 preceding siblings ...)
2023-05-12 18:41 ` [Bug c/109828] [13/14 Regression] " pinskia at gcc dot gnu.org
@ 2023-05-12 19:10 ` yann at droneaud dot fr
2023-05-12 19:16 ` pinskia at gcc dot gnu.org
` (9 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: yann at droneaud dot fr @ 2023-05-12 19:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109828
--- Comment #4 from Yann Droneaud <yann at droneaud dot fr> ---
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.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/109828] [13/14 Regression] C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE
2023-05-12 12:42 [Bug c/109828] New: C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE yann at droneaud dot fr
` (3 preceding siblings ...)
2023-05-12 19:10 ` yann at droneaud dot fr
@ 2023-05-12 19:16 ` pinskia at gcc dot gnu.org
2023-05-12 20:43 ` pinskia at gcc dot gnu.org
` (8 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-12 19:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109828
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(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 .
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/109828] [13/14 Regression] C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE
2023-05-12 12:42 [Bug c/109828] New: C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE yann at droneaud dot fr
` (4 preceding siblings ...)
2023-05-12 19:16 ` pinskia at gcc dot gnu.org
@ 2023-05-12 20:43 ` pinskia at gcc dot gnu.org
2023-05-15 6:47 ` [Bug c/109828] [13/14 Regression] static compound literal with flexible array " rguenth at gcc dot gnu.org
` (7 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-12 20:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109828
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
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
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/109828] [13/14 Regression] static compound literal with flexible array in initializer leads to invalid size and ICE
2023-05-12 12:42 [Bug c/109828] New: C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE yann at droneaud dot fr
` (5 preceding siblings ...)
2023-05-12 20:43 ` pinskia at gcc dot gnu.org
@ 2023-05-15 6:47 ` rguenth at gcc dot gnu.org
2023-05-15 12:38 ` yann at droneaud dot fr
` (6 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-05-15 6:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109828
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |13.2
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/109828] [13/14 Regression] static compound literal with flexible array in initializer leads to invalid size and ICE
2023-05-12 12:42 [Bug c/109828] New: C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE yann at droneaud dot fr
` (6 preceding siblings ...)
2023-05-15 6:47 ` [Bug c/109828] [13/14 Regression] static compound literal with flexible array " rguenth at gcc dot gnu.org
@ 2023-05-15 12:38 ` yann at droneaud dot fr
2023-05-15 16:30 ` yann at droneaud dot fr
` (5 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: yann at droneaud dot fr @ 2023-05-15 12:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109828
--- Comment #7 from Yann Droneaud <yann at droneaud dot fr> ---
I've also experimented compound literal initialization at block level instead
of file level. Except in case it's not supported, it shows the same issue at
block level as file level.
https://godbolt.org/z/vn5Pn7hTx
Unrelated, I've noted it's not possible to initialize the flexible array if the
initializer is not having a static storage. I would have expected this
restriction to be lifted by now.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/109828] [13/14 Regression] static compound literal with flexible array in initializer leads to invalid size and ICE
2023-05-12 12:42 [Bug c/109828] New: C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE yann at droneaud dot fr
` (7 preceding siblings ...)
2023-05-15 12:38 ` yann at droneaud dot fr
@ 2023-05-15 16:30 ` yann at droneaud dot fr
2023-07-27 9:26 ` rguenth at gcc dot gnu.org
` (4 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: yann at droneaud dot fr @ 2023-05-15 16:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109828
--- Comment #8 from Yann Droneaud <yann at droneaud dot fr> ---
(In reply to Yann Droneaud from comment #7)
> I've also experimented compound literal initialization at block level
> instead of file level. Except in case it's not supported, it shows the same
> issue at block level as file level.
>
> https://godbolt.org/z/vn5Pn7hTx
>
> Unrelated, I've noted it's not possible to initialize the flexible array if
> the initializer is not having a static storage. I would have expected this
> restriction to be lifted by now.
I've opened bug #109863
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/109828] [13/14 Regression] static compound literal with flexible array in initializer leads to invalid size and ICE
2023-05-12 12:42 [Bug c/109828] New: C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE yann at droneaud dot fr
` (8 preceding siblings ...)
2023-05-15 16:30 ` yann at droneaud dot fr
@ 2023-07-27 9:26 ` rguenth at gcc dot gnu.org
2023-08-27 20:00 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-27 9:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109828
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|13.2 |13.3
--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 13.2 is being released, retargeting bugs to GCC 13.3.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/109828] [13/14 Regression] static compound literal with flexible array in initializer leads to invalid size and ICE
2023-05-12 12:42 [Bug c/109828] New: C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE yann at droneaud dot fr
` (9 preceding siblings ...)
2023-07-27 9:26 ` rguenth at gcc dot gnu.org
@ 2023-08-27 20:00 ` pinskia at gcc dot gnu.org
2024-01-10 17:28 ` jamborm at gcc dot gnu.org
` (2 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-27 20:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109828
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |Araknod at hotmail dot it
--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 111175 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/109828] [13/14 Regression] static compound literal with flexible array in initializer leads to invalid size and ICE
2023-05-12 12:42 [Bug c/109828] New: C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE yann at droneaud dot fr
` (10 preceding siblings ...)
2023-08-27 20:00 ` pinskia at gcc dot gnu.org
@ 2024-01-10 17:28 ` jamborm at gcc dot gnu.org
2024-01-12 11:58 ` rguenth at gcc dot gnu.org
2024-05-21 9:15 ` [Bug c/109828] [13/14/15 " jakub at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: jamborm at gcc dot gnu.org @ 2024-01-10 17:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109828
Martin Jambor <jamborm at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jsm28 at gcc dot gnu.org
Keywords|needs-bisection |
--- Comment #11 from Martin Jambor <jamborm at gcc dot gnu.org> ---
ICE compiling testcase
---------------------
#include <stddef.h>
struct s {
int i;
char c[];
};
const struct s s = { .c = "0", };
const struct s *const r = &(constexpr struct s) { .c = "1", };
const struct s *const t = &(static struct s) { .c = "2", };
size_t ice(void)
{
return __builtin_object_size(t, 1);
}
----------------------
with options -O2 -std=gnu2x -S was introduced with commit
r13-3930-gb556d1773db717 (Joseph Myers: c: C2x constexpr), the testcase simply
errors before that because it tests constexprs.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/109828] [13/14 Regression] static compound literal with flexible array in initializer leads to invalid size and ICE
2023-05-12 12:42 [Bug c/109828] New: C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE yann at droneaud dot fr
` (11 preceding siblings ...)
2024-01-10 17:28 ` jamborm at gcc dot gnu.org
@ 2024-01-12 11:58 ` rguenth at gcc dot gnu.org
2024-05-21 9:15 ` [Bug c/109828] [13/14/15 " jakub at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-01-12 11:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109828
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/109828] [13/14/15 Regression] static compound literal with flexible array in initializer leads to invalid size and ICE
2023-05-12 12:42 [Bug c/109828] New: C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE yann at droneaud dot fr
` (12 preceding siblings ...)
2024-01-12 11:58 ` rguenth at gcc dot gnu.org
@ 2024-05-21 9:15 ` jakub at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-05-21 9:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109828
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|13.3 |13.4
--- Comment #12 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 13.3 is being released, retargeting bugs to GCC 13.4.
^ permalink raw reply [flat|nested] 15+ messages in thread