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