This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
runtime asserts
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Mark Mitchell <mark at codesourcery dot com>
- Date: Thu, 09 Sep 2004 12:07:21 +0100
- Subject: runtime asserts
- Organization: Codesourcery LLC
Hi,
this patch implements a runtime checking option and associated
assertions. With this we can proceed to convert the runtime files.
booted & tested on i686-pc-linux-gnu, ok?
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
2004-09-09 Nathan Sidwell <nathan@codesourcery.com>
* configure.ac (enable-checking): Add 'runtime' option.
* doc/install.texi (enable-checking): Document 'runtime' checking.
* tsystem.h (gcc_assert, gcc_unreachable): Define.
* config.in: Regenerated.
* configure: Regenerated.
Index: config.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config.in,v
retrieving revision 1.196
diff -c -3 -p -r1.196 config.in
*** config.in 4 Sep 2004 00:15:32 -0000 1.196
--- config.in 9 Sep 2004 10:25:33 -0000
***************
*** 54,59 ****
--- 54,62 ----
that are supported for each access macro. This is relatively cheap. */
#undef ENABLE_RTL_FLAG_CHECKING
+ /* Define if you want runtime assertions enabled. This is a cheap check. */
+ #undef ENABLE_RUNTIME_CHECKING
+
/* Define if you want all operations on trees (the basic data structure of the
front ends) to be checked for dynamic type safety at runtime. This is
moderately expensive. The tree browser debugging routines will also be
Index: configure
===================================================================
RCS file: /cvs/gcc/gcc/gcc/configure,v
retrieving revision 1.853
diff -c -3 -p -r1.853 configure
*** configure 7 Sep 2004 09:56:25 -0000 1.853
--- configure 9 Sep 2004 10:26:00 -0000
*************** Optional Features:
*** 868,874 ****
enable expensive run-time checks. With LIST,
enable only specific categories of checks.
Categories are: assert,fold,gc,gcac,misc,
! rtlflag,rtl,tree,valgrind,release,yes,all;
--enable-mapped-location location_t is fileline integer cookie
--enable-coverage=LEVEL
enable compiler's code coverage collection.
--- 868,874 ----
enable expensive run-time checks. With LIST,
enable only specific categories of checks.
Categories are: assert,fold,gc,gcac,misc,
! rtlflag,rtl,runtime,tree,valgrind,release,yes,all;
--enable-mapped-location location_t is fileline integer cookie
--enable-coverage=LEVEL
enable compiler's code coverage collection.
*************** ac_checking=
*** 3942,3947 ****
--- 3942,3948 ----
ac_tree_checking=
ac_rtl_checking=
ac_rtlflag_checking=
+ ac_runtime_checking=1
ac_gc_checking=
ac_gc_always_collect=
ac_fold_checking=
*************** do
*** 3951,3966 ****
case $check in
yes) ac_assert_checking=1 ; ac_checking=1 ;
ac_tree_checking=1 ; ac_gc_checking=1 ;
! ac_rtlflag_checking=1 ;;
no) ac_assert_checking= ; ac_checking= ;
ac_tree_checking= ; ac_rtl_checking= ;
ac_rtlflag_checking= ; ac_gc_checking= ;
ac_gc_always_collect= ; ac_fold_checking= ;;
all) ac_assert_checking=1 ; ac_checking=1 ;
ac_tree_checking=1 ; ac_rtl_checking=1 ;
! ac_rtlflag_checking=1 ; ac_gc_checking=1 ;
! ac_gc_always_collect=1 ; ac_fold_checking=1 ;;
! release) ac_assert_checking=1 ;;
assert) ac_assert_checking=1 ;;
fold) ac_fold_checking=1 ;;
gc) ac_gc_checking=1 ;;
--- 3952,3968 ----
case $check in
yes) ac_assert_checking=1 ; ac_checking=1 ;
ac_tree_checking=1 ; ac_gc_checking=1 ;
! ac_rtlflag_checking=1 ; ac_runtime_checking=1 ;;
no) ac_assert_checking= ; ac_checking= ;
ac_tree_checking= ; ac_rtl_checking= ;
ac_rtlflag_checking= ; ac_gc_checking= ;
ac_gc_always_collect= ; ac_fold_checking= ;;
all) ac_assert_checking=1 ; ac_checking=1 ;
ac_tree_checking=1 ; ac_rtl_checking=1 ;
! ac_rtlflag_checking=1 ; ac_runtime_checking=1;
! ac_gc_checking=1 ; ac_gc_always_collect=1 ;
! ac_fold_checking=1 ;;
! release) ac_assert_checking=1 ; ac_runtime_checking=1 ;;
assert) ac_assert_checking=1 ;;
fold) ac_fold_checking=1 ;;
gc) ac_gc_checking=1 ;;
*************** do
*** 3968,3973 ****
--- 3970,3976 ----
misc) ac_checking=1 ;;
rtlflag) ac_rtlflag_checking=1 ;;
rtl) ac_rtl_checking=1 ;;
+ runtime) ac_runtime_checking=1 ;;
tree) ac_tree_checking=1 ;;
valgrind) ac_checking_valgrind=1 ;;
*) { { echo "$as_me:$LINENO: error: unknown check category $check" >&5
*************** cat >>confdefs.h <<\_ACEOF
*** 3994,3999 ****
--- 3997,4009 ----
_ACEOF
fi
+ if test x$ac_runtime_checking != x ; then
+
+ cat >>confdefs.h <<\_ACEOF
+ #define ENABLE_RUNTIME_CHECKING 1
+ _ACEOF
+
+ fi
if test x$ac_tree_checking != x ; then
cat >>confdefs.h <<\_ACEOF
*************** if test "${gcc_cv_prog_makeinfo_modern+s
*** 5291,5297 ****
else
ac_prog_version=`$MAKEINFO --version 2>&1 |
sed -n 's/^.*GNU texinfo.* \([0-9][0-9.]*\).*$/\1/p'`
! echo "configure:5294: version of makeinfo is $ac_prog_version" >&5
case $ac_prog_version in
'') gcc_cv_prog_makeinfo_modern=no;;
4.[2-9]*)
--- 5301,5307 ----
else
ac_prog_version=`$MAKEINFO --version 2>&1 |
sed -n 's/^.*GNU texinfo.* \([0-9][0-9.]*\).*$/\1/p'`
! echo "configure:5304: version of makeinfo is $ac_prog_version" >&5
case $ac_prog_version in
'') gcc_cv_prog_makeinfo_modern=no;;
4.[2-9]*)
Index: configure.ac
===================================================================
RCS file: /cvs/gcc/gcc/gcc/configure.ac,v
retrieving revision 2.63
diff -c -3 -p -r2.63 configure.ac
*** configure.ac 7 Sep 2004 09:56:25 -0000 2.63
--- configure.ac 9 Sep 2004 10:26:06 -0000
*************** AC_ARG_ENABLE(checking,
*** 393,399 ****
enable expensive run-time checks. With LIST,
enable only specific categories of checks.
Categories are: assert,fold,gc,gcac,misc,
! rtlflag,rtl,tree,valgrind,release,yes,all;],
[ac_checking_flags="${enableval}"],[
# Determine the default checks.
if test x$is_release = x ; then
--- 393,399 ----
enable expensive run-time checks. With LIST,
enable only specific categories of checks.
Categories are: assert,fold,gc,gcac,misc,
! rtlflag,rtl,runtime,tree,valgrind,release,yes,all;],
[ac_checking_flags="${enableval}"],[
# Determine the default checks.
if test x$is_release = x ; then
*************** ac_checking=
*** 406,411 ****
--- 406,412 ----
ac_tree_checking=
ac_rtl_checking=
ac_rtlflag_checking=
+ ac_runtime_checking=1
ac_gc_checking=
ac_gc_always_collect=
ac_fold_checking=
*************** do
*** 415,430 ****
case $check in
yes) ac_assert_checking=1 ; ac_checking=1 ;
ac_tree_checking=1 ; ac_gc_checking=1 ;
! ac_rtlflag_checking=1 ;;
no) ac_assert_checking= ; ac_checking= ;
ac_tree_checking= ; ac_rtl_checking= ;
ac_rtlflag_checking= ; ac_gc_checking= ;
ac_gc_always_collect= ; ac_fold_checking= ;;
all) ac_assert_checking=1 ; ac_checking=1 ;
ac_tree_checking=1 ; ac_rtl_checking=1 ;
! ac_rtlflag_checking=1 ; ac_gc_checking=1 ;
! ac_gc_always_collect=1 ; ac_fold_checking=1 ;;
! release) ac_assert_checking=1 ;;
assert) ac_assert_checking=1 ;;
fold) ac_fold_checking=1 ;;
gc) ac_gc_checking=1 ;;
--- 416,432 ----
case $check in
yes) ac_assert_checking=1 ; ac_checking=1 ;
ac_tree_checking=1 ; ac_gc_checking=1 ;
! ac_rtlflag_checking=1 ; ac_runtime_checking=1 ;;
no) ac_assert_checking= ; ac_checking= ;
ac_tree_checking= ; ac_rtl_checking= ;
ac_rtlflag_checking= ; ac_gc_checking= ;
ac_gc_always_collect= ; ac_fold_checking= ;;
all) ac_assert_checking=1 ; ac_checking=1 ;
ac_tree_checking=1 ; ac_rtl_checking=1 ;
! ac_rtlflag_checking=1 ; ac_runtime_checking=1;
! ac_gc_checking=1 ; ac_gc_always_collect=1 ;
! ac_fold_checking=1 ;;
! release) ac_assert_checking=1 ; ac_runtime_checking=1 ;;
assert) ac_assert_checking=1 ;;
fold) ac_fold_checking=1 ;;
gc) ac_gc_checking=1 ;;
*************** do
*** 432,437 ****
--- 434,440 ----
misc) ac_checking=1 ;;
rtlflag) ac_rtlflag_checking=1 ;;
rtl) ac_rtl_checking=1 ;;
+ runtime) ac_runtime_checking=1 ;;
tree) ac_tree_checking=1 ;;
valgrind) ac_checking_valgrind=1 ;;
*) AC_MSG_ERROR(unknown check category $check) ;;
*************** if test x$ac_assert_checking != x ; then
*** 451,456 ****
--- 454,463 ----
AC_DEFINE(ENABLE_ASSERT_CHECKING, 1,
[Define if you want assertions enabled. This is a cheap check.])
fi
+ if test x$ac_runtime_checking != x ; then
+ AC_DEFINE(ENABLE_RUNTIME_CHECKING, 1,
+ [Define if you want runtime assertions enabled. This is a cheap check.])
+ fi
if test x$ac_tree_checking != x ; then
AC_DEFINE(ENABLE_TREE_CHECKING, 1,
[Define if you want all operations on trees (the basic data
Index: doc/install.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/install.texi,v
retrieving revision 1.316
diff -c -3 -p -r1.316 install.texi
*** doc/install.texi 7 Sep 2004 19:39:06 -0000 1.316
--- doc/install.texi 9 Sep 2004 10:26:43 -0000
*************** with GCC@. This is on by default when b
*** 1112,1131 ****
but off for releases. More control over the checks may be had by
specifying @var{list}; the categories of checks available are
@samp{release}, @samp{assert}, @samp{misc}, @samp{tree}, @samp{gc},
! @samp{rtl}, @samp{rtlflag}, @samp{fold}, @samp{gcac} and
@samp{valgrind}. The @samp{release} category enables only those checks
! suitable for release builds, currently this is just @samp{assert}. The
! check @samp{valgrind} requires the external @command{valgrind}
! simulator, available from @uref{http://valgrind.kde.org/}. The checks
! @samp{rtl}, @samp{gcac} and @samp{valgrind} are very expensive. The
! default when @var{list} is not specified is
! @samp{assert,misc,tree,gc,rtlflag}. That is also the default for
! development builds, when @samp{--enable-checking} is not specified. For
! release builds the default, when @samp{--enable-checking} is not given,
! is @samp{release}. To disable all checking, @samp{--disable-checking}
! must be explicitly requested. Disabling assertions will make the
! compiler slightly faster but increase the risk of undetected internal
! errors causing wrong code to be generated.
@item --enable-coverage
@itemx --enable-coverage=@var{level}
--- 1112,1132 ----
but off for releases. More control over the checks may be had by
specifying @var{list}; the categories of checks available are
@samp{release}, @samp{assert}, @samp{misc}, @samp{tree}, @samp{gc},
! @samp{rtl}, @samp{rtlflag}, @samp{runtime}, @samp{fold}, @samp{gcac} and
@samp{valgrind}. The @samp{release} category enables only those checks
! suitable for release builds, currently this is @samp{assert} and
! @samp{runtime}. The check @samp{valgrind} requires the external
! @command{valgrind} simulator, available from
! @uref{http://valgrind.kde.org/}. The checks @samp{rtl}, @samp{gcac} and
! @samp{valgrind} are very expensive. The default when @var{list} is not
! specified is @samp{assert,misc,tree,gc,rtlflag,runtime}. That is also
! the default for development builds, when @samp{--enable-checking} is not
! specified. For release builds the default, when
! @samp{--enable-checking} is not given, is @samp{release}. To disable
! all checking, @samp{--disable-checking} must be explicitly requested.
! Disabling assertions will make the compiler and runtime slightly faster
! but increase the risk of undetected internal errors causing wrong code
! to be generated.
@item --enable-coverage
@itemx --enable-coverage=@var{level}
Index: tsystem.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tsystem.h,v
retrieving revision 1.13
diff -c -3 -p -r1.13 tsystem.h
*** tsystem.h 3 Sep 2004 05:26:27 -0000 1.13
--- tsystem.h 9 Sep 2004 10:30:59 -0000
*************** extern int errno;
*** 117,120 ****
--- 117,130 ----
#define NULL 0
#endif
+ #ifdef ENABLE_RUNTIME_CHECKING
+ #define gcc_assert(EXPR) ((void)(!(EXPR) ? abort (), 0 : 0))
+ #else
+ /* Include EXPR, so that unused variable warnings do not occur. */
+ #define gcc_assert(EXPR) ((void)(0 && (EXPR)))
+ #endif
+ /* Use gcc_unreachable() to mark unreachable locations (like an
+ unreachable default case of a switch. Do not use gcc_assert(0). */
+ #define gcc_unreachable() (abort ())
+
#endif /* ! GCC_TSYSTEM_H */