Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fe83a3f

Browse files
committed
Use -fwrapv in CFLAGS if we are using a version of gcc that accepts this flag.
This prevents compiler optimizations that assume overflow won't occur, which breaks numerous overflow tests that we need to have working. It is known that gcc 4.3 causes problems and possible that 4.1 does. Per my proposal of some time ago and a recent report from Kris Jurka. Backpatch as far as 8.0, which is as far as the patch conveniently goes. 7.x was pretty short of overflow tests anyway, so it may not matter there, even assuming that anyone cares whether 7.x builds on recent gcc.
1 parent f0828b2 commit fe83a3f

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

configure

+50
Original file line numberDiff line numberDiff line change
@@ -3563,6 +3563,56 @@ sed 's/^/| /' conftest.$ac_ext >&5
35633563
echo "${ECHO_T}no" >&6; }
35643564
fi
35653565

3566+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
3567+
3568+
# Disable optimizations that assume no overflow; needed for gcc 4.3+
3569+
{ echo "$as_me:$LINENO: checking if $CC supports -fwrapv" >&5
3570+
echo $ECHO_N "checking if $CC supports -fwrapv... $ECHO_C" >&6; }
3571+
pgac_save_CFLAGS=$CFLAGS
3572+
CFLAGS="$pgac_save_CFLAGS -fwrapv"
3573+
cat >conftest.$ac_ext <<_ACEOF
3574+
/* confdefs.h. */
3575+
_ACEOF
3576+
cat confdefs.h >>conftest.$ac_ext
3577+
cat >>conftest.$ac_ext <<_ACEOF
3578+
/* end confdefs.h. */
3579+
3580+
int
3581+
main ()
3582+
{
3583+
3584+
;
3585+
return 0;
3586+
}
3587+
_ACEOF
3588+
rm -f conftest.$ac_objext
3589+
if { (ac_try="$ac_compile"
3590+
case "(($ac_try" in
3591+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
3592+
*) ac_try_echo=$ac_try;;
3593+
esac
3594+
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
3595+
(eval "$ac_compile") 2>conftest.er1
3596+
ac_status=$?
3597+
grep -v '^ *+' conftest.er1 >conftest.err
3598+
rm -f conftest.er1
3599+
cat conftest.err >&5
3600+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
3601+
(exit $ac_status); } && {
3602+
test -z "$ac_c_werror_flag" ||
3603+
test ! -s conftest.err
3604+
} && test -s conftest.$ac_objext; then
3605+
{ echo "$as_me:$LINENO: result: yes" >&5
3606+
echo "${ECHO_T}yes" >&6; }
3607+
else
3608+
echo "$as_me: failed program was:" >&5
3609+
sed 's/^/| /' conftest.$ac_ext >&5
3610+
3611+
CFLAGS="$pgac_save_CFLAGS"
3612+
{ echo "$as_me:$LINENO: result: no" >&5
3613+
echo "${ECHO_T}no" >&6; }
3614+
fi
3615+
35663616
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
35673617

35683618
elif test "$ICC" = yes; then

configure.in

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl Process this file with autoconf to produce a configure script.
2-
dnl $PostgreSQL: pgsql/configure.in,v 1.553 2008/03/10 20:06:27 tgl Exp $
2+
dnl $PostgreSQL: pgsql/configure.in,v 1.554 2008/03/10 21:50:16 tgl Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -284,6 +284,8 @@ if test "$GCC" = yes -a "$ICC" = no; then
284284
PGAC_PROG_CC_CFLAGS_OPT([-Wendif-labels])
285285
# Disable strict-aliasing rules; needed for gcc 3.3+
286286
PGAC_PROG_CC_CFLAGS_OPT([-fno-strict-aliasing])
287+
# Disable optimizations that assume no overflow; needed for gcc 4.3+
288+
PGAC_PROG_CC_CFLAGS_OPT([-fwrapv])
287289
elif test "$ICC" = yes; then
288290
# Intel's compiler has a bug/misoptimization in checking for
289291
# division by NAN (NaN == 0), -mp1 fixes it, so add it to the CFLAGS.

0 commit comments

Comments
 (0)