https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121323

            Bug ID: 121323
           Summary: UBSAN error in ao_ref_init_from_ptr_and_range (signed
                    integer overflow: -9223372036854775808 * 8 cannot be
                    represented in type 'long int')
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sjames at gcc dot gnu.org
            Blocks: 63426
  Target Milestone: ---

No testcase here as it needs LTO, I can spend time on that if it's needed.

```
/var/tmp/portage/sys-devel/gcc-16.0.9999/work/gcc-16.0.9999/gcc/poly-int.h:1038:5:
runtime error: signed integer overflow: -9223372036854775808 * 8 cannot be
represented in type 'long int'
    #0 0x559e4d9ad856 in poly_int<1u, poly_result<if_nonpoly<int, int,
poly_int_traits<int>::is_poly>::type, long,
poly_coeff_pair_traits<if_nonpoly<int, int,
poly_int_traits<int>::is_poly>::type, long>::result_kind>::type> operator*<1u,
int, long>(int const&, poly_int<1u, long> const&)
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/poly-int.h:1038
    #1 0x559e4d9ad856 in ao_ref_init_from_ptr_and_range(ao_ref*, tree_node*,
bool, poly_int<1u, long>, poly_int<1u, long>, poly_int<1u, long>)
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/tree-ssa-alias.cc:905
    #2 0x559e4d9ae1c0 in ao_ref_init_from_ptr_and_size(ao_ref*, tree_node*,
tree_node*)
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/tree-ssa-alias.cc:947
    #3 0x559e4deb94e5 in maybe_invalidate
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/tree-ssa-strlen.cc:1384
    #4 0x559e4dee4fab in strlen_pass::check_and_optimize_stmt(bool*)
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/tree-ssa-strlen.cc:5776
    #5 0x559e4dee6e97 in strlen_pass::before_dom_children(basic_block_def*)
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/tree-ssa-strlen.cc:5921
    #6 0x559e521e70fc in dom_walker::walk(basic_block_def*)
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/domwalk.cc:311
    #7 0x559e4debf569 in printf_strlen_execute
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/tree-ssa-strlen.cc:5981
    #8 0x559e4cdcb970 in execute_one_pass(opt_pass*)
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/passes.cc:2648
    #9 0x559e4cdce7f0 in execute_pass_list_1
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/passes.cc:2757
    #10 0x559e4cdce837 in execute_pass_list_1
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/passes.cc:2758
    #11 0x559e4cdce8fc in execute_pass_list(function*, opt_pass*)
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/passes.cc:2768
    #12 0x559e4b9e0a3e in cgraph_node::expand()
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/cgraphunit.cc:1859
    #13 0x559e4b9e0a3e in cgraph_node::expand()
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/cgraphunit.cc:1812
    #14 0x559e4b9f279d in expand_all_functions
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/cgraphunit.cc:2042
    #15 0x559e4b9f279d in symbol_table::compile()
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/cgraphunit.cc:2419
    #16 0x559e4b5c7410 in lto_main()
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/lto/lto.cc:693
    #17 0x559e4d42d435 in compile_file
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/toplev.cc:453
    #18 0x559e4b52f464 in do_compile
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/toplev.cc:2220
    #19 0x559e4b52f464 in toplev::main(int, char**)
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/toplev.cc:2383
    #20 0x559e4b532ba4 in main
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/main.cc:39
    #21 0x7fbdcc2277ca  (/usr/lib64/libc.so.6+0x277ca)
    #22 0x7fbdcc227879 in __libc_start_main (/usr/lib64/libc.so.6+0x27879)
    #23 0x559e4b5330a4 in _start
(/usr/libexec/gcc/x86_64-pc-linux-gnu/16/lto1+0x70f30a4)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
/var/tmp/portage/sys-devel/gcc-16.0.9999/work/gcc-16.0.9999/gcc/poly-int.h:1038:5
 
during GIMPLE pass: strlen
cribbage/cribbage.c:209:17: internal compiler error: Aborted
  209 | static unsigned score_fifteens (const struct Hand* hand)
      |                 ^
0x559e52d8106f internal_error(char const*, ...)
       
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/diagnostic-global-context.cc:534
0x559e4d42b367 crash_signal
        /usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/toplev.cc:323
0x559e4b52ba64 __sanitizer::Abort()
       
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/libsanitizer/sanitizer_common/sanitizer_posix_libcdep.cpp:163
0x559e53228f6b __sanitizer::Die()
       
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/libsanitizer/sanitizer_common/sanitizer_termination.cpp:58
0x559e53229bb6 __ubsan::ScopedReport::~ScopedReport()
       
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/libsanitizer/ubsan/ubsan_diag.cpp:402
0x559e5321eb0e handleIntegerOverflowImpl<__ubsan::Value>
       
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/libsanitizer/ubsan/ubsan_handlers.cpp:231
0x559e53222a7c __ubsan_handle_mul_overflow
       
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/libsanitizer/ubsan/ubsan_handlers.cpp:246
0x559e4d9ad856 poly_int<1u, poly_result<if_nonpoly<int, int,
poly_int_traits<int>::is_poly>::type, long,
poly_coeff_pair_traits<if_nonpoly<int, int,
poly_int_traits<int>::is_poly>::type, long>::result_kind>::type> operator*<1u,
int, long>(int const&, poly_int<1u, long> const&)
       
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/poly-int.h:1038
0x559e4d9ad856 ao_ref_init_from_ptr_and_range(ao_ref*, tree_node*, bool,
poly_int<1u, long>, poly_int<1u, long>, poly_int<1u, long>)
       
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/tree-ssa-alias.cc:905
0x559e4d9ae1c0 ao_ref_init_from_ptr_and_size(ao_ref*, tree_node*, tree_node*)
       
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/tree-ssa-alias.cc:947
0x559e4deb94e5 maybe_invalidate
       
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/tree-ssa-strlen.cc:1384
0x559e4dee4fab strlen_pass::check_and_optimize_stmt(bool*)
       
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/tree-ssa-strlen.cc:5776
0x559e4dee6e97 strlen_pass::before_dom_children(basic_block_def*)
       
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/tree-ssa-strlen.cc:5921
0x559e521e70fc dom_walker::walk(basic_block_def*)
        /usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/domwalk.cc:311
0x559e4debf569 printf_strlen_execute
       
/usr/src/debug/sys-devel/gcc-16.0.9999/gcc-16.0.9999/gcc/tree-ssa-strlen.cc:5981
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://bugs.gentoo.org/> for instructions.
```

