Difference between revisions of "Helpful Compiler Flags for Testing"

From Mpich
Jump to: navigation, search
(documenting compiler flags i've used to track down 32 bit overflows.)
(No difference)

Revision as of 20:48, 11 September 2018

Starting a list of compiler warnings, facilities, and other features that might help you track down that strange bug

Integer overflow

We have many spots where the product of one or more 64 bit values is stored in a 32 bit value. What happens when the product is larger than 32 bits? usually the result is a very large negative number and a very confused MPICH library

(clang only) generates a compile-time warning for any case where, as the name implies, a 64 bit value is getting jammed into a 32 bit value. If you can prove this is fine, an explicit cast will silence this warning
(clang only) Will generate a run-time error whenever an integer is treated strangely. From the manual: <quote> Checks for undefined or suspicious integer behavior (e.g. unsigned integer overflow). Enables signed-integer-overflow, unsigned-integer-overflow, shift, integer-divide-by-zero, and implicit-integer-truncation.</quote>. May require you to add -lubsan to your LIBS variable when you configure mpich. Will complain about unsigned int overflowing, too. Though it can be surprising, this is defined behavior, and the places in MPICH that overflow an unsigned int do so deliberately. -fno-sanitize=unsigned-integer-overflow will eliminate the warnings for the seven or so locations where this happens.