public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/109828] New: C2x:static compound literal (with flexible array) in initializer leads to invalid size and ICE
@ 2023-05-12 12:42 yann at droneaud dot fr
2023-05-12 12:54 ` [Bug c/109828] " yann at droneaud dot fr
` (12 more replies)
0 siblings, 13 replies; 14+ messages in thread
From: yann at droneaud dot fr @ 2023-05-12 12:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109828
Bug ID: 109828
Summary: C2x:static compound literal (with flexible array) in
initializer leads to invalid size and ICE
Product: gcc
Version: 13.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: yann at droneaud dot fr
Target Milestone: ---
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
Adding a call to __builtin_object_size() and compiling with optimization
triggers an ICE
size_t ice(void)
{
return __builtin_object_size(t, 0);
}
$ gcc -std=gnu2x -O2 -S ice.c
ice.c: In function ‘ice’:
ice.c:11:12: internal compiler error: Segmentation fault
11 | return __builtin_object_size(t, 0);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
0xc4dc6f crash_signal
../../gcc/toplev.cc:317
0x7f39935907cf ???
/usr/src/debug/glibc-2.37.9000-9.fc39.x86_64/signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0xb1023e tree_fits_poly_int64_p(tree_node const*)
../../gcc/tree.cc:6378
0xb1023e tree_to_poly_int64(tree_node const*)
../../gcc/tree.cc:3285
0x83b5bb component_ref_size(tree_node*, special_array_member*)
../../gcc/tree.cc:13199
0x8096ed decl_init_size(tree_node*, bool)
../../gcc/tree-object-size.cc:493
0xc7f08b addr_object_size
../../gcc/tree-object-size.cc:568
0x6d0248 fold_builtin_object_size
../../gcc/builtins.cc:10808
0x6d0248 fold_builtin_2
../../gcc/builtins.cc:9841
0x6d0248 fold_builtin_n(unsigned int, tree_node*, tree_node*, tree_node**,
int, bool) [clone .isra.0]
../../gcc/builtins.cc:9949
0x12084a6 gimplify_call_expr
../../gcc/gimplify.cc:3824
0x12084a6 gimplify_expr(tree_node**, gimple**, gimple**, bool
(*)(tree_node*), int)
../../gcc/gimplify.cc:16348
0x1207508 gimplify_modify_expr
../../gcc/gimplify.cc:6153
0x1207508 gimplify_expr(tree_node**, gimple**, gimple**, bool
(*)(tree_node*), int)
../../gcc/gimplify.cc:16376
0x1206dfc gimplify_stmt(tree_node**, gimple**)
../../gcc/gimplify.cc:7219
0x1699436 gimplify_and_add(tree_node*, gimple**)
../../gcc/gimplify.cc:492
0x1699436 gimplify_return_expr
../../gcc/gimplify.cc:1680
0x1208676 gimplify_expr(tree_node**, gimple**, gimple**, bool
(*)(tree_node*), int)
../../gcc/gimplify.cc:16638
0x1206dfc gimplify_stmt(tree_node**, gimple**)
../../gcc/gimplify.cc:7219
0x1698c04 gimplify_bind_expr
../../gcc/gimplify.cc:1430
See https://godbolt.org/z/fnnW5T8TG
^ permalink raw reply [flat|nested] 14+ 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 ` yann at droneaud dot fr
2023-05-12 14:32 ` yann at droneaud dot fr
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ 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] 14+ 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
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ 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] 14+ 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
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ 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] 14+ 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
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ 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] 14+ 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
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ 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] 14+ 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
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ 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] 14+ 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
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ 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] 14+ 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
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ 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] 14+ 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
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ 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] 14+ 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
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ 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] 14+ 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
2024-01-12 11:58 ` rguenth at gcc dot gnu.org
12 siblings, 0 replies; 14+ 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] 14+ 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
12 siblings, 0 replies; 14+ 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] 14+ 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
12 siblings, 0 replies; 14+ 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] 14+ messages in thread
end of thread, other threads:[~2024-01-12 11:58 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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
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
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
2024-01-12 11:58 ` rguenth at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).