Skip to content

Commit dff01e4

Browse files
committed
Use appropriate -Wno-warning switches when compiling bitcode.
We use "clang" to compile bitcode files for LLVM inlining. That might be different from the build's main C compiler, so it needs its own set of compiler flags. To simplify configure, we don't bother adding any -W switches to that flag set; there's little need since the main build will show us any warnings. However, if we don't want to see unwanted warnings, we still have to add any -Wno-warning switches we'd normally use with clang. This escaped notice before commit 9ff47ea, which tried to add -Wno-compound-token-split-by-macro; buildfarm animals using mismatched CC and CLANG still showed those warnings. I'm not sure why we never saw any effects from the lack of -Wno-unused-command-line-argument (maybe that's only activated by -Wall?). clang does not currently support -Wno-format-truncation or -Wno-stringop-truncation, although in the interests of future-proofing and consistency I included tests for those. Back-patch to v11 where we started building bitcode files. Discussion: https://postgr.es/m/2921539.1637254619@sss.pgh.pa.us
1 parent a414eb8 commit dff01e4

File tree

2 files changed

+222
-18
lines changed

2 files changed

+222
-18
lines changed

configure

Lines changed: 185 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5068,7 +5068,7 @@ else
50685068
fi
50695069

50705070
# When generating bitcode (for inlining) we always want to use -O2
5071-
# even when --enable-debug is specified. The bitcode it's not going to
5071+
# even when --enable-debug is specified. The bitcode is not going to
50725072
# be used for line-by-line debugging, and JIT inlining doesn't work
50735073
# without at least -O1 (otherwise clang will emit 'noinline'
50745074
# attributes everywhere), which is bad for testing. Still allow the
@@ -5778,9 +5778,14 @@ if test x"$pgac_cv_prog_CC_cflags__ftree_vectorize" = x"yes"; then
57785778
fi
57795779

57805780

5781-
# We want to suppress clang's unhelpful unused-command-line-argument warnings
5782-
# but gcc won't complain about unrecognized -Wno-foo switches, so we have to
5783-
# test for the positive form and if that works, add the negative form
5781+
#
5782+
# The following tests want to suppress various unhelpful warnings by adding
5783+
# -Wno-foo switches. But gcc won't complain about unrecognized -Wno-foo
5784+
# switches, so we have to test for the positive form and if that works,
5785+
# add the negative form. Note that tests of this form typically need to
5786+
# be duplicated in the BITCODE_CFLAGS setup stanza below.
5787+
#
5788+
# Suppress clang's unhelpful unused-command-line-argument warnings.
57845789
NOT_THE_CFLAGS=""
57855790
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -Wunused-command-line-argument, for NOT_THE_CFLAGS" >&5
57865791
$as_echo_n "checking whether ${CC} supports -Wunused-command-line-argument, for NOT_THE_CFLAGS... " >&6; }
@@ -5825,8 +5830,7 @@ fi
58255830
CFLAGS="$CFLAGS -Wno-unused-command-line-argument"
58265831
fi
58275832
# Remove clang 12+'s compound-token-split-by-macro, as this causes a lot
5828-
# of warnings when building plperl because of Perl. Like previously, test
5829-
# for the positive form and add the negative form
5833+
# of warnings when building plperl because of usages in the Perl headers.
58305834
NOT_THE_CFLAGS=""
58315835
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -Wcompound-token-split-by-macro, for NOT_THE_CFLAGS" >&5
58325836
$as_echo_n "checking whether ${CC} supports -Wcompound-token-split-by-macro, for NOT_THE_CFLAGS... " >&6; }
@@ -6425,9 +6429,12 @@ fi
64256429

64266430

64276431

6428-
# Determine flags used to emit bitcode for JIT inlining. Need to test
6429-
# for behaviour changing compiler flags, to keep compatibility with
6430-
# compiler used for normal postgres code.
6432+
# Determine flags used to emit bitcode for JIT inlining.
6433+
# 1. We must duplicate any behaviour-changing compiler flags used above,
6434+
# to keep compatibility with the compiler used for normal Postgres code.
6435+
# 2. We don't bother to duplicate extra-warnings switches --- seeing a
6436+
# warning in the main build is enough.
6437+
# 3. But we must duplicate -Wno-warning flags, else we'll see those anyway.
64316438
if test "$with_llvm" = yes ; then
64326439
CLANGXX="$CLANG -xc++"
64336440

@@ -6695,6 +6702,175 @@ if test x"$pgac_cv_prog_CLANGXX_cxxflags__fexcess_precision_standard" = x"yes";
66956702
BITCODE_CXXFLAGS="${BITCODE_CXXFLAGS} -fexcess-precision=standard"
66966703
fi
66976704

