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

            Bug ID: 87703
           Summary: UBSAN: poly-int.h:1941:12: runtime error: negation of
                    -9223372036854775808 cannot be represented in type
                    'long int'; cast to an unsigned type to negate this
                    value to itself
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marxin at gcc dot gnu.org
            Blocks: 63426
  Target Milestone: ---

Happens with UBSAN gcc compiler for:

$ cat overflow.i
int a;
unsigned long b;

void bar ();

void c() {
  if (__builtin_sub_overflow(0, a, &b))
    bar();
}

$ UBSAN_OPTIONS=print_stacktrace=1 ./xgcc -B. overflow.i -O2 -c
../../gcc/poly-int.h:1941:12: runtime error: negation of -9223372036854775808
cannot be represented in type 'long int'; cast to an unsigned type to negate
this value to itself
    #0 0xca1d18 in poly_result<poly_int_traits<long>::coeff_type,
poly_int_traits<long>::coeff_type,
poly_coeff_pair_traits<poly_int_traits<long>::coeff_type,
poly_int_traits<long>::coeff_type>::result_kind>::type known_alignment<1u,
long>(poly_int_pod<1u, long> const&) ../../gcc/poly-int.h:1941
    #1 0x40085d7 in force_int_to_mode ../../gcc/combine.c:8868
    #2 0x400711e in force_to_mode ../../gcc/combine.c:8721
    #3 0x3ff15b6 in simplify_set ../../gcc/combine.c:6800
    #4 0x3febb64 in combine_simplify_rtx ../../gcc/combine.c:6380
    #5 0x3fe2615 in subst ../../gcc/combine.c:5652
    #6 0x3fe0e8c in subst ../../gcc/combine.c:5515
    #7 0x3fcabc6 in try_combine ../../gcc/combine.c:3385
    #8 0x3fb9d2e in combine_instructions ../../gcc/combine.c:1301
    #9 0x4046a70 in rest_of_handle_combine ../../gcc/combine.c:14994
    #10 0x4046c30 in execute ../../gcc/combine.c:15039
    #11 0x1c66de3 in execute_one_pass(opt_pass*) ../../gcc/passes.c:2428
    #12 0x1c6783c in execute_pass_list_1 ../../gcc/passes.c:2517
    #13 0x1c678f9 in execute_pass_list_1 ../../gcc/passes.c:2518
    #14 0x1c679a3 in execute_pass_list(function*, opt_pass*)
../../gcc/passes.c:2528
    #15 0xe6fc6d in cgraph_node::expand() ../../gcc/cgraphunit.c:2194
    #16 0xe713a1 in expand_all_functions ../../gcc/cgraphunit.c:2332
    #17 0xe73e23 in symbol_table::compile() ../../gcc/cgraphunit.c:2683
    #18 0xe7497d in symbol_table::finalize_compilation_unit()
../../gcc/cgraphunit.c:2861
    #19 0x21076f2 in compile_file ../../gcc/toplev.c:480
    #20 0x2110385 in do_compile ../../gcc/toplev.c:2172
    #21 0x2110acb in toplev::main(int, char**) ../../gcc/toplev.c:2307
    #22 0x460055e in main ../../gcc/main.c:39
    #23 0x7ffff608cfea in __libc_start_main ../csu/libc-start.c:308
    #24 0x84e1a9 in _start
(/home/marxin/Programming/gcc2/objdir/gcc/cc1+0x84e1a9)


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