Skip to content

Commit 899b9c3

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 d19d354 commit 899b9c3

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

configure

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3058,6 +3058,60 @@ else
30583058
echo "$as_me: failed program was:" >&5
30593059
sed 's/^/| /' conftest.$ac_ext >&5
30603060

3061+
CFLAGS="$pgac_save_CFLAGS"
3062+
echo "$as_me:$LINENO: result: no" >&5
3063+
echo "${ECHO_T}no" >&6
3064+
fi
3065+
rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
3066+
3067+
# Disable optimizations that assume no overflow; needed for gcc 4.3+
3068+
echo "$as_me:$LINENO: checking if $CC supports -fwrapv" >&5
3069+
echo $ECHO_N "checking if $CC supports -fwrapv... $ECHO_C" >&6
3070+
pgac_save_CFLAGS=$CFLAGS
3071+
CFLAGS="$pgac_save_CFLAGS -fwrapv"
3072+
cat >conftest.$ac_ext <<_ACEOF
3073+
/* confdefs.h. */
3074+
_ACEOF
3075+
cat confdefs.h >>conftest.$ac_ext
3076+
cat >>conftest.$ac_ext <<_ACEOF
3077+
/* end confdefs.h. */
3078+
3079+
int
3080+
main ()
3081+
{
3082+
3083+
;
3084+
return 0;
3085+
}
3086+
_ACEOF
3087+
rm -f conftest.$ac_objext
3088+
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
3089+
(eval $ac_compile) 2>conftest.er1
3090+
ac_status=$?
3091+
grep -v '^ *+' conftest.er1 >conftest.err
3092+
rm -f conftest.er1
3093+
cat conftest.err >&5
3094+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
3095+
(exit $ac_status); } &&
3096+
{ ac_try='test -z "$ac_c_werror_flag"
3097+
|| test ! -s conftest.err'
3098+
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
3099+
(eval $ac_try) 2>&5
3100+
ac_status=$?
3101+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
3102+
(exit $ac_status); }; } &&
3103+
{ ac_try='test -s conftest.$ac_objext'
3104+
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
3105+
(eval $ac_try) 2>&5
3106+
ac_status=$?
3107+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
3108+
(exit $ac_status); }; }; then
3109+
echo "$as_me:$LINENO: result: yes" >&5
3110+
echo "${ECHO_T}yes" >&6
3111+
else
3112+
echo "$as_me: failed program was:" >&5
3113+
sed 's/^/| /' conftest.$ac_ext >&5
3114+
30613115
CFLAGS="$pgac_save_CFLAGS"
30623116
echo "$as_me:$LINENO: result: no" >&5
30633117
echo "${ECHO_T}no" >&6

configure.in

Lines changed: 3 additions & 1 deletion
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.546.2.1 2008/02/24 05:22:03 tgl Exp $
2+
dnl $PostgreSQL: pgsql/configure.in,v 1.546.2.2 2008/03/10 21:50:23 tgl Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -290,6 +290,8 @@ if test "$GCC" = yes -a "$ICC" = no; then
290290
PGAC_PROG_CC_CFLAGS_OPT([-Wendif-labels])
291291
# Disable strict-aliasing rules; needed for gcc 3.3+
292292
PGAC_PROG_CC_CFLAGS_OPT([-fno-strict-aliasing])
293+
# Disable optimizations that assume no overflow; needed for gcc 4.3+
294+
PGAC_PROG_CC_CFLAGS_OPT([-fwrapv])
293295
elif test "$ICC" = yes; then
294296
# Intel's compiler has a bug/misoptimization in checking for
295297
# division by NAN (NaN == 0), -mp1 fixes it, so add it to the CFLAGS.

0 commit comments

Comments
 (0)