6705+
6706+
NOT_THE_CFLAGS=""
6707+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CLANG} supports -Wunused-command-line-argument, for NOT_THE_CFLAGS" >&5
6708+
$as_echo_n "checking whether ${CLANG} supports -Wunused-command-line-argument, for NOT_THE_CFLAGS... " >&6; }
6709+
if ${pgac_cv_prog_CLANG_cflags__Wunused_command_line_argument+:} false; then :
6710+
$as_echo_n "(cached) " >&6
6711+
else
6712+
pgac_save_CFLAGS=$CFLAGS
6713+
pgac_save_CC=$CC
6714+
CC=${CLANG}
6715+
CFLAGS="${NOT_THE_CFLAGS} -Wunused-command-line-argument"
6716+
ac_save_c_werror_flag=$ac_c_werror_flag
6717+
ac_c_werror_flag=yes
6718+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
6719+
/* end confdefs.h. */
6720+
6721+
int
6722+
main ()
6723+
{
6724+
6725+
;
6726+
return 0;
6727+
}
6728+
_ACEOF
6729+
if ac_fn_c_try_compile "$LINENO"; then :
6730+
pgac_cv_prog_CLANG_cflags__Wunused_command_line_argument=yes
6731+
else
6732+
pgac_cv_prog_CLANG_cflags__Wunused_command_line_argument=no
6733+
fi
6734+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
6735+
ac_c_werror_flag=$ac_save_c_werror_flag
6736+
CFLAGS="$pgac_save_CFLAGS"
6737+
CC="$pgac_save_CC"
6738+
fi
6739+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CLANG_cflags__Wunused_command_line_argument" >&5
6740+
$as_echo "$pgac_cv_prog_CLANG_cflags__Wunused_command_line_argument" >&6; }
6741+
if test x"$pgac_cv_prog_CLANG_cflags__Wunused_command_line_argument" = x"yes"; then
6742+
NOT_THE_CFLAGS="${NOT_THE_CFLAGS} -Wunused-command-line-argument"
6743+
fi
6744+
6745+
if test -n "$NOT_THE_CFLAGS"; then
6746+
BITCODE_CFLAGS="$BITCODE_CFLAGS -Wno-unused-command-line-argument"
6747+
fi
6748+
NOT_THE_CFLAGS=""
6749+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CLANG} supports -Wcompound-token-split-by-macro, for NOT_THE_CFLAGS" >&5
6750+
$as_echo_n "checking whether ${CLANG} supports -Wcompound-token-split-by-macro, for NOT_THE_CFLAGS... " >&6; }
6751+
if ${pgac_cv_prog_CLANG_cflags__Wcompound_token_split_by_macro+:} false; then :
6752+
$as_echo_n "(cached) " >&6
6753+
else
6754+
pgac_save_CFLAGS=$CFLAGS
6755+
pgac_save_CC=$CC
6756+
CC=${CLANG}
6757+
CFLAGS="${NOT_THE_CFLAGS} -Wcompound-token-split-by-macro"
6758+
ac_save_c_werror_flag=$ac_c_werror_flag
6759+
ac_c_werror_flag=yes
6760+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
6761+
/* end confdefs.h. */
6762+
6763+
int
6764+
main ()
6765+
{
6766+
6767+
;
6768+
return 0;
6769+
}
6770+
_ACEOF
6771+
if ac_fn_c_try_compile "$LINENO"; then :
6772+
pgac_cv_prog_CLANG_cflags__Wcompound_token_split_by_macro=yes
6773+
else
6774+
pgac_cv_prog_CLANG_cflags__Wcompound_token_split_by_macro=no
6775+
fi
6776+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
6777+
ac_c_werror_flag=$ac_save_c_werror_flag
6778+
CFLAGS="$pgac_save_CFLAGS"
6779+
CC="$pgac_save_CC"
6780+
fi
6781+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CLANG_cflags__Wcompound_token_split_by_macro" >&5
6782+
$as_echo "$pgac_cv_prog_CLANG_cflags__Wcompound_token_split_by_macro" >&6; }
6783+
if test x"$pgac_cv_prog_CLANG_cflags__Wcompound_token_split_by_macro" = x"yes"; then
6784+
NOT_THE_CFLAGS="${NOT_THE_CFLAGS} -Wcompound-token-split-by-macro"
6785+
fi
6786+
6787+
if test -n "$NOT_THE_CFLAGS"; then
6788+
BITCODE_CFLAGS="$BITCODE_CFLAGS -Wno-compound-token-split-by-macro"
6789+
fi
6790+
NOT_THE_CFLAGS=""
6791+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CLANG} supports -Wformat-truncation, for NOT_THE_CFLAGS" >&5
6792+
$as_echo_n "checking whether ${CLANG} supports -Wformat-truncation, for NOT_THE_CFLAGS... " >&6; }
6793+
if ${pgac_cv_prog_CLANG_cflags__Wformat_truncation+:} false; then :
6794+
$as_echo_n "(cached) " >&6
6795+
else
6796+
pgac_save_CFLAGS=$CFLAGS
6797+
pgac_save_CC=$CC
6798+
CC=${CLANG}
6799+
CFLAGS="${NOT_THE_CFLAGS} -Wformat-truncation"
6800+
ac_save_c_werror_flag=$ac_c_werror_flag
6801+
ac_c_werror_flag=yes
6802+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
6803+
/* end confdefs.h. */
6804+
6805+
int
6806+
main ()
6807+
{
6808+
6809+
;
6810+
return 0;
6811+
}
6812+
_ACEOF
6813+
if ac_fn_c_try_compile "$LINENO"; then :
6814+
pgac_cv_prog_CLANG_cflags__Wformat_truncation=yes
6815+
else
6816+
pgac_cv_prog_CLANG_cflags__Wformat_truncation=no
6817+
fi
6818+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
6819+
ac_c_werror_flag=$ac_save_c_werror_flag
6820+
CFLAGS="$pgac_save_CFLAGS"
6821+
CC="$pgac_save_CC"
6822+
fi
6823+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CLANG_cflags__Wformat_truncation" >&5
6824+
$as_echo "$pgac_cv_prog_CLANG_cflags__Wformat_truncation" >&6; }
6825+
if test x"$pgac_cv_prog_CLANG_cflags__Wformat_truncation" = x"yes"; then
6826+
NOT_THE_CFLAGS="${NOT_THE_CFLAGS} -Wformat-truncation"
6827+
fi
6828+
6829+
if test -n "$NOT_THE_CFLAGS"; then
6830+
BITCODE_CFLAGS="$BITCODE_CFLAGS -Wno-format-truncation"
6831+
fi
6832+
NOT_THE_CFLAGS=""
6833+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CLANG} supports -Wstringop-truncation, for NOT_THE_CFLAGS" >&5
6834+
$as_echo_n "checking whether ${CLANG} supports -Wstringop-truncation, for NOT_THE_CFLAGS... " >&6; }
6835+
if ${pgac_cv_prog_CLANG_cflags__Wstringop_truncation+:} false; then :
6836+
$as_echo_n "(cached) " >&6
6837+
else
6838+
pgac_save_CFLAGS=$CFLAGS
6839+
pgac_save_CC=$CC
6840+
CC=${CLANG}
6841+
CFLAGS="${NOT_THE_CFLAGS} -Wstringop-truncation"
6842+
ac_save_c_werror_flag=$ac_c_werror_flag
6843+
ac_c_werror_flag=yes
6844+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
6845+
/* end confdefs.h. */
6846+
6847+
int
6848+
main ()
6849+
{
6850+
6851+
;
6852+
return 0;
6853+
}
6854+
_ACEOF
6855+
if ac_fn_c_try_compile "$LINENO"; then :
6856+
pgac_cv_prog_CLANG_cflags__Wstringop_truncation=yes
6857+
else
6858+
pgac_cv_prog_CLANG_cflags__Wstringop_truncation=no
6859+
fi
6860+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
6861+
ac_c_werror_flag=$ac_save_c_werror_flag
6862+
CFLAGS="$pgac_save_CFLAGS"
6863+
CC="$pgac_save_CC"
6864+
fi
6865+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CLANG_cflags__Wstringop_truncation" >&5
6866+
$as_echo "$pgac_cv_prog_CLANG_cflags__Wstringop_truncation" >&6; }
6867+
if test x"$pgac_cv_prog_CLANG_cflags__Wstringop_truncation" = x"yes"; then
6868+
NOT_THE_CFLAGS="${NOT_THE_CFLAGS} -Wstringop-truncation"
6869+
fi
6870+
6871+
if test -n "$NOT_THE_CFLAGS"; then
6872+
BITCODE_CFLAGS="$BITCODE_CFLAGS -Wno-stringop-truncation"
6873+
fi
66986874
fi
66996875

