Skip to content

Commit e9e387a

Browse files
committed
Disable -faggressive-loop-optimizations in gcc 4.8+ for pre-9.2 branches.
With this optimization flag enabled, recent versions of gcc can generate incorrect code that assumes variable-length arrays (such as oidvector) are actually fixed-length because they're embedded in some larger struct. The known instance of this problem was fixed in 9.2 and up by commit 8137f2c and followon work, which hides actually-variable-length catalog fields from the compiler altogether. And we plan to gradually convert variable-length fields to official "flexible array member" notation over time, which should prevent this type of bug from reappearing as gcc gets smarter. We're not going to try to back-port those changes into older branches, though, so apply this band-aid instead. Andres Freund
1 parent 8e0b7d2 commit e9e387a

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

configure

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4250,6 +4250,58 @@ sed 's/^/| /' conftest.$ac_ext >&5
42504250
$as_echo "no" >&6; }
42514251
fi
42524252

4253+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
4254+
4255+
# Disable loop optimizations that get confused by variable-length struct
4256+
# declarations in gcc 4.8+
4257+
{ $as_echo "$as_me:$LINENO: checking if $CC supports -fno-aggressive-loop-optimizations" >&5
4258+
$as_echo_n "checking if $CC supports -fno-aggressive-loop-optimizations... " >&6; }
4259+
pgac_save_CFLAGS=$CFLAGS
4260+
CFLAGS="$pgac_save_CFLAGS -fno-aggressive-loop-optimizations"
4261+
cat >conftest.$ac_ext <<_ACEOF
4262+
/* confdefs.h. */
4263+
_ACEOF
4264+
cat confdefs.h >>conftest.$ac_ext
4265+
cat >>conftest.$ac_ext <<_ACEOF
4266+
/* end confdefs.h. */
4267+
4268+
int
4269+
main ()
4270+
{
4271+
4272+
;
4273+
return 0;
4274+
}
4275+
_ACEOF
4276+
rm -f conftest.$ac_objext
4277+
if { (ac_try="$ac_compile"
4278+
case "(($ac_try" in
4279+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
4280+
*) ac_try_echo=$ac_try;;
4281+
esac
4282+
eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
4283+
$as_echo "$ac_try_echo") >&5
4284+
(eval "$ac_compile") 2>conftest.er1
4285+
ac_status=$?
4286+
grep -v '^ *+' conftest.er1 >conftest.err
4287+
rm -f conftest.er1
4288+
cat conftest.err >&5
4289+
$as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
4290+
(exit $ac_status); } && {
4291+
test -z "$ac_c_werror_flag" ||
4292+
test ! -s conftest.err
4293+
} && test -s conftest.$ac_objext; then
4294+
{ $as_echo "$as_me:$LINENO: result: yes" >&5
4295+
$as_echo "yes" >&6; }
4296+
else
4297+
$as_echo "$as_me: failed program was:" >&5
4298+
sed 's/^/| /' conftest.$ac_ext >&5
4299+
4300+
CFLAGS="$pgac_save_CFLAGS"
4301+
{ $as_echo "$as_me:$LINENO: result: no" >&5
4302+
$as_echo "no" >&6; }
4303+
fi
4304+
42534305
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
42544306

42554307
elif test "$ICC" = yes; then

configure.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,9 @@ if test "$GCC" = yes -a "$ICC" = no; then
435435
PGAC_PROG_CC_CFLAGS_OPT([-fwrapv])
436436
# Disable FP optimizations that cause various errors on gcc 4.5+ or maybe 4.6+
437437
PGAC_PROG_CC_CFLAGS_OPT([-fexcess-precision=standard])
438+
# Disable loop optimizations that get confused by variable-length struct
439+
# declarations in gcc 4.8+
440+
PGAC_PROG_CC_CFLAGS_OPT([-fno-aggressive-loop-optimizations])
438441
elif test "$ICC" = yes; then
439442
# Intel's compiler has a bug/misoptimization in checking for
440443
# division by NAN (NaN == 0), -mp1 fixes it, so add it to the CFLAGS.

0 commit comments

Comments
 (0)