https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85158
Bug ID: 85158
Summary: ubsan and -O3 finds a problem
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: dcb314 at hotmail dot com
Target Milestone: ---
For this C code:
short *a;
long b;
d() {
char *c;
for (; b; b++)
if (a[b + 1])
c[1] = a[b];
e();
}
and recent ubsan trunk gcc
$ ~/gcc/results/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/home/dcb/gcc/results/bin/gcc
COLLECT_LTO_WRAPPER=/home/dcb/gcc/results.259004.ubsan/libexec/gcc/x86_64-pc-linux-gnu/8.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../trunk/configure --prefix=/home/dcb/gcc/results.259004.ubsan
--with-build-config=bootstrap-ubsan --disable-multilib --disable-werror
--enable-checking=df,extra,fold,rtl,yes --enable-languages=c,c++,fortran
Thread model: posix
gcc version 8.0.1 20180402 (experimental) (GCC)
$
Then I get:
$ ~/gcc/results/bin/gcc -c -w -O3 bug424.c
../../trunk/gcc/tree-data-ref.c:3758:26: runtime error: signed integer
overflow: 9223372036854775807 - -1 cannot be represented in type 'long int'
../../trunk/gcc/tree-data-ref.c:3760:40: runtime error: signed integer
overflow: -9223372036854775808 - 1 cannot be represented in type 'long int'
$