https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124969
Bug ID: 124969
Summary: [16 Regression] ICE Segmentation fault since r16-7934,
sanitizer with counted_by attribute on invalid code
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: ice-on-invalid-code
Severity: normal
Priority: P3
Component: sanitizer
Assignee: unassigned at gcc dot gnu.org
Reporter: mjires at gcc dot gnu.org
CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
jakub at gcc dot gnu.org, kcc at gcc dot gnu.org,
qing.zhao at oracle dot com
Target Milestone: ---
Compiling reduced llvm/clang/test/Sema/attr-counted-by-void-ptr-gnu.c results
in Segmentation fault since r16-7934-g9b3c24577e7535.
I haven't found a way to reproduce it with valid code; it seems to be
interaction between void* and counted_by attribute.
$ cat attr-counted-by-void-ptr-gnu.c
struct {
int count;
void *buf __attribute__((counted_by(count)));
} pointer_arithmetic_t;
void pointer_arithmetic() { pointer_arithmetic_t.buf + 10; }
$ gcc attr-counted-by-void-ptr-gnu.c -fsanitize=undefined
attr-counted-by-void-ptr-gnu.c: In function ‘pointer_arithmetic’:
attr-counted-by-void-ptr-gnu.c:6:1: internal compiler error: Segmentation fault
6 | void pointer_arithmetic() { pointer_arithmetic_t.buf + 10; }
| ^~~~
0x25db825 internal_error(char const*, ...)
/home/mjires/git/GCC/master/gcc/diagnostic-global-context.cc:787
0x10828b7 crash_signal
/home/mjires/git/GCC/master/gcc/toplev.cc:325
0x99c8f2 get_index_from_offset
/home/mjires/git/GCC/master/gcc/c-family/c-ubsan.cc:677
0x99c8f2 get_index_from_pointer_addr_expr
/home/mjires/git/GCC/master/gcc/c-family/c-ubsan.cc:759
0x99c8f2 is_instrumentable_pointer_array_address
/home/mjires/git/GCC/master/gcc/c-family/c-ubsan.cc:803
0x99fd4f ubsan_maybe_instrument_array_ref(tree_node**, bool)
/home/mjires/git/GCC/master/gcc/c-family/c-ubsan.cc:873
0x9601a1 ubsan_walk_array_refs_r
/home/mjires/git/GCC/master/gcc/c-family/c-gimplify.cc:150
0x14997d4 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
/home/mjires/git/GCC/master/gcc/tree.cc:11742
0x96036d ubsan_walk_array_refs_r
/home/mjires/git/GCC/master/gcc/c-family/c-gimplify.cc:105
0x14997d4 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
/home/mjires/git/GCC/master/gcc/tree.cc:11742
0x95ffc1 c_genericize(tree_node*)
/home/mjires/git/GCC/master/gcc/c-family/c-gimplify.cc:788
0x82c71e finish_function(unsigned long)
/home/mjires/git/GCC/master/gcc/c/c-decl.cc:11661
0x8dbc19 c_parser_declaration_or_fndef
/home/mjires/git/GCC/master/gcc/c/c-parser.cc:3380
0x8ea862 c_parser_external_declaration
/home/mjires/git/GCC/master/gcc/c/c-parser.cc:2254
0x8eb885 c_parser_translation_unit
/home/mjires/git/GCC/master/gcc/c/c-parser.cc:2093
0x8eb885 c_parse_file()
/home/mjires/git/GCC/master/gcc/c/c-parser.cc:31302
0x9812ec c_common_parse_file()
/home/mjires/git/GCC/master/gcc/c-family/c-opts.cc:1430
/home/mjires/built/master/libexec/gcc/x86_64-pc-linux-gnu/16.0.1/cc1 -quiet
attr-counted-by-void-ptr-gnu.c -quiet -dumpdir a- -dumpbase
attr-counted-by-void-ptr-gnu.c -dumpbase-ext .c -mtune=generic -march=x86-64
-fsanitize=undefined -o /tmp/ccnceXvm.s
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.
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/home/mjires/built/master/libexec/gcc/x86_64-pc-linux-gnu/16.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /home/mjires/git/GCC/master/configure
--prefix=/home/mjires/built/master --disable-bootstrap
--enable-languages=c,c++,fortran,lto --disable-multilib --disable-libsanitizer
--enable-checking : (reconfigured) /home/mjires/git/GCC/master/configure
--prefix=/home/mjires/built/master --disable-bootstrap
--enable-languages=c,c++,fortran,lto --disable-multilib --disable-libsanitizer
--enable-checking
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 16.0.1 20260421 (experimental) (GCC)