diff options
author | Mark H Weaver <mhw@netris.org> | 2014-03-07 04:21:46 -0500 |
---|---|---|
committer | Mark H Weaver <mhw@netris.org> | 2014-03-07 04:34:27 -0500 |
commit | de7aa61ac48811610b1b99005ada2464cf1a96f1 (patch) | |
tree | dbdd56eacaa8f9dca3c23f8e7006c0852373a4d9 | |
parent | ce0ba9d087fd5b03d85a64deddaf3c59bd136a3d (diff) | |
download | guile-de7aa61ac48811610b1b99005ada2464cf1a96f1.tar.gz |
Improve compliance with C standards regarding signed integer shifts.
* configure.ac: Add -fwrapv when using GCC (or compatible), if
supported.
* libguile/numbers.h (SCM_I_MAKINUM): Cast to scm_t_bits (unsigned)
before shifting, to avoid undefined behavior.
-rw-r--r-- | configure.ac | 9 | ||||
-rw-r--r-- | libguile/numbers.h | 4 |
2 files changed, 7 insertions, 6 deletions
diff --git a/configure.ac b/configure.ac index e99b27290..a5cb4b867 100644 --- a/configure.ac +++ b/configure.ac @@ -1516,7 +1516,8 @@ AC_SUBST(HOST_CC) GUILE_CHECK_GUILE_FOR_BUILD -## If we're using GCC, ask for aggressive warnings. +## If we're using GCC, add flags to reduce strictness of undefined +## behavior, and ask for aggressive warnings. GCC_CFLAGS="" case "$GCC" in yes ) @@ -1526,13 +1527,13 @@ case "$GCC" in ## -Wundef was removed because Gnulib prevented it (see ## <http://thread.gmane.org/gmane.lisp.guile.bugs/5329>.) - ## Build with `-fno-strict-aliasing' to prevent miscompilation on - ## some platforms. See + ## Build with `-fno-strict-aliasing' and `-fwrapv' to prevent + ## miscompilation on some platforms. See ## <http://lists.gnu.org/archive/html/guile-devel/2012-01/msg00487.html>. POTENTIAL_GCC_CFLAGS="-Wall -Wmissing-prototypes \ -Wdeclaration-after-statement -Wpointer-arith \ - -Wswitch-enum -fno-strict-aliasing" + -Wswitch-enum -fno-strict-aliasing -fwrapv" # Do this here so we don't screw up any of the tests above that might # not be "warning free" if test "${GUILE_ERROR_ON_WARNING}" = yes diff --git a/libguile/numbers.h b/libguile/numbers.h index 4d977dc3c..b4202f26a 100644 --- a/libguile/numbers.h +++ b/libguile/numbers.h @@ -4,7 +4,7 @@ #define SCM_NUMBERS_H /* Copyright (C) 1995,1996,1998,2000,2001,2002,2003,2004,2005, 2006, - * 2008, 2009, 2010, 2011, 2013 Free Software Foundation, Inc. + * 2008, 2009, 2010, 2011, 2013, 2014 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -60,7 +60,7 @@ typedef scm_t_int32 scm_t_wchar; #define SCM_I_INUMP(x) (2 & SCM_UNPACK (x)) #define SCM_I_NINUMP(x) (!SCM_I_INUMP (x)) #define SCM_I_MAKINUM(x) \ - (SCM_PACK ((((scm_t_signed_bits) (x)) << 2) + scm_tc2_int)) + (SCM_PACK ((((scm_t_bits) (x)) << 2) + scm_tc2_int)) #define SCM_I_INUM(x) (SCM_SRS ((scm_t_signed_bits) SCM_UNPACK (x), 2)) /* SCM_FIXABLE is true if its long argument can be encoded in an SCM_INUM. */ |