Bug 84946 - [8 Regression] UBSAN: in mem_valid_for_store_merging ../../gcc/gimple-ssa-store-merging.c:3951
Summary: [8 Regression] UBSAN: in mem_valid_for_store_merging ../../gcc/gimple-ssa-sto...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 8.0.1
: P1 normal
Target Milestone: 8.0
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks: ubsan
  Show dependency treegraph
 
Reported: 2018-03-19 08:08 UTC by Martin Liška
Modified: 2018-03-19 20:51 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-03-19 00:00:00


Attachments
gcc8-pr84946.patch (378 bytes, patch)
2018-03-19 17:04 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Liška 2018-03-19 08:08:42 UTC
Following causes UBSAN:

$ ./xgcc -B. -mavx512f -O2  /home/marxin/Programming/gcc/gcc/testsuite/gcc.dg/pr82389.c
../../gcc/poly-int.h:845:5: runtime error: signed integer overflow: 9223372034573074432 + 8589934592 cannot be represented in type 'long int'
    #0 0x38fd659 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&) ../../gcc/poly-int.h:845
    #1 0x38fd659 in mem_valid_for_store_merging ../../gcc/gimple-ssa-store-merging.c:3951
    #2 0x3908e85 in process_store ../../gcc/gimple-ssa-store-merging.c:4043
    #3 0x3908e85 in execute ../../gcc/gimple-ssa-store-merging.c:4279
    #4 0x18f5250 in execute_one_pass(opt_pass*) ../../gcc/passes.c:2497
    #5 0x18f85bb in execute_pass_list_1 ../../gcc/passes.c:2586
    #6 0x18f85e4 in execute_pass_list_1 ../../gcc/passes.c:2587
    #7 0x18f8674 in execute_pass_list(function*, opt_pass*) ../../gcc/passes.c:2597
    #8 0xbe01ae in cgraph_node::expand() ../../gcc/cgraphunit.c:2139
    #9 0xbe4f7d in expand_all_functions ../../gcc/cgraphunit.c:2275
    #10 0xbe4f7d in symbol_table::compile() ../../gcc/cgraphunit.c:2624
    #11 0xbeee87 in symbol_table::compile() ../../gcc/cgraphunit.c:2720
    #12 0xbeee87 in symbol_table::finalize_compilation_unit() ../../gcc/cgraphunit.c:2717
    #13 0x1d100a8 in compile_file ../../gcc/toplev.c:480
    #14 0x639d9c in do_compile ../../gcc/toplev.c:2132
    #15 0x639d9c in toplev::main(int, char**) ../../gcc/toplev.c:2267
    #16 0x63c7fa in main ../../gcc/main.c:39
    #17 0x7ffff5cafa86 in __libc_start_main (/lib64/libc.so.6+0x21a86)
    #18 0x63c929 in _start (/home/marxin/Programming/gcc/objdir2/gcc/cc1+0x63c929)
Comment 1 Jakub Jelinek 2018-03-19 08:27:00 UTC
This is another thing that I could easily fix for UHWI computations, but not really sure how to do it with the poly-int.h stuff in the way.  Richard, please have a look.
Comment 2 Jakub Jelinek 2018-03-19 17:04:34 UTC
Created attachment 43709 [details]
gcc8-pr84946.patch

Untested fix.
Comment 3 Jakub Jelinek 2018-03-19 20:50:31 UTC
Author: jakub
Date: Mon Mar 19 20:49:57 2018
New Revision: 258665

URL: https://gcc.gnu.org/viewcvs?rev=258665&root=gcc&view=rev
Log:
	PR tree-optimization/84946
	* gimple-ssa-store-merging.c (mem_valid_for_store_merging): Compute
	bitsize + bitsize in poly_uint64 rather than poly_int64.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/gimple-ssa-store-merging.c
Comment 4 Jakub Jelinek 2018-03-19 20:51:29 UTC
Fixed.