Skip to content

Commit 276517a

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 ac1c745 commit 276517a

File tree

2 files changed

+222
-18
lines changed

2 files changed

+222
-18
lines changed

configure

+185-9
Original file line numberDiff line numberDiff line change
@@ -5251,7 +5251,7 @@ else
52515251
fi
52525252

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

62906290

6291-
# We want to suppress clang's unhelpful unused-command-line-argument warnings
6292-
# but gcc won't complain about unrecognized -Wno-foo switches, so we have to
6293-
# test for the positive form and if that works, add the negative form
6291+
#
6292+
# The following tests want to suppress various unhelpful warnings by adding
6293+
# -Wno-foo switches. But gcc won't complain about unrecognized -Wno-foo
6294+
# switches, so we have to test for the positive form and if that works,
6295+
# add the negative form. Note that tests of this form typically need to
6296+
# be duplicated in the BITCODE_CFLAGS setup stanza below.
6297+
#
6298+
# Suppress clang's unhelpful unused-command-line-argument warnings.
62946299
NOT_THE_CFLAGS=""
62956300
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -Wunused-command-line-argument, for NOT_THE_CFLAGS" >&5
62966301
$as_echo_n "checking whether ${CC} supports -Wunused-command-line-argument, for NOT_THE_CFLAGS... " >&6; }
@@ -6335,8 +6340,7 @@ fi
63356340
CFLAGS="$CFLAGS -Wno-unused-command-line-argument"
63366341
fi
63376342
# Remove clang 12+'s compound-token-split-by-macro, as this causes a lot
6338-
# of warnings when building plperl because of Perl. Like previously, test
6339-
# for the positive form and add the negative form
6343+
# of warnings when building plperl because of usages in the Perl headers.
63406344
NOT_THE_CFLAGS=""
63416345
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -Wcompound-token-split-by-macro, for NOT_THE_CFLAGS" >&5
63426346
$as_echo_n "checking whether ${CC} supports -Wcompound-token-split-by-macro, for NOT_THE_CFLAGS... " >&6; }
@@ -6936,9 +6940,12 @@ fi
69366940

69376941

69386942

6939-
# Determine flags used to emit bitcode for JIT inlining. Need to test
6940-
# for behaviour changing compiler flags, to keep compatibility with
6941-
# compiler used for normal postgres code.
6943+
# Determine flags used to emit bitcode for JIT inlining.
6944+
# 1. We must duplicate any behaviour-changing compiler flags used above,
6945+
# to keep compatibility with the compiler used for normal Postgres code.
6946+
# 2. We don't bother to duplicate extra-warnings switches --- seeing a
6947+
# warning in the main build is enough.
6948+
# 3. But we must duplicate -Wno-warning flags, else we'll see those anyway.
69426949
if test "$with_llvm" = yes ; then
69436950
CLANGXX="$CLANG -xc++"
69446951

@@ -7206,6 +7213,175 @@ if test x"$pgac_cv_prog_CLANGXX_cxxflags__fexcess_precision_standard" = x"yes";
72067213
BITCODE_CXXFLAGS="${BITCODE_CXXFLAGS} -fexcess-precision=standard"
72077214
fi
72087215

