[Chapel Merge] Improve squashing of conservative gcc warnings

Branch: refs/heads/master
Revision: bc9d7ad
Author: bradcray
Log Message:

Merge pull request #17812 from bradcray/squash-bounds-warnings-more

Improve squashing of conservative gcc warnings

[reviewed by @dmk42 and @ronawho]

When casting int64 values to uint64 values in our generated code,
we have traditionally run into, and then squashed, warnings from
specific versions of gcc in our generated code caused by its concern
that we might be using a negative or too-big number in doing a memcpy()
or the like. This has become something of a game of whack-a-mole
where we hit a case, and then squash it for a specific version of gcc,
then run into another one in the future. For example, see PRs #16204
and #6467.

This started happening this past weekend using gcc 10 and -O on some
of our systems where the integer value that the C compiler was complaining
about was received from another locale vs. a chpl_comm_get, so its value
couldn't possibly be known to the C compiler. I was initially guessing that
this was due to my .size->int changes (e.g., #17628), and it may have been,
yet the String / Bytes code that was causing the complaints didn't particularly
change as a result of these efforts. I then found that I could reproduce a
similar issue using gcc-10 on my Mac compiling with -O as far back as 1.24.1
for hello world (see details below).

I also don't have any sense that we've ever received positive benefit from
these gcc warnings, particularly given the amount of bounds checking that
we do by default.

For those reasons, in this PR, I've:

  • combined a few squashings of -Wno-string-overflow that were pinned to
    gcc (actually g++) versions 7 and 9
  • switched to turning them on for any post-7 gcc version
  • switched the Makefile check from checking the g++ version to the gcc version
    since we use the latter for compiling generated code
  • added a similar -Wno-array-bounds squashing to that conditional, which was
    necessary to quiet the hello world test on my Mac mentioned above
  • forked another gcc-7-only setting out into its own conditional to avoid sharing
    a comment that doesn't apply to it and keep it specific to gcc 7.
As far back as Chapel's 1.24.1 sources, if I use homebrew gcc-10, and compile hello world with:
CHPL_COMM=gasnet
CHPL_COMM_SUBSTRATE=mpi   # though I think this doesn't matter
chpl test/release/examples/hello.chpl  --no-devel --cc-warnings -O --no-inline

I get warnings like:

In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/string.h:190,
                 from /Users/bradc/chapel2/chapel/runtime/include/chpltypes.h:31,
                 from /Users/bradc/chapel2/chapel/runtime/include/chpl-string-support.h:34,
                 from /Users/bradc/chapel2/chapel/runtime/include/chpl-string.h:24,
                 from /var/folders/69/jbk0y4q95lq8xhhwpqgwf_rh000bxs/T//chpl-bradc-17407.deleteme/chpl_str_config.c:1,
                 from /var/folders/69/jbk0y4q95lq8xhhwpqgwf_rh000bxs/T//chpl-bradc-17407.deleteme/_main.c:1:
In function 'chpl_memmove',
    inlined from 'chpl_gen_comm_get' at /Users/bradc/chapel2/chapel/runtime/include/chpl-comm-compiler-macros.h:55:5,
    inlined from 'on_fn_chpl19.isra' at /var/folders/69/jbk0y4q95lq8xhhwpqgwf_rh000bxs/T//chpl-bradc-17407.deleteme/ByteBufferHelpers.c:44:1:
/Users/bradc/chapel2/chapel/runtime/include/chpl-mem.h:166:10: error: '__builtin_memmove' specified bound between 9223372036854775808 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]
  166 |   return memmove(dest, src, num);
      >          ^~~~~~~
In function 'chpl_memmove',
    inlined from 'chpl_gen_comm_get' at /Users/bradc/chapel2/chapel/runtime/include/chpl-comm-compiler-macros.h:55:5,
    inlined from 'doConcat_chpl' at /var/folders/69/jbk0y4q95lq8xhhwpqgwf_rh000bxs/T//chpl-bradc-17407.deleteme/ByteBufferHelpers.c:44:1:
/Users/bradc/chapel2/chapel/runtime/include/chpl-mem.h:166:10: error: '__builtin_memmove' specified bound between 9223372036854775808 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]
  166 |   return memmove(dest, src, num);
      >          ^~~~~~~
cc1: all warnings being treated as errors

If I throw -Wno-stringop-overflow, the errors shift to:

In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/string.h:190,
                 from /Users/bradc/chapel2/chapel/runtime/include/chpltypes.h:31,
                 from /Users/bradc/chapel2/chapel/runtime/include/chpl-string-support.h:34,
                 from /Users/bradc/chapel2/chapel/runtime/include/chpl-string.h:24,
                 from /var/folders/69/jbk0y4q95lq8xhhwpqgwf_rh000bxs/T//chpl-bradc-17624.deleteme/chpl_str_config.c:1,
                 from /var/folders/69/jbk0y4q95lq8xhhwpqgwf_rh000bxs/T//chpl-bradc-17624.deleteme/_main.c:1:
In function 'chpl_memmove',
    inlined from 'chpl_gen_comm_get' at /Users/bradc/chapel2/chapel/runtime/include/chpl-comm-compiler-macros.h:55:5,
    inlined from 'on_fn_chpl19.isra' at /var/folders/69/jbk0y4q95lq8xhhwpqgwf_rh000bxs/T//chpl-bradc-17624.deleteme/ByteBufferHelpers.c:44:1:
/Users/bradc/chapel2/chapel/runtime/include/chpl-mem.h:166:10: error: '__builtin_memmove' pointer overflow between offset 0 and size [-9223372036854775808, -1] [-Werror=array-bounds]
  166 |   return memmove(dest, src, num);
      >          ^~~~~~~
In function 'chpl_memmove',
    inlined from 'chpl_gen_comm_get' at /Users/bradc/chapel2/chapel/runtime/include/chpl-comm-compiler-macros.h:55:5,
    inlined from 'doConcat_chpl' at /var/folders/69/jbk0y4q95lq8xhhwpqgwf_rh000bxs/T//chpl-bradc-17624.deleteme/ByteBufferHelpers.c:44:1:
/Users/bradc/chapel2/chapel/runtime/include/chpl-mem.h:166:10: error: '__builtin_memmove' pointer overflow between offset 0 and size [-9223372036854775808, -1] [-Werror=array-bounds]
  166 |   return memmove(dest, src, num);
      >          ^~~~~~~
cc1: all warnings being treated as errors
make: *** [/var/folders/69/jbk0y4q95lq8xhhwpqgwf_rh000bxs/T//chpl-bradc-17624.deleteme/hello.tmp] Error 1
error: compiling generated source
Modified Files:
M make/compiler/Makefile.gnu

Compare: https://github.com/chapel-lang/chapel/compare/37cee926f37f...bc9d7adc81f1