* Paul Eggert wrote on Wed, Dec 20, 2006 at 08:38:56AM CET:
> Here's a patch that would allow programs to avoid running afoul of
> unexpected gotchas with signed integer overflow when being compiled by
> GCC using the default compilation flags. It also attempts to document
> the issue. Comments?
Thank you for writing the patch, a couple of nits inline.
I do wonder whether we should proceed with this patch, or wait a bit:
if GCC gets a warning flag, that may help in fixing the code that this
concerns. Even if we apply this, I'd prefer to also have code fixed
that relies on LIA-1 now but wouldn't need to in principle.
> +To work around this problem, Autoconf-generated @command{configure}
> +scripts by default compile with @option{-O2 -fwrapv} when using
I assume you left out -g here on purpose to avoid having to repeat those
semantics. Dunno if it will confuse the casual reader.
> [EMAIL PROTECTED] (assuming @acronym{GCC} is modern enough to support
> [EMAIL PROTECTED]). The @option{-fwrapv} option requires @command{GCC}
> +to implement wraparound arithmetic for signed integers. In some cases
> [EMAIL PROTECTED] makes code faster and in some cases slower, but the
> +important thing is that it leads to better-defined behavior that matches
> +longstanding C tradition, so it is less likely to break existing code.
long-standing?
> --- lib/autoconf/c.m4 7 Dec 2006 06:39:40 -0000 1.242
> +++ lib/autoconf/c.m4 20 Dec 2006 07:37:12 -0000
> @@ -598,15 +598,15 @@
> ac_c_werror_flag=$ac_save_c_werror_flag])
> if test "$ac_test_CFLAGS" = set; then
> CFLAGS=$ac_save_CFLAGS
> -elif test $ac_cv_prog_cc_g = yes; then
> - if test "$GCC" = yes; then
> - CFLAGS="-g -O2"
> - else
> - CFLAGS="-g"
> - fi
> else
> if test "$GCC" = yes; then
> - CFLAGS="-O2"
> + CFLAGS='-O2 -fwrapv'
> + _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [], [CFLAGS='-O2'])
> + if test $ac_cv_prog_cc_g = yes; then
> + CFLAGS="-g $CFLAGS"
> + fi
> + elif test $ac_cv_prog_cc_g = yes; then
> + CFLAGS='-g'
> else
> CFLAGS=
> fi
This will cause configure to set -fwrapv with icc, although it does not
understand it:
| icc: Command line warning: ignoring unknown option '-fwrapv'
Same for CXX. It's the known issue with icc (without -no-gcc) claiming
to be GCC. We could ignore it: if need be, icc will (have to) adapt,
otherwise the user can always use CC='icc -no-gcc'. Or we could test
for empty (or unchanged wrt. omitted -fwrapv) warning output, but that
has its own set of glitches. I'd prefer ignoring.
Cheers,
Ralf