7216+
7217+
NOT_THE_CFLAGS=""
7218+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CLANG} supports -Wunused-command-line-argument, for NOT_THE_CFLAGS" >&5
7219+
$as_echo_n "checking whether ${CLANG} supports -Wunused-command-line-argument, for NOT_THE_CFLAGS... " >&6; }
7220+
if ${pgac_cv_prog_CLANG_cflags__Wunused_command_line_argument+:} false; then :
7221+
$as_echo_n "(cached) " >&6
7222+
else
7223+
pgac_save_CFLAGS=$CFLAGS
7224+
pgac_save_CC=$CC
7225+
CC=${CLANG}
7226+
CFLAGS="${NOT_THE_CFLAGS} -Wunused-command-line-argument"
7227+
ac_save_c_werror_flag=$ac_c_werror_flag
7228+
ac_c_werror_flag=yes
7229+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
7230+
/* end confdefs.h. */
7231+
7232+
int
7233+
main ()
7234+
{
7235+
7236+
;
7237+
return 0;
7238+
}
7239+
_ACEOF
7240+
if ac_fn_c_try_compile "$LINENO"; then :
7241+
pgac_cv_prog_CLANG_cflags__Wunused_command_line_argument=yes
7242+
else
7243+
pgac_cv_prog_CLANG_cflags__Wunused_command_line_argument=no
7244+
fi
7245+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
7246+
ac_c_werror_flag=$ac_save_c_werror_flag
7247+
CFLAGS="$pgac_save_CFLAGS"
7248+
CC="$pgac_save_CC"
7249+
fi
7250+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CLANG_cflags__Wunused_command_line_argument" >&5
7251+
$as_echo "$pgac_cv_prog_CLANG_cflags__Wunused_command_line_argument" >&6; }
7252+
if test x"$pgac_cv_prog_CLANG_cflags__Wunused_command_line_argument" = x"yes"; then
7253+
NOT_THE_CFLAGS="${NOT_THE_CFLAGS} -Wunused-command-line-argument"
7254+
fi
7255+
7256+
if test -n "$NOT_THE_CFLAGS"; then
7257+
BITCODE_CFLAGS="$BITCODE_CFLAGS -Wno-unused-command-line-argument"
7258+
fi
7259+
NOT_THE_CFLAGS=""
7260+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CLANG} supports -Wcompound-token-split-by-macro, for NOT_THE_CFLAGS" >&5
7261+
$as_echo_n "checking whether ${CLANG} supports -Wcompound-token-split-by-macro, for NOT_THE_CFLAGS... " >&6; }
7262+
if ${pgac_cv_prog_CLANG_cflags__Wcompound_token_split_by_macro+:} false; then :
7263+
$as_echo_n "(cached) " >&6
7264+
else
7265+
pgac_save_CFLAGS=$CFLAGS
7266+
pgac_save_CC=$CC
7267+
CC=${CLANG}
7268+
CFLAGS="${NOT_THE_CFLAGS} -Wcompound-token-split-by-macro"
7269+
ac_save_c_werror_flag=$ac_c_werror_flag
7270+
ac_c_werror_flag=yes
7271+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
7272+
/* end confdefs.h. */
7273+
7274+
int
7275+
main ()
7276+
{
7277+
7278+
;
7279+
return 0;
7280+
}
7281+
_ACEOF
7282+
if ac_fn_c_try_compile "$LINENO"; then :
7283+
pgac_cv_prog_CLANG_cflags__Wcompound_token_split_by_macro=yes
7284+
else
7285+
pgac_cv_prog_CLANG_cflags__Wcompound_token_split_by_macro=no
7286+
fi
7287+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
7288+
ac_c_werror_flag=$ac_save_c_werror_flag
7289+
CFLAGS="$pgac_save_CFLAGS"
7290+
CC="$pgac_save_CC"
7291+
fi
7292+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CLANG_cflags__Wcompound_token_split_by_macro" >&5
7293+
$as_echo "$pgac_cv_prog_CLANG_cflags__Wcompound_token_split_by_macro" >&6; }
7294+
if test x"$pgac_cv_prog_CLANG_cflags__Wcompound_token_split_by_macro" = x"yes"; then
7295+
NOT_THE_CFLAGS="${NOT_THE_CFLAGS} -Wcompound-token-split-by-macro"
7296+
fi
7297+
7298+
if test -n "$NOT_THE_CFLAGS"; then
7299+
BITCODE_CFLAGS="$BITCODE_CFLAGS -Wno-compound-token-split-by-macro"
7300+
fi
7301+
NOT_THE_CFLAGS=""
7302+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CLANG} supports -Wformat-truncation, for NOT_THE_CFLAGS" >&5
7303+
$as_echo_n "checking whether ${CLANG} supports -Wformat-truncation, for NOT_THE_CFLAGS... " >&6; }
7304+
if ${pgac_cv_prog_CLANG_cflags__Wformat_truncation+:} false; then :
7305+
$as_echo_n "(cached) " >&6
7306+
else
7307+
pgac_save_CFLAGS=$CFLAGS
7308+
pgac_save_CC=$CC
7309+
CC=${CLANG}
7310+
CFLAGS="${NOT_THE_CFLAGS} -Wformat-truncation"
7311+
ac_save_c_werror_flag=$ac_c_werror_flag
7312+
ac_c_werror_flag=yes
7313+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
7314+
/* end confdefs.h. */
7315+
7316+
int
7317+
main ()
7318+
{
7319+
7320+
;
7321+
return 0;
7322+
}
7323+
_ACEOF
7324+
if ac_fn_c_try_compile "$LINENO"; then :
7325+
pgac_cv_prog_CLANG_cflags__Wformat_truncation=yes
7326+
else
7327+
pgac_cv_prog_CLANG_cflags__Wformat_truncation=no
7328+
fi
7329+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
7330+
ac_c_werror_flag=$ac_save_c_werror_flag
7331+
CFLAGS="$pgac_save_CFLAGS"
7332+
CC="$pgac_save_CC"
7333+
fi
7334+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CLANG_cflags__Wformat_truncation" >&5
7335+
$as_echo "$pgac_cv_prog_CLANG_cflags__Wformat_truncation" >&6; }
7336+
if test x"$pgac_cv_prog_CLANG_cflags__Wformat_truncation" = x"yes"; then
7337+
NOT_THE_CFLAGS="${NOT_THE_CFLAGS} -Wformat-truncation"
7338+
fi
7339+
7340+
if test -n "$NOT_THE_CFLAGS"; then
7341+
BITCODE_CFLAGS="$BITCODE_CFLAGS -Wno-format-truncation"
7342+
fi
7343+
NOT_THE_CFLAGS=""
7344+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CLANG} supports -Wstringop-truncation, for NOT_THE_CFLAGS" >&5
7345+
$as_echo_n "checking whether ${CLANG} supports -Wstringop-truncation, for NOT_THE_CFLAGS... " >&6; }
7346+
if ${pgac_cv_prog_CLANG_cflags__Wstringop_truncation+:} false; then :
7347+
$as_echo_n "(cached) " >&6
7348+
else
7349+
pgac_save_CFLAGS=$CFLAGS
7350+
pgac_save_CC=$CC
7351+
CC=${CLANG}
7352+
CFLAGS="${NOT_THE_CFLAGS} -Wstringop-truncation"
7353+
ac_save_c_werror_flag=$ac_c_werror_flag
7354+
ac_c_werror_flag=yes
7355+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
7356+
/* end confdefs.h. */
7357+
7358+
int
7359+
main ()
7360+
{
7361+
7362+
;
7363+
return 0;
7364+
}
7365+
_ACEOF
7366+
if ac_fn_c_try_compile "$LINENO"; then :
7367+
pgac_cv_prog_CLANG_cflags__Wstringop_truncation=yes
7368+
else
7369+
pgac_cv_prog_CLANG_cflags__Wstringop_truncation=no
7370+
fi
7371+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
7372+
ac_c_werror_flag=$ac_save_c_werror_flag
7373+
CFLAGS="$pgac_save_CFLAGS"
7374+
CC="$pgac_save_CC"
7375+
fi
7376+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CLANG_cflags__Wstringop_truncation" >&5
7377+
$as_echo "$pgac_cv_prog_CLANG_cflags__Wstringop_truncation" >&6; }
7378+
if test x"$pgac_cv_prog_CLANG_cflags__Wstringop_truncation" = x"yes"; then
7379+
NOT_THE_CFLAGS="${NOT_THE_CFLAGS} -Wstringop-truncation"
7380+
fi
7381+
7382+
if test -n "$NOT_THE_CFLAGS"; then
7383+
BITCODE_CFLAGS="$BITCODE_CFLAGS -Wno-stringop-truncation"
7384+
fi
72097385
fi
72107386

