Skip to content

Commit 276c017

Browse files
committed
Use -Wno-format-truncation and -Wno-stringop-truncation, if available.
This back-patches commit e716585 into out-of-support branches, pursuant to newly-established project policy. The point is to suppress scary-looking warnings so that people building these branches needn't expend brain cells verifying that it's safe to ignore the warnings. Also back-patch the adjacent test from commit 73b416b (Suppress clang's unhelpful gripes about -pthread switch being unused) and the necessary autoconf macro from fdea253. Discussion: https://postgr.es/m/d0316012-ece7-7b7e-2d36-9c38cb77cb3b@enterprisedb.com
1 parent a4061ee commit 276c017

File tree

3 files changed

+240
-0
lines changed

3 files changed

+240
-0
lines changed

config/c-compiler.m4

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,31 @@ undefine([Ac_cachevar])dnl
158158

159159

160160

161+
# PGAC_PROG_CC_VAR_OPT
162+
# -----------------------
163+
# Given a variable name and a string, check if the compiler supports
164+
# the string as a command-line option. If it does, add the string to
165+
# the given variable.
166+
AC_DEFUN([PGAC_PROG_CC_VAR_OPT],
167+
[define([Ac_cachevar], [AS_TR_SH([pgac_cv_prog_cc_cflags_$2])])dnl
168+
AC_CACHE_CHECK([whether $CC supports $2], [Ac_cachevar],
169+
[pgac_save_CFLAGS=$CFLAGS
170+
CFLAGS="$pgac_save_CFLAGS $2"
171+
ac_save_c_werror_flag=$ac_c_werror_flag
172+
ac_c_werror_flag=yes
173+
_AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
174+
[Ac_cachevar=yes],
175+
[Ac_cachevar=no])
176+
ac_c_werror_flag=$ac_save_c_werror_flag
177+
CFLAGS="$pgac_save_CFLAGS"])
178+
if test x"$Ac_cachevar" = x"yes"; then
179+
$1="${$1} $2"
180+
fi
181+
undefine([Ac_cachevar])dnl
182+
])# PGAC_PROG_CC_CFLAGS_OPT
183+
184+
185+
161186
# PGAC_PROG_CC_LDFLAGS_OPT
162187
# ------------------------
163188
# Given a string, check if the compiler supports the string as a

configure

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4407,6 +4407,202 @@ if test x"$pgac_cv_prog_cc_cflags__fexcess_precision_standard" = x"yes"; then
44074407
CFLAGS="$CFLAGS -fexcess-precision=standard"
44084408
fi
44094409