```
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/16/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-pc-linux-gnu
Configured with:
/var/tmp/portage/sys-devel/gcc-16.0.9999/work/gcc-16.0.9999/configure
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr
--bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/16
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/16/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/16
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/16/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/16/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16
--disable-silent-rules --disable-dependency-tracking
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/16/python
--enable-libphobos --enable-objc-gc
--enable-languages=c,c++,d,objc,obj-c++,fortran,ada,rust --enable-obsolete
--enable-secureplt --disable-werror --with-system-zlib --enable-nls
--without-included-gettext --disable-libunwind-exceptions
--enable-checking=release --with-bugurl=https://bugs.gentoo.org/
--with-pkgversion='Gentoo 16.0.9999 p, commit
8cda62318174b911a7cba57fcf70efd38f265f0e' --with-gcc-major-version-only
--enable-libstdcxx-time --enable-lto --disable-libstdcxx-pch --enable-shared
--enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu
--enable-multilib --with-multilib-list=m32,m64 --disable-fixed-point
--enable-targets=all --enable-offload-defaulted
--enable-offload-targets=nvptx-none --enable-libgomp --disable-libssp
--enable-libada --enable-cet --disable-systemtap --enable-valgrind-annotations
--disable-vtable-verify --disable-libvtv --with-zstd --without-isl
--enable-default-pie --enable-host-pie --enable-host-bind-now
--enable-default-ssp --disable-fixincludes
--with-gxx-libcxx-include-dir=/usr/include/c++/v1
--with-build-config='bootstrap-ubsan bootstrap-cet'
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 16.0.0 20250730 (experimental)
7aa9565a62ea2ce04e2ddf61e1932bc123374988 (Gentoo 16.0.9999 p, commit
8cda62318174b911a7cba57fcf70efd38f265f0e)
```


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63426
[Bug 63426] [meta-bug] Issues found with -fsanitize=undefined

Reply via email to