72117387
# supply -g if --enable-debug

configure.ac

+37-9
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ else
440440
fi
441441

442442
# When generating bitcode (for inlining) we always want to use -O2
443-
# even when --enable-debug is specified. The bitcode it's not going to
443+
# even when --enable-debug is specified. The bitcode is not going to
444444
# be used for line-by-line debugging, and JIT inlining doesn't work
445445
# without at least -O1 (otherwise clang will emit 'noinline'
446446
# attributes everywhere), which is bad for testing. Still allow the
@@ -522,17 +522,21 @@ if test "$GCC" = yes -a "$ICC" = no; then
522522
PGAC_PROG_CC_VAR_OPT(CFLAGS_UNROLL_LOOPS, [-funroll-loops])
523523
# Optimization flags for specific files that benefit from vectorization
524524
PGAC_PROG_CC_VAR_OPT(CFLAGS_VECTORIZE, [-ftree-vectorize])
525-
# We want to suppress clang's unhelpful unused-command-line-argument warnings
526-
# but gcc won't complain about unrecognized -Wno-foo switches, so we have to
527-
# test for the positive form and if that works, add the negative form
525+
#
526+
# The following tests want to suppress various unhelpful warnings by adding
527+
# -Wno-foo switches. But gcc won't complain about unrecognized -Wno-foo
528+
# switches, so we have to test for the positive form and if that works,
529+
# add the negative form. Note that tests of this form typically need to
530+
# be duplicated in the BITCODE_CFLAGS setup stanza below.
531+
#
532+
# Suppress clang's unhelpful unused-command-line-argument warnings.
528533
NOT_THE_CFLAGS=""
529534
PGAC_PROG_CC_VAR_OPT(NOT_THE_CFLAGS, [-Wunused-command-line-argument])
530535
if test -n "$NOT_THE_CFLAGS"; then
531536
CFLAGS="$CFLAGS -Wno-unused-command-line-argument"
532537
fi
533538
# Remove clang 12+'s compound-token-split-by-macro, as this causes a lot
534-
# of warnings when building plperl because of Perl. Like previously, test
535-
# for the positive form and add the negative form
539+
# of warnings when building plperl because of usages in the Perl headers.
536540
NOT_THE_CFLAGS=""
537541
PGAC_PROG_CC_VAR_OPT(NOT_THE_CFLAGS, [-Wcompound-token-split-by-macro])
538542
if test -n "$NOT_THE_CFLAGS"; then
@@ -573,9 +577,12 @@ fi
573577
AC_SUBST(CFLAGS_UNROLL_LOOPS)
574578
AC_SUBST(CFLAGS_VECTORIZE)
575579

