http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53968
Bug #: 53968
Summary: integer undefined behaviors in GCC
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: [email protected]
ReportedBy: [email protected]
Using IOC (link below) I made a GCC that looks for integer overflow problems in
itself, and then used it to run the GCC testsuite and bootstrap itself. The
resulting defects are listed below.
I've found that the best way to track down these problems is to put an
assertion into the source code close to where the overflow happens.
Note that this is far fewer undefined behaviors than were present two years
ago:
http://gcc.gnu.org/ml/gcc/2010-08/msg00039.html
Version info:
regehr@home:~/z/checked-gcc-install/bin$ ./gcc -v
Using built-in specs.
COLLECT_GCC=./gcc
COLLECT_LTO_WRAPPER=/home/regehr/z/checked-gcc-install/libexec/gcc/x86_64-unknown-linux-gnu/4.8.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /home/regehr/z/compiler-source/gcc/configure
--enable-languages=c,c++ CC='clang -w -fcatch-undefined-behavior' CXX='clang++
-w -fcatch-undefined-behavior' --prefix=/home/regehr/z/checked-gcc-install
--disable-bootstrap
Thread model: posix
gcc version 4.8.0 20120714 (experimental) (GCC)
IOC tool:
http://embed.cs.utah.edu/ioc/
Defects:
ARITHMETIC UNDEFINED at </home/regehr/z/compiler-source/gcc/gcc/diagnostic.c,
(244:28)> : Op: -, Reason : Signed Subtraction Overflow, BINARY OPERATION: left
(int32): 2147483647 right (int32): -1
ARITHMETIC UNDEFINED at </home/regehr/z/compiler-source/gcc/gcc/double-int.c,
(158:21)> : Op: *, Reason : Signed Multiplication Overflow, BINARY OPERATION:
left (int64): 4294967295 right (int64): 4294967295
ARITHMETIC UNDEFINED at </home/regehr/z/compiler-source/gcc/gcc/double-int.c,
(613:46)> : Op: <<, Reason : Unsigned Left Shift: Right operand is negative or
is greater than or equal to the width of the promoted left operand, BINARY
OPERATION: left (uint64): 2 right (uint64): 4294967295
ARITHMETIC UNDEFINED at </home/regehr/z/compiler-source/gcc/gcc/expr.c,
(3832:20)> : Op: -, Reason : Signed Subtraction Overflow, UNARY OPERATION: left
(int64): 0 right (int64): -9223372036854775808
ARITHMETIC UNDEFINED at
</home/regehr/z/compiler-source/gcc/gcc/ipa-inline-analysis.c, (2347:22)> : Op:
*, Reason : Signed Multiplication Overflow, BINARY OPERATION: left (int32):
256348 right (int32): 10000
ARITHMETIC UNDEFINED at </home/regehr/z/compiler-source/gcc/gcc/simplify-rtx.c,
(69:24)> : Op: -, Reason : Signed Subtraction Overflow, UNARY OPERATION: left
(int64): 0 right (int64): -9223372036854775808
ARITHMETIC UNDEFINED at </home/regehr/z/compiler-source/gcc/gcc/stor-layout.c,
(2563:52)> : Op: -, Reason : Signed Subtraction Overflow, BINARY OPERATION:
left (int64): -9223372036854775808 right (int64): 1
ARITHMETIC UNDEFINED at </home/regehr/z/compiler-source/gcc/gcc/stor-layout.c,
(2566:54)> : Op: -, Reason : Signed Subtraction Overflow, BINARY OPERATION:
left (int64): -9223372036854775808 right (int64): 1
ARITHMETIC UNDEFINED at
</home/regehr/z/compiler-source/gcc/gcc/tree-ssa-loop-ivopts.c, (3450:10)> :
Op: -, Reason : Signed Subtraction Overflow, UNARY OPERATION: left (int64): 0
right (int64): -9223372036854775808
ARITHMETIC UNDEFINED at
</home/regehr/z/compiler-source/gcc/gcc/tree-ssa-loop-ivopts.c, (3459:35)> :
Op: -, Reason : Signed Subtraction Overflow, BINARY OPERATION: left (int64):
-9223372036854775808 right (int64): 1
ARITHMETIC UNDEFINED at </home/regehr/z/compiler-source/gcc/gcc/tree.c,
(1889:37)> : Op: -, Reason : Signed Subtraction Overflow, BINARY OPERATION:
left (int64): -9223372036854775808 right (int64): 1