On Tue, 2004-10-19 at 11:59, Neil Conway wrote:
> -Wpointer-arith might be worth enabling. I'll add it to the GCC CFLAGS
> in the next patch I send in.
Attached is a revised patch. Changes:
- add -Wpointer-arith to the default CFLAGS when using GCC
- add an AC macro AC_PROG_CC_CFLAGS_OPT that checks if $CC supports the
specified command-line option and adds it to the CFLAGS if it does
- replace the hard-coded test for -fno-strict-aliasing with
AC_PROG_CC_CFLAGS, and use AC_PROG_CC_CFLAGS to check for
-Wendif-labels, -Wdeclaration-after-statement, and
-Wold-style-definition
Barring any objections, I will apply this to CVS tomorrow.
BTW, since we're on the topic of compiler options, is there a reason we
don't use -g3 with GCC when --enable-debug is specified? It seems worth
using to me.
-Neil
Index: configure
===================================================================
RCS file: /var/lib/cvs/pgsql/configure,v
retrieving revision 1.402
diff -c -r1.402 configure
*** configure 15 Oct 2004 05:10:53 -0000 1.402
--- configure 19 Oct 2004 06:32:31 -0000
***************
*** 2433,2454 ****
fi
# Need to specify -fno-strict-aliasing too in case it's gcc 3.3 or later.
! echo "$as_me:$LINENO: checking how to turn off strict aliasing in $CC" >&5
! echo $ECHO_N "checking how to turn off strict aliasing in $CC... $ECHO_C" >&6
! if test "${pgac_cv_prog_cc_no_strict_aliasing+set}" = set; then
! echo $ECHO_N "(cached) $ECHO_C" >&6
else
! pgac_save_CFLAGS=$CFLAGS
if test "$GCC" = yes; then
! pgac_try="-fno-strict-aliasing"
else
! # Maybe fill in later...
! pgac_try=
fi
! for pgac_flag in $pgac_try; do
! CFLAGS="$pgac_save_CFLAGS $pgac_flag"
! cat >conftest.$ac_ext <<_ACEOF
#line $LINENO "configure"
#include "confdefs.h"
--- 2433,2539 ----
fi
# Need to specify -fno-strict-aliasing too in case it's gcc 3.3 or later.
! echo "$as_me:$LINENO: checking if $CC supports -fno-strict-aliasing" >&5
! echo $ECHO_N "checking if $CC supports -fno-strict-aliasing... $ECHO_C" >&6
! pgac_save_CFLAGS=$CFLAGS
! CFLAGS="$pgac_save_CFLAGS -fno-strict-aliasing"
! cat >conftest.$ac_ext <<_ACEOF
! #line $LINENO "configure"
! #include "confdefs.h"
!
! #ifdef F77_DUMMY_MAIN
! # ifdef __cplusplus
! extern "C"
! # endif
! int F77_DUMMY_MAIN() { return 1; }
! #endif
! int
! main ()
! {
!
! ;
! return 0;
! }
! _ACEOF
! rm -f conftest.$ac_objext
! if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
! (eval $ac_compile) 2>&5
! ac_status=$?
! echo "$as_me:$LINENO: \$? = $ac_status" >&5
! (exit $ac_status); } &&
! { ac_try='test -s conftest.$ac_objext'
! { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
! (eval $ac_try) 2>&5
! ac_status=$?
! echo "$as_me:$LINENO: \$? = $ac_status" >&5
! (exit $ac_status); }; }; then
! echo "$as_me:$LINENO: result: yes" >&5
! echo "${ECHO_T}yes" >&6
else
! echo "$as_me: failed program was:" >&5
! cat conftest.$ac_ext >&5
! CFLAGS="$pgac_save_CFLAGS"
! echo "$as_me:$LINENO: result: no" >&5
! echo "${ECHO_T}no" >&6
! fi
! rm -f conftest.$ac_objext conftest.$ac_ext
!
!
if test "$GCC" = yes; then
! CFLAGS="$CFLAGS -Wall -Wmissing-prototypes -Wpointer-arith"
!
! # Recent versions of GCC support some useful warning options. Check
! # whether they are supported, and add them to CFLAGS if so.
! echo "$as_me:$LINENO: checking if $CC supports -Wdeclaration-after-statement" >&5
! echo $ECHO_N "checking if $CC supports -Wdeclaration-after-statement... $ECHO_C" >&6
! pgac_save_CFLAGS=$CFLAGS
! CFLAGS="$pgac_save_CFLAGS -Wdeclaration-after-statement"
! cat >conftest.$ac_ext <<_ACEOF
! #line $LINENO "configure"
! #include "confdefs.h"
!
! #ifdef F77_DUMMY_MAIN
! # ifdef __cplusplus
! extern "C"
! # endif
! int F77_DUMMY_MAIN() { return 1; }
! #endif
! int
! main ()
! {
!
! ;
! return 0;
! }
! _ACEOF
! rm -f conftest.$ac_objext
! if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
! (eval $ac_compile) 2>&5
! ac_status=$?
! echo "$as_me:$LINENO: \$? = $ac_status" >&5
! (exit $ac_status); } &&
! { ac_try='test -s conftest.$ac_objext'
! { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
! (eval $ac_try) 2>&5
! ac_status=$?
! echo "$as_me:$LINENO: \$? = $ac_status" >&5
! (exit $ac_status); }; }; then
! echo "$as_me:$LINENO: result: yes" >&5
! echo "${ECHO_T}yes" >&6
else
! echo "$as_me: failed program was:" >&5
! cat conftest.$ac_ext >&5
! CFLAGS="$pgac_save_CFLAGS"
! echo "$as_me:$LINENO: result: no" >&5
! echo "${ECHO_T}no" >&6
fi
+ rm -f conftest.$ac_objext conftest.$ac_ext
! echo "$as_me:$LINENO: checking if $CC supports -Wold-style-definition" >&5
! echo $ECHO_N "checking if $CC supports -Wold-style-definition... $ECHO_C" >&6
! pgac_save_CFLAGS=$CFLAGS
! CFLAGS="$pgac_save_CFLAGS -Wold-style-definition"
! cat >conftest.$ac_ext <<_ACEOF
#line $LINENO "configure"
#include "confdefs.h"
***************
*** 2478,2500 ****
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
! pgac_cv_prog_cc_no_strict_aliasing=$pgac_try
! break
else
echo "$as_me: failed program was:" >&5
cat conftest.$ac_ext >&5
fi
rm -f conftest.$ac_objext conftest.$ac_ext
- done
! CFLAGS=$pgac_save_CFLAGS
fi
! echo "$as_me:$LINENO: result: $pgac_cv_prog_cc_no_strict_aliasing" >&5
! echo "${ECHO_T}$pgac_cv_prog_cc_no_strict_aliasing" >&6
- if test x"$pgac_cv_prog_cc_no_strict_aliasing" != x""; then
- CFLAGS="$CFLAGS $pgac_cv_prog_cc_no_strict_aliasing"
fi
# supply -g if --enable-debug
--- 2563,2624 ----
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
! echo "$as_me:$LINENO: result: yes" >&5
! echo "${ECHO_T}yes" >&6
else
echo "$as_me: failed program was:" >&5
cat conftest.$ac_ext >&5
+ CFLAGS="$pgac_save_CFLAGS"
+ echo "$as_me:$LINENO: result: no" >&5
+ echo "${ECHO_T}no" >&6
fi
rm -f conftest.$ac_objext conftest.$ac_ext
! echo "$as_me:$LINENO: checking if $CC supports -Wendif-labels" >&5
! echo $ECHO_N "checking if $CC supports -Wendif-labels... $ECHO_C" >&6
! pgac_save_CFLAGS=$CFLAGS
! CFLAGS="$pgac_save_CFLAGS -Wendif-labels"
! cat >conftest.$ac_ext <<_ACEOF
! #line $LINENO "configure"
! #include "confdefs.h"
!
! #ifdef F77_DUMMY_MAIN
! # ifdef __cplusplus
! extern "C"
! # endif
! int F77_DUMMY_MAIN() { return 1; }
! #endif
! int
! main ()
! {
+ ;
+ return 0;
+ }
+ _ACEOF
+ rm -f conftest.$ac_objext
+ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ echo "$as_me:$LINENO: result: yes" >&5
+ echo "${ECHO_T}yes" >&6
+ else
+ echo "$as_me: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ CFLAGS="$pgac_save_CFLAGS"
+ echo "$as_me:$LINENO: result: no" >&5
+ echo "${ECHO_T}no" >&6
fi
! rm -f conftest.$ac_objext conftest.$ac_ext
fi
# supply -g if --enable-debug
Index: configure.in
===================================================================
RCS file: /var/lib/cvs/pgsql/configure.in,v
retrieving revision 1.381
diff -c -r1.381 configure.in
*** configure.in 15 Oct 2004 05:10:59 -0000 1.381
--- configure.in 19 Oct 2004 06:18:42 -0000
***************
*** 251,257 ****
fi
# Need to specify -fno-strict-aliasing too in case it's gcc 3.3 or later.
! PGAC_PROG_CC_NO_STRICT_ALIASING
# supply -g if --enable-debug
if test "$enable_debug" = yes && test "$ac_cv_prog_cc_g" = yes; then
--- 251,267 ----
fi
# Need to specify -fno-strict-aliasing too in case it's gcc 3.3 or later.
! PGAC_PROG_CC_CFLAGS_OPT([-fno-strict-aliasing])
!
! if test "$GCC" = yes; then
! CFLAGS="$CFLAGS -Wall -Wmissing-prototypes -Wpointer-arith"
!
! # Recent versions of GCC support some useful warning options. Check
! # whether they are supported, and add them to CFLAGS if so.
! PGAC_PROG_CC_CFLAGS_OPT([-Wdeclaration-after-statement])
! PGAC_PROG_CC_CFLAGS_OPT([-Wold-style-definition])
! PGAC_PROG_CC_CFLAGS_OPT([-Wendif-labels])
! fi
# supply -g if --enable-debug
if test "$enable_debug" = yes && test "$ac_cv_prog_cc_g" = yes; then
Index: config/c-compiler.m4
===================================================================
RCS file: /var/lib/cvs/pgsql/config/c-compiler.m4,v
retrieving revision 1.12
diff -c -r1.12 c-compiler.m4
*** config/c-compiler.m4 2 Feb 2004 04:07:18 -0000 1.12
--- config/c-compiler.m4 19 Oct 2004 06:32:16 -0000
***************
*** 121,155 ****
fi
fi])# PGAC_C_FUNCNAME_SUPPORT
!
! # PGAC_PROG_CC_NO_STRICT_ALIASING
! # -------------------------------
! # Find out how to turn off strict aliasing in the C compiler.
! AC_DEFUN([PGAC_PROG_CC_NO_STRICT_ALIASING],
! [AC_CACHE_CHECK([how to turn off strict aliasing in $CC],
! pgac_cv_prog_cc_no_strict_aliasing,
! [pgac_save_CFLAGS=$CFLAGS
! if test "$GCC" = yes; then
! pgac_try="-fno-strict-aliasing"
! else
! # Maybe fill in later...
! pgac_try=
! fi
!
! for pgac_flag in $pgac_try; do
! CFLAGS="$pgac_save_CFLAGS $pgac_flag"
! _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
! [pgac_cv_prog_cc_no_strict_aliasing=$pgac_try
! break])
! done
!
! CFLAGS=$pgac_save_CFLAGS
! ])
!
! if test x"$pgac_cv_prog_cc_no_strict_aliasing" != x""; then
! CFLAGS="$CFLAGS $pgac_cv_prog_cc_no_strict_aliasing"
! fi])# PGAC_PROG_CC_NO_STRICT_ALIASING
!
# The below backpatches the following Autoconf change:
#
--- 121,139 ----
fi
fi])# PGAC_C_FUNCNAME_SUPPORT
! # PGAC_PROG_CC_CFLAGS_OPT
! # -----------------------
! # Given a string, check if the compiler supports the string as a
! # command-line option. If it does, add the string to CFLAGS.
! AC_DEFUN([PGAC_PROG_CC_CFLAGS_OPT],
! [AC_MSG_CHECKING([if $CC supports $1])
! pgac_save_CFLAGS=$CFLAGS
! CFLAGS="$pgac_save_CFLAGS $1"
! _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
! AC_MSG_RESULT(yes),
! [CFLAGS="$pgac_save_CFLAGS"
! AC_MSG_RESULT(no)])
! ])# PGAC_PROG_CC_CFLAGS_OPT
# The below backpatches the following Autoconf change:
#
Index: src/Makefile.global.in
===================================================================
RCS file: /var/lib/cvs/pgsql/src/Makefile.global.in,v
retrieving revision 1.203
diff -c -r1.203 Makefile.global.in
*** src/Makefile.global.in 15 Oct 2004 17:10:58 -0000 1.203
--- src/Makefile.global.in 19 Oct 2004 05:29:03 -0000
***************
*** 184,192 ****
CC = @CC@
GCC = @GCC@
CFLAGS = @CFLAGS@
- ifeq ($(GCC), yes)
- CFLAGS += -Wall -Wmissing-prototypes -Wmissing-declarations
- endif
# Kind-of compilers
--- 184,189 ----
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])