576-
# Determine flags used to emit bitcode for JIT inlining. Need to test
577-
# for behaviour changing compiler flags, to keep compatibility with
578-
# compiler used for normal postgres code.
580+
# Determine flags used to emit bitcode for JIT inlining.
581+
# 1. We must duplicate any behaviour-changing compiler flags used above,
582+
# to keep compatibility with the compiler used for normal Postgres code.
583+
# 2. We don't bother to duplicate extra-warnings switches --- seeing a
584+
# warning in the main build is enough.
585+
# 3. But we must duplicate -Wno-warning flags, else we'll see those anyway.
579586
if test "$with_llvm" = yes ; then
580587
CLANGXX="$CLANG -xc++"
581588

@@ -585,6 +592,27 @@ if test "$with_llvm" = yes ; then
585592
PGAC_PROG_VARCXX_VARFLAGS_OPT(CLANGXX, BITCODE_CXXFLAGS, [-fwrapv])
586593
PGAC_PROG_VARCC_VARFLAGS_OPT(CLANG, BITCODE_CFLAGS, [-fexcess-precision=standard])
587594
PGAC_PROG_VARCXX_VARFLAGS_OPT(CLANGXX, BITCODE_CXXFLAGS, [-fexcess-precision=standard])
595+
596+
NOT_THE_CFLAGS=""
597+
PGAC_PROG_VARCC_VARFLAGS_OPT(CLANG, NOT_THE_CFLAGS, [-Wunused-command-line-argument])
598+
if test -n "$NOT_THE_CFLAGS"; then
599+
BITCODE_CFLAGS="$BITCODE_CFLAGS -Wno-unused-command-line-argument"
600+
fi
601+
NOT_THE_CFLAGS=""
602+
PGAC_PROG_VARCC_VARFLAGS_OPT(CLANG, NOT_THE_CFLAGS, [-Wcompound-token-split-by-macro])
603+
if test -n "$NOT_THE_CFLAGS"; then
604+
BITCODE_CFLAGS="$BITCODE_CFLAGS -Wno-compound-token-split-by-macro"
605+
fi
606+
NOT_THE_CFLAGS=""
607+
PGAC_PROG_VARCC_VARFLAGS_OPT(CLANG, NOT_THE_CFLAGS, [-Wformat-truncation])
608+
if test -n "$NOT_THE_CFLAGS"; then
609+
BITCODE_CFLAGS="$BITCODE_CFLAGS -Wno-format-truncation"
610+
fi
611+
NOT_THE_CFLAGS=""
612+
PGAC_PROG_VARCC_VARFLAGS_OPT(CLANG, NOT_THE_CFLAGS, [-Wstringop-truncation])
613+
if test -n "$NOT_THE_CFLAGS"; then
614+
BITCODE_CFLAGS="$BITCODE_CFLAGS -Wno-stringop-truncation"
615+
fi
588616
fi
589617

590618
# supply -g if --enable-debug

0 commit comments

Comments
 (0)