67006876
# supply -g if --enable-debug

configure.in

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ else
435435
fi
436436

437437
# When generating bitcode (for inlining) we always want to use -O2
438-
# even when --enable-debug is specified. The bitcode it's not going to
438+
# even when --enable-debug is specified. The bitcode is not going to
439439
# be used for line-by-line debugging, and JIT inlining doesn't work
440440
# without at least -O1 (otherwise clang will emit 'noinline'
441441
# attributes everywhere), which is bad for testing. Still allow the
@@ -496,17 +496,21 @@ if test "$GCC" = yes -a "$ICC" = no; then
496496
# Optimization flags for specific files that benefit from vectorization
497497
PGAC_PROG_CC_VAR_OPT(CFLAGS_VECTOR, [-funroll-loops])
498498
PGAC_PROG_CC_VAR_OPT(CFLAGS_VECTOR, [-ftree-vectorize])
499-
# We want to suppress clang's unhelpful unused-command-line-argument warnings
500-
# but gcc won't complain about unrecognized -Wno-foo switches, so we have to
501-
# test for the positive form and if that works, add the negative form
499+
#
500+
# The following tests want to suppress various unhelpful warnings by adding
501+
# -Wno-foo switches. But gcc won't complain about unrecognized -Wno-foo
502+
# switches, so we have to test for the positive form and if that works,
503+
# add the negative form. Note that tests of this form typically need to
504+
# be duplicated in the BITCODE_CFLAGS setup stanza below.
505+
#
506+
# Suppress clang's unhelpful unused-command-line-argument warnings.
502507
NOT_THE_CFLAGS=""
503508
PGAC_PROG_CC_VAR_OPT(NOT_THE_CFLAGS, [-Wunused-command-line-argument])
504509
if test -n "$NOT_THE_CFLAGS"; then
505510
CFLAGS="$CFLAGS -Wno-unused-command-line-argument"
506511
fi
507512
# Remove clang 12+'s compound-token-split-by-macro, as this causes a lot
508-
# of warnings when building plperl because of Perl. Like previously, test
509-
# for the positive form and add the negative form
513+
# of warnings when building plperl because of usages in the Perl headers.
510514
NOT_THE_CFLAGS=""
511515
PGAC_PROG_CC_VAR_OPT(NOT_THE_CFLAGS, [-Wcompound-token-split-by-macro])
512516
if test -n "$NOT_THE_CFLAGS"; then
@@ -546,9 +550,12 @@ fi
546550

