autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: changing "configure" to default to "gcc -g -O2 -fwrapv ..."


From: Ralf Wildenhues
Subject: Re: changing "configure" to default to "gcc -g -O2 -fwrapv ..."
Date: Wed, 20 Dec 2006 13:33:49 +0100
User-agent: Mutt/1.5.13 (2006-11-01)

* 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.

> address@hidden (assuming @acronym{GCC} is modern enough to support
> address@hidden).  The @option{-fwrapv} option requires @command{GCC}
> +to implement wraparound arithmetic for signed integers.  In some cases
> address@hidden 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]