File: Helpful_Compiler_Flags_For_Testing.md

package info (click to toggle)
mpich 4.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 101,184 kB
  • sloc: ansic: 1,040,629; cpp: 82,270; javascript: 40,763; perl: 27,933; python: 16,041; sh: 14,676; xml: 14,418; f90: 12,916; makefile: 9,270; fortran: 8,046; java: 4,635; asm: 324; ruby: 103; awk: 27; lisp: 19; php: 8; sed: 4
file content (29 lines) | stat: -rw-r--r-- 1,818 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Helpful Compiler Flags For Testing

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

- `-Wshorten-64-to-32` - (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
- `-fsanitize=integer` - (Clang only) Will generate a run-time error whenever an integer is
  treated strangely. From the [manual](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html):
  "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." 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.
- `-fsanitize=signed-integer-overflow` - (GCC only) GCC's integer sanitizer does not have a general integer
  category like clang does, but you can get the case we most often care about with this flag.
- `-fsanitize=undefined` - (GCC and Clang) Very broad category of any undefined behavior. 
  Untested: if you try this, let me know how many sites are flagged.