Reduced from gzip package: $ cat savedir.i char *streamsavedir_name_space; long streamsavedir_used; void *ximalloc() __attribute__((__alloc_size__(1))); const char **x; void streamsavedir___src() { streamsavedir_name_space = ximalloc(streamsavedir_used); char *dest = streamsavedir_name_space + streamsavedir_used; long __trans_tmp_1 = __builtin_dynamic_object_size(dest, 1); __builtin___stpcpy_chk(dest, *x, __trans_tmp_1); } $ gcc savedir.i -D_FORTIFY_SOURCE=3 -O during GIMPLE pass: objsz savedir.i: In function ‘streamsavedir___src’: savedir.i:9:1: internal compiler error: in size_for_offset, at tree-object-size.cc:352 9 | streamsavedir___src() { | ^~~~~~~~~~~~~~~~~~~ 0x79987d size_for_offset /home/marxin/Programming/gcc/gcc/tree-object-size.cc:352 0x1006124 plus_stmt_object_size /home/marxin/Programming/gcc/gcc/tree-object-size.cc:1354 0x1006124 collect_object_sizes_for /home/marxin/Programming/gcc/gcc/tree-object-size.cc:1645 0x10070a7 compute_builtin_object_size(tree_node*, int, tree_node**) /home/marxin/Programming/gcc/gcc/tree-object-size.cc:1106 0xa1d849 fold_builtin_object_size /home/marxin/Programming/gcc/gcc/builtins.cc:10397 0xa1d849 fold_builtin_2 /home/marxin/Programming/gcc/gcc/builtins.cc:9420 0xa1d849 fold_builtin_n /home/marxin/Programming/gcc/gcc/builtins.cc:9528 0x1007d2e dynamic_object_sizes_execute_one /home/marxin/Programming/gcc/gcc/tree-object-size.cc:1974 0x1007d2e object_sizes_execute /home/marxin/Programming/gcc/gcc/tree-object-size.cc:2034 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.
The master branch has been updated by Siddhesh Poyarekar <siddhesh@gcc.gnu.org>: https://gcc.gnu.org/g:818e305ea692ebc6578fb40881887d45382f876b commit r12-7667-g818e305ea692ebc6578fb40881887d45382f876b Author: Siddhesh Poyarekar <siddhesh@gotplt.org> Date: Wed Mar 16 16:10:51 2022 +0530 tree-optimization/104942: Retain sizetype conversions till the end Retain the sizetype alloc_object_size to guarantee the assertion in size_for_offset and to avoid adding a conversion there. nop conversions are eliminated at the end anyway in dynamic object size computation. gcc/ChangeLog: PR tree-optimization/104942 * tree-object-size.cc (alloc_object_size): Remove STRIP_NOPS. gcc/testsuite/ChangeLog: PR tree-optimization/104942 * gcc.dg/builtin-dynamic-object-size-0.c (alloc_func_long, test_builtin_malloc_long): New functions. (main): Use it. Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
Fixed.