547551
AC_SUBST(CFLAGS_VECTOR)
548552

549-
# Determine flags used to emit bitcode for JIT inlining. Need to test
550-
# for behaviour changing compiler flags, to keep compatibility with
551-
# compiler used for normal postgres code.
553+
# Determine flags used to emit bitcode for JIT inlining.
554+
# 1. We must duplicate any behaviour-changing compiler flags used above,
555+
# to keep compatibility with the compiler used for normal Postgres code.
556+
# 2. We don't bother to duplicate extra-warnings switches --- seeing a
557+
# warning in the main build is enough.
558+
# 3. But we must duplicate -Wno-warning flags, else we'll see those anyway.
552559
if test "$with_llvm" = yes ; then
553560
CLANGXX="$CLANG -xc++"
554561

@@ -558,6 +565,27 @@ if test "$with_llvm" = yes ; then
558565
PGAC_PROG_VARCXX_VARFLAGS_OPT(CLANGXX, BITCODE_CXXFLAGS, [-fwrapv])
559566
PGAC_PROG_VARCC_VARFLAGS_OPT(CLANG, BITCODE_CFLAGS, [-fexcess-precision=standard])
560567
PGAC_PROG_VARCXX_VARFLAGS_OPT(CLANGXX, BITCODE_CXXFLAGS, [-fexcess-precision=standard])
568+
569+
NOT_THE_CFLAGS=""
570+
PGAC_PROG_VARCC_VARFLAGS_OPT(CLANG, NOT_THE_CFLAGS, [-Wunused-command-line-argument])
571+
if test -n "$NOT_THE_CFLAGS"; then
572+
BITCODE_CFLAGS="$BITCODE_CFLAGS -Wno-unused-command-line-argument"
573+
fi
574+
NOT_THE_CFLAGS=""
575+
PGAC_PROG_VARCC_VARFLAGS_OPT(CLANG, NOT_THE_CFLAGS, [-Wcompound-token-split-by-macro])
576+
if test -n "$NOT_THE_CFLAGS"; then
577+
BITCODE_CFLAGS="$BITCODE_CFLAGS -Wno-compound-token-split-by-macro"
578+
fi
579+
NOT_THE_CFLAGS=""
580+
PGAC_PROG_VARCC_VARFLAGS_OPT(CLANG, NOT_THE_CFLAGS, [-Wformat-truncation])
581+
if test -n "$NOT_THE_CFLAGS"; then
582+
BITCODE_CFLAGS="$BITCODE_CFLAGS -Wno-format-truncation"
583+
fi
584+
NOT_THE_CFLAGS=""
585+
PGAC_PROG_VARCC_VARFLAGS_OPT(CLANG, NOT_THE_CFLAGS, [-Wstringop-truncation])
586+
if test -n "$NOT_THE_CFLAGS"; then
587+
BITCODE_CFLAGS="$BITCODE_CFLAGS -Wno-stringop-truncation"
588+
fi
561589
fi
562590

563591
# supply -g if --enable-debug

0 commit comments

Comments
 (0)