1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

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.
This commit is contained in:
Mark H Weaver 2014-03-07 04:21:46 -05:00
parent ce0ba9d087
commit de7aa61ac4
2 changed files with 7 additions and 6 deletions

View file

@ -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

View file

@ -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. */