https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119717
Bug ID: 119717 Summary: ICE in gimplify_expr, at gimplify.cc:20339 due to counted_by attribute Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: qinzhao at gcc dot gnu.org Target Milestone: --- for the following small testing case: []$ cat t3.c #include <stdlib.h> #include <stddef.h> struct annotated { size_t count; [[gnu::counted_by(count)]] char array[]; }; [[gnu::noinline,gnu::noipa]] static size_t size_of (bool x, struct annotated *a) { char *p = (x ? a : 0)->array; return __builtin_dynamic_object_size (p, 1); } int main() { struct annotated *p = malloc(sizeof *p); p->count = 0; __builtin_printf ("the bdos whole is %ld\n", size_of (0, p)); return 0; } with latest trunk GCC: gcc -O2 -Wall t3.c t3.c: In function ‘size_of’: t3.c:13:16: internal compiler error: in gimplify_expr, at gimplify.cc:20339 13 | char *p = (x ? a : 0)->array; | ^ 0x22c9777 internal_error(char const*, ...) ../../latest-gcc-write/gcc/diagnostic-global-context.cc:517 0x80fecf fancy_abort(char const*, int, char const*) ../../latest-gcc-write/gcc/diagnostic.cc:1749 0xc6cdef gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) ../../latest-gcc-write/gcc/gimplify.cc:20339 0xc6f17f gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) ../../latest-gcc-write/gcc/gimplify.cc:20309 0xc898e3 gimplify_cond_expr ../../latest-gcc-write/gcc/gimplify.cc:5569 0xc6e51b gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) ../../latest-gcc-write/gcc/gimplify.cc:19442 0xc704d3 gimplify_stmt(tree_node**, gimple**) ../../latest-gcc-write/gcc/gimplify.cc:8454 0xc89767 gimplify_cond_expr ../../latest-gcc-write/gcc/gimplify.cc:5529 0xc6e51b gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) ../../latest-gcc-write/gcc/gimplify.cc:19442 0xc6e747 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) ../../latest-gcc-write/gcc/gimplify.cc:19609 0xc774a7 gimplify_compound_lval ../../latest-gcc-write/gcc/gimplify.cc:3571 0xc6d327 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) ../../latest-gcc-write/gcc/gimplify.cc:19437 0xc79ffb gimplify_addr_expr ../../latest-gcc-write/gcc/gimplify.cc:7777 0xc6ebb3 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) ../../latest-gcc-write/gcc/gimplify.cc:19535 0xc85c5b gimplify_expr ../../latest-gcc-write/gcc/gimplify.cc:20593 0xc85c5b gimplify_arg(tree_node**, gimple**, unsigned long, bool) ../../latest-gcc-write/gcc/gimplify.cc:3832 0xc8cc07 gimplify_modify_expr ../../latest-gcc-write/gcc/gimplify.cc:7453 0xc6da0b gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) ../../latest-gcc-write/gcc/gimplify.cc:19488 0xc704d3 gimplify_stmt(tree_node**, gimple**) ../../latest-gcc-write/gcc/gimplify.cc:8454 0xc885ab gimplify_and_add(tree_node*, gimple**) ../../latest-gcc-write/gcc/gimplify.cc:547 Please submit a full bug report, with preprocessed source (by using -freport-bug). Please include the complete backtrace with any bug report. See <https://gcc.gnu.org/bugs/> for instructions. t: line 13: 2983087 Segmentation fault (core dumped) ./a.out 139