4410+
# We want to suppress clang's unhelpful unused-command-line-argument warnings
4411+
# but gcc won't complain about unrecognized -Wno-foo switches, so we have to
4412+
# test for the positive form and if that works, add the negative form
4413+
NOT_THE_CFLAGS=""
4414+
{ $as_echo "$as_me:$LINENO: checking whether $CC supports -Wunused-command-line-argument" >&5
4415+
$as_echo_n "checking whether $CC supports -Wunused-command-line-argument... " >&6; }
4416+
if test "${pgac_cv_prog_cc_cflags__Wunused_command_line_argument+set}" = set; then
4417+
$as_echo_n "(cached) " >&6
4418+
else
4419+
pgac_save_CFLAGS=$CFLAGS
4420+
CFLAGS="$pgac_save_CFLAGS -Wunused-command-line-argument"
4421+
ac_save_c_werror_flag=$ac_c_werror_flag
4422+
ac_c_werror_flag=yes
4423+
cat >conftest.$ac_ext <<_ACEOF
4424+
/* confdefs.h. */
4425+
_ACEOF
4426+
cat confdefs.h >>conftest.$ac_ext
4427+
cat >>conftest.$ac_ext <<_ACEOF
4428+
/* end confdefs.h. */
4429+
4430+
int
4431+
main ()
4432+
{
4433+
4434+
;
4435+
return 0;
4436+
}
4437+
_ACEOF
4438+
rm -f conftest.$ac_objext
4439+
if { (ac_try="$ac_compile"
4440+
case "(($ac_try" in
4441+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
4442+
*) ac_try_echo=$ac_try;;
4443+
esac
4444+
eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
4445+
$as_echo "$ac_try_echo") >&5
4446+
(eval "$ac_compile") 2>conftest.er1
4447+
ac_status=$?
4448+
grep -v '^ *+' conftest.er1 >conftest.err
4449+
rm -f conftest.er1
4450+
cat conftest.err >&5
4451+
$as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
4452+
(exit $ac_status); } && {
4453+
test -z "$ac_c_werror_flag" ||
4454+
test ! -s conftest.err
4455+
} && test -s conftest.$ac_objext; then
4456+
pgac_cv_prog_cc_cflags__Wunused_command_line_argument=yes
4457+
else
4458+
$as_echo "$as_me: failed program was:" >&5
4459+
sed 's/^/| /' conftest.$ac_ext >&5
4460+
4461+
pgac_cv_prog_cc_cflags__Wunused_command_line_argument=no
4462+
fi
4463+
4464+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
4465+
ac_c_werror_flag=$ac_save_c_werror_flag
4466+
CFLAGS="$pgac_save_CFLAGS"
4467+
fi
4468+
{ $as_echo "$as_me:$LINENO: result: $pgac_cv_prog_cc_cflags__Wunused_command_line_argument" >&5
4469+
$as_echo "$pgac_cv_prog_cc_cflags__Wunused_command_line_argument" >&6; }
4470+
if test x"$pgac_cv_prog_cc_cflags__Wunused_command_line_argument" = x"yes"; then
4471+
NOT_THE_CFLAGS="${NOT_THE_CFLAGS} -Wunused-command-line-argument"
4472+
fi
4473+
4474+
if test -n "$NOT_THE_CFLAGS"; then
4475+
CFLAGS="$CFLAGS -Wno-unused-command-line-argument"
4476+
fi
4477+
# Similarly disable useless truncation warnings from gcc 8+
4478+
NOT_THE_CFLAGS=""
4479+
{ $as_echo "$as_me:$LINENO: checking whether $CC supports -Wformat-truncation" >&5
4480+
$as_echo_n "checking whether $CC supports -Wformat-truncation... " >&6; }
4481+
if test "${pgac_cv_prog_cc_cflags__Wformat_truncation+set}" = set; then
4482+
$as_echo_n "(cached) " >&6
4483+
else
4484+
pgac_save_CFLAGS=$CFLAGS
4485+
CFLAGS="$pgac_save_CFLAGS -Wformat-truncation"
4486+
ac_save_c_werror_flag=$ac_c_werror_flag
4487+
ac_c_werror_flag=yes
4488+
cat >conftest.$ac_ext <<_ACEOF
4489+
/* confdefs.h. */
4490+
_ACEOF
4491+
cat confdefs.h >>conftest.$ac_ext
4492+
cat >>conftest.$ac_ext <<_ACEOF
4493+
/* end confdefs.h. */
4494+
4495+
int
4496+
main ()
4497+
{
4498+
4499+
;
4500+
return 0;
4501+
}
4502+
_ACEOF
4503+
rm -f conftest.$ac_objext
4504+
if { (ac_try="$ac_compile"
4505+
case "(($ac_try" in
4506+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
4507+
*) ac_try_echo=$ac_try;;
4508+
esac
4509+
eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
4510+
$as_echo "$ac_try_echo") >&5
4511+
(eval "$ac_compile") 2>conftest.er1
4512+
ac_status=$?
4513+
grep -v '^ *+' conftest.er1 >conftest.err
4514+
rm -f conftest.er1
4515+
cat conftest.err >&5
4516+
$as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
4517+
(exit $ac_status); } && {
4518+
test -z "$ac_c_werror_flag" ||
4519+
test ! -s conftest.err
4520+
} && test -s conftest.$ac_objext; then
4521+
pgac_cv_prog_cc_cflags__Wformat_truncation=yes
4522+
else
4523+
$as_echo "$as_me: failed program was:" >&5
4524+
sed 's/^/| /' conftest.$ac_ext >&5
4525+
4526+
pgac_cv_prog_cc_cflags__Wformat_truncation=no
4527+
fi
4528+
4529+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
4530+
ac_c_werror_flag=$ac_save_c_werror_flag
4531+
CFLAGS="$pgac_save_CFLAGS"
4532+
fi
4533+
{ $as_echo "$as_me:$LINENO: result: $pgac_cv_prog_cc_cflags__Wformat_truncation" >&5
4534+
$as_echo "$pgac_cv_prog_cc_cflags__Wformat_truncation" >&6; }
4535+
if test x"$pgac_cv_prog_cc_cflags__Wformat_truncation" = x"yes"; then
4536+
NOT_THE_CFLAGS="${NOT_THE_CFLAGS} -Wformat-truncation"
4537+
fi
4538+
4539+
if test -n "$NOT_THE_CFLAGS"; then
4540+
CFLAGS="$CFLAGS -Wno-format-truncation"
4541+
fi
4542+
NOT_THE_CFLAGS=""
4543+
{ $as_echo "$as_me:$LINENO: checking whether $CC supports -Wstringop-truncation" >&5
4544+
$as_echo_n "checking whether $CC supports -Wstringop-truncation... " >&6; }
4545+
if test "${pgac_cv_prog_cc_cflags__Wstringop_truncation+set}" = set; then
4546+
$as_echo_n "(cached) " >&6
4547+
else
4548+
pgac_save_CFLAGS=$CFLAGS
4549+
CFLAGS="$pgac_save_CFLAGS -Wstringop-truncation"
4550+
ac_save_c_werror_flag=$ac_c_werror_flag
4551+
ac_c_werror_flag=yes
4552+
cat >conftest.$ac_ext <<_ACEOF
4553+
/* confdefs.h. */
4554+
_ACEOF
4555+
cat confdefs.h >>conftest.$ac_ext
4556+
cat >>conftest.$ac_ext <<_ACEOF
4557+
/* end confdefs.h. */
4558+
4559+
int
4560+
main ()
4561+
{
4562+
4563+
;
4564+
return 0;
4565+
}
4566+
_ACEOF
4567+
rm -f conftest.$ac_objext
4568+
if { (ac_try="$ac_compile"
4569+
case "(($ac_try" in
4570+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
4571+
*) ac_try_echo=$ac_try;;
4572+
esac
4573+
eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
4574+
$as_echo "$ac_try_echo") >&5
4575+
(eval "$ac_compile") 2>conftest.er1
4576+
ac_status=$?
4577+
grep -v '^ *+' conftest.er1 >conftest.err
4578+
rm -f conftest.er1
4579+
cat conftest.err >&5
4580+
$as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
4581+
(exit $ac_status); } && {
4582+
test -z "$ac_c_werror_flag" ||
4583+
test ! -s conftest.err
4584+
} && test -s conftest.$ac_objext; then
4585+
pgac_cv_prog_cc_cflags__Wstringop_truncation=yes
4586+
else
4587+
$as_echo "$as_me: failed program was:" >&5
4588+
sed 's/^/| /' conftest.$ac_ext >&5
4589+
4590+
pgac_cv_prog_cc_cflags__Wstringop_truncation=no
4591+
fi
4592+
4593+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
4594+
ac_c_werror_flag=$ac_save_c_werror_flag
4595+
CFLAGS="$pgac_save_CFLAGS"
4596+
fi
4597+
{ $as_echo "$as_me:$LINENO: result: $pgac_cv_prog_cc_cflags__Wstringop_truncation" >&5
4598+
$as_echo "$pgac_cv_prog_cc_cflags__Wstringop_truncation" >&6; }
4599+
if test x"$pgac_cv_prog_cc_cflags__Wstringop_truncation" = x"yes"; then
4600+
NOT_THE_CFLAGS="${NOT_THE_CFLAGS} -Wstringop-truncation"
4601+
fi
4602+
4603+
if test -n "$NOT_THE_CFLAGS"; then
4604+
CFLAGS="$CFLAGS -Wno-stringop-truncation"
4605+
fi
44104606
elif test "$ICC" = yes; then
44114607
# Intel's compiler has a bug/misoptimization in checking for
44124608
# division by NAN (NaN == 0), -mp1 fixes it, so add it to the CFLAGS.

configure.in

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,25 @@ if test "$GCC" = yes -a "$ICC" = no; then
426426
PGAC_PROG_CC_CFLAGS_OPT([-fwrapv])
427427
# Disable FP optimizations that cause various errors on gcc 4.5+ or maybe 4.6+
428428
PGAC_PROG_CC_CFLAGS_OPT([-fexcess-precision=standard])
429+
# We want to suppress clang's unhelpful unused-command-line-argument warnings
430+
# but gcc won't complain about unrecognized -Wno-foo switches, so we have to
431+
# test for the positive form and if that works, add the negative form
432+
NOT_THE_CFLAGS=""
433+
PGAC_PROG_CC_VAR_OPT(NOT_THE_CFLAGS, [-Wunused-command-line-argument])
434+
if test -n "$NOT_THE_CFLAGS"; then
435+
CFLAGS="$CFLAGS -Wno-unused-command-line-argument"
436+
fi
437+
# Similarly disable useless truncation warnings from gcc 8+
438+
NOT_THE_CFLAGS=""
439+
PGAC_PROG_CC_VAR_OPT(NOT_THE_CFLAGS, [-Wformat-truncation])
440+
if test -n "$NOT_THE_CFLAGS"; then
441+
CFLAGS="$CFLAGS -Wno-format-truncation"
442+
fi
443+
NOT_THE_CFLAGS=""
444+
PGAC_PROG_CC_VAR_OPT(NOT_THE_CFLAGS, [-Wstringop-truncation])
445+
if test -n "$NOT_THE_CFLAGS"; then
446+
CFLAGS="$CFLAGS -Wno-stringop-truncation"
447+
fi
429448
elif test "$ICC" = yes; then
430449
# Intel's compiler has a bug/misoptimization in checking for
431450
# division by NAN (NaN == 0), -mp1 fixes it, so add it to the CFLAGS.

0 commit comments

Comments
 (0)