Bug 90214 - UBSAN: signed integer overflow: 162675373468811328 - -9060696663385964544 cannot be represented in type 'long int'
Summary: UBSAN: signed integer overflow: 162675373468811328 - -9060696663385964544 can...
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: ubsan
  Show dependency treegraph
 
Reported: 2019-04-23 12:48 UTC by Martin Liška
Modified: 2023-01-06 12:22 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Liška 2019-04-23 12:48:35 UTC
Following fails:

$ cat ubsan2.c
long b[1][9];
typedef long V __attribute__((vector_size (16), may_alias));

void
foo ()
{
  V *c = (V *) ((char *) b + -9060696663385964544);
  *c = (V) { 1, 1 };
  long __attribute__((may_alias)) *d = (long *) ((char *) b +
162675373468811328);
  *d = 1;
}

$ ~/BIG/buildbot/buildworker/marxinbox-gcc-ubsan/objdir/gcc/xgcc -B ~/BIG/buildbot/buildworker/marxinbox-gcc-ubsan/objdir/gcc/  ubsan2.c -c -O
/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-ubsan/build/gcc/poly-int.h:944:5: runtime error: signed integer overflow: 162675373468811328 - -9060696663385964544 cannot be represented in type 'long int'
    #0 0x4335e62 in poly_int<1u, poly_result<long, long, poly_coeff_pair_traits<long, long>::result_kind>::type> operator-<1u, long, long>(poly_int_pod<1u, long> const&, poly_int_pod<1u, long> const&) /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-ubsan/build/gcc/poly-int.h:944
    #1 0x4335e62 in record_store /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-ubsan/build/gcc/dse.c:1573
    #2 0x43393d2 in scan_insn /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-ubsan/build/gcc/dse.c:2568
    #3 0x43393d2 in dse_step1 /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-ubsan/build/gcc/dse.c:2680
    #4 0x43393d2 in rest_of_handle_dse /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-ubsan/build/gcc/dse.c:3597
    #5 0x43393d2 in execute /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-ubsan/build/gcc/dse.c:3655
    #6 0x1c6d018 in execute_one_pass(opt_pass*) /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-ubsan/build/gcc/passes.c:2487
    #7 0x1c70921 in execute_pass_list_1 /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-ubsan/build/gcc/passes.c:2573
    #8 0x1c70964 in execute_pass_list_1 /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-ubsan/build/gcc/passes.c:2574
    #9 0x1c70a18 in execute_pass_list(function*, opt_pass*) /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-ubsan/build/gcc/passes.c:2584
    #10 0xdb211d in cgraph_node::expand() /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-ubsan/build/gcc/cgraphunit.c:2198
    #11 0xdb64ab in expand_all_functions /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-ubsan/build/gcc/cgraphunit.c:2336
    #12 0xdb64ab in symbol_table::compile() /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-ubsan/build/gcc/cgraphunit.c:2687
    #13 0xdc0d5b in symbol_table::compile() /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-ubsan/build/gcc/cgraphunit.c:2599
    #14 0xdc0d5b in symbol_table::finalize_compilation_unit() /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-ubsan/build/gcc/cgraphunit.c:2865
    #15 0x2148fc4 in compile_file /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-ubsan/build/gcc/toplev.c:481
    #16 0x7bf43a in do_compile /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-ubsan/build/gcc/toplev.c:2205
    #17 0x7bf43a in toplev::main(int, char**) /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-ubsan/build/gcc/toplev.c:2340
    #18 0x83062e in main /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-ubsan/build/gcc/main.c:39
    #19 0x7ffff7976b7a in __libc_start_main ../csu/libc-start.c:308
    #20 0x834749 in _start (/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-ubsan/objdir/gcc/cc1+0x834749)
Comment 1 Nicholas Krause 2020-03-31 17:21:53 UTC
I've tried this on godbolt for gcc 9.1, gcc 9.2 and gcc 9.3. I've also tried this on trunk from a recent build and it does not occur anymore. Seems to be fixed now. Does this still occur for you, Martin as it does now occur for me on x86 or power?
Comment 2 Jonathan Wakely 2020-03-31 19:51:42 UTC
This is a ubsan error in GCC when GCC is built with ubsan. It's useless to test on godbolt, because their GCC builds are not built with ubsan.