On 10/12/2015 11:57 PM, Jeff Law wrote: >>> -#ifdef ENABLE_CHECKING >>> +#if CHECKING_P >> >> I fail to see the point of this change. > I'm guessing (and Mikhail, please correct me if I'm wrong), but I think he's > trying to get away from ENABLE_CHECKING and instead use a macro which is > always defined to a value. Yes, exactly. Such macro is better because it can be used both for conditional compilation (if needed) and normal if-s (unlike ENABLE_CHECKING).
On 10/14/2015 12:33 AM, Jeff Law wrote: >> gcc/common.opt | 5 +++++ >> gcc/system.h | 3 +++ >> libcpp/system.h | 8 ++++++++ >> 3 files changed, 16 insertions(+) > I committed this prerequisite patch to the trunk. > > jeff > There is a typo here: > #ifdef ENABLE_CHECKING > #define gcc_checking_assert(EXPR) gcc_assert (EXPR) >+#define CHECKING_P 1 > #else >+/* N.B.: in release build EXPR is not evaluated. */ > #define gcc_checking_assert(EXPR) ((void)(0 && (EXPR))) >+#define CHECKING_P 1 > #endif In my original patch the second definition actually was '+#define CHECKING_P 0' Also, gcc_checking_assert in libcpp requires gcc_assert to be defined. That was missing in my original patch (and was added in patch 2/9), but I think it would be better to fix it here, as Bernd noticed (in the last paragraph of [1]). Besides, I like Richard's proposal [2] about moving CHECKING_P macros into configure.ac. [1] https://gcc.gnu.org/ml/gcc-patches/2015-10/msg00550.html [2] https://gcc.gnu.org/ml/gcc-patches/2015-10/msg00555.html It required minor tweaking in order to silence autotools' warnings. I attached the modified patch. OK for trunk (after bootstrap/regtest)? P.S. I am planning to post at least some of the other updated parts today, and I also hope to get in time with the whole series (before stage1 ends). -- Regards, Mikhail Maltsev gcc/ChangeLog: 2015-10-18 Mikhail Maltsev <malts...@gmail.com> * config.in: Regenerate. * configure: Regenerate. * configure.ac (CHECKING_P): Define. * system.h: Use CHECKING_P. libcpp/ChangeLog: 2015-10-18 Mikhail Maltsev <malts...@gmail.com> * config.in: Regenerate. * configure: Regenerate. * configure.ac (CHECKING_P): Define. * system.h (fancy_abort): Declare. (abort): Define. (gcc_assert): Define. Use CHECKING_P.
diff --git a/gcc/config.in b/gcc/config.in index 093478c..48d7e64 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -30,6 +30,13 @@ #endif +/* Define to 1 if you want more run-time sanity checks. This one gets a grab + bag of miscellaneous but relatively cheap checks. */ +#ifndef USED_FOR_TARGET +#undef CHECKING_P +#endif + + /* Define 0/1 to force the choice for exception handling model. */ #ifndef USED_FOR_TARGET #undef CONFIG_SJLJ_EXCEPTIONS diff --git a/gcc/configure b/gcc/configure index 6b160ae..3122499 100755 --- a/gcc/configure +++ b/gcc/configure @@ -7096,7 +7096,12 @@ if test x$ac_checking != x ; then $as_echo "#define ENABLE_CHECKING 1" >>confdefs.h + $as_echo "#define CHECKING_P 1" >>confdefs.h + nocommon_flag=-fno-common +else + $as_echo "#define CHECKING_P 0" >>confdefs.h + fi if test x$ac_df_checking != x ; then @@ -18385,7 +18390,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 18388 "configure" +#line 18393 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -18491,7 +18496,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 18494 "configure" +#line 18499 "configure" #include "confdefs.h" #if HAVE_DLFCN_H diff --git a/gcc/configure.ac b/gcc/configure.ac index be721e6..a30bb3b 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -569,7 +569,12 @@ if test x$ac_checking != x ; then AC_DEFINE(ENABLE_CHECKING, 1, [Define if you want more run-time sanity checks. This one gets a grab bag of miscellaneous but relatively cheap checks.]) + AC_DEFINE(CHECKING_P, 1, +[Define to 1 if you want more run-time sanity checks. This one gets a grab + bag of miscellaneous but relatively cheap checks.]) nocommon_flag=-fno-common +else + AC_DEFINE(CHECKING_P, 0) fi AC_SUBST(nocommon_flag) if test x$ac_df_checking != x ; then diff --git a/gcc/system.h b/gcc/system.h index 61790d7..f9c7e2a 100644 --- a/gcc/system.h +++ b/gcc/system.h @@ -714,13 +714,11 @@ extern void fancy_abort (const char *, int, const char *) ATTRIBUTE_NORETURN; #define gcc_assert(EXPR) ((void)(0 && (EXPR))) #endif -#ifdef ENABLE_CHECKING +#if CHECKING_P #define gcc_checking_assert(EXPR) gcc_assert (EXPR) -#define CHECKING_P 1 #else /* N.B.: in release build EXPR is not evaluated. */ #define gcc_checking_assert(EXPR) ((void)(0 && (EXPR))) -#define CHECKING_P 1 #endif /* Use gcc_unreachable() to mark unreachable locations (like an diff --git a/libcpp/config.in b/libcpp/config.in index 8df00ec..5865eb3 100644 --- a/libcpp/config.in +++ b/libcpp/config.in @@ -3,6 +3,9 @@ /* Define if building universal (internal helper macro) */ #undef AC_APPLE_UNIVERSAL_BUILD +/* Define to 1 if you want more run-time sanity checks. */ +#undef CHECKING_P + /* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP systems. This function is required for `alloca.c' support on those systems. */ diff --git a/libcpp/configure b/libcpp/configure index 8cf2f77..1c70c75 100755 --- a/libcpp/configure +++ b/libcpp/configure @@ -7300,6 +7300,11 @@ if test x$ac_checking != x ; then $as_echo "#define ENABLE_CHECKING 1" >>confdefs.h + $as_echo "#define CHECKING_P 1" >>confdefs.h + +else + $as_echo "#define CHECKING_P 0" >>confdefs.h + fi if test x$ac_valgrind_checking != x ; then diff --git a/libcpp/configure.ac b/libcpp/configure.ac index 5f008a4..3fcbe84 100644 --- a/libcpp/configure.ac +++ b/libcpp/configure.ac @@ -166,6 +166,10 @@ IFS="$ac_save_IFS" if test x$ac_checking != x ; then AC_DEFINE(ENABLE_CHECKING, 1, [Define if you want more run-time sanity checks.]) + AC_DEFINE(CHECKING_P, 1, +[Define to 1 if you want more run-time sanity checks.]) +else + AC_DEFINE(CHECKING_P, 0) fi if test x$ac_valgrind_checking != x ; then diff --git a/libcpp/system.h b/libcpp/system.h index 20f07bb..2250f10 100644 --- a/libcpp/system.h +++ b/libcpp/system.h @@ -391,13 +391,28 @@ extern void abort (void); #define __builtin_expect(a, b) (a) #endif -#ifdef ENABLE_CHECKING +/* Redefine abort to report an internal error w/o coredump, and + reporting the location of the error in the source file. */ +extern void fancy_abort (const char *, int, const char *) ATTRIBUTE_NORETURN; +#define abort() fancy_abort (__FILE__, __LINE__, __FUNCTION__) + +/* Use gcc_assert(EXPR) to test invariants. */ +#if ENABLE_ASSERT_CHECKING +#define gcc_assert(EXPR) \ + ((void)(!(EXPR) ? fancy_abort (__FILE__, __LINE__, __FUNCTION__), 0 : 0)) +#elif (GCC_VERSION >= 4005) +#define gcc_assert(EXPR) \ + ((void)(__builtin_expect (!(EXPR), 0) ? __builtin_unreachable (), 0 : 0)) +#else +/* Include EXPR, so that unused variable warnings do not occur. */ +#define gcc_assert(EXPR) ((void)(0 && (EXPR))) +#endif + +#if CHECKING_P #define gcc_checking_assert(EXPR) gcc_assert (EXPR) -#define CHECKING_P 1 #else /* N.B.: in release build EXPR is not evaluated. */ #define gcc_checking_assert(EXPR) ((void)(0 && (EXPR))) -#define CHECKING_P 1 #endif /* Provide a fake boolean type. We make no attempt to use the