Don't use _Bool
Zack Weinberg
zack@codesourcery.com
Sat Jun 12 11:33:00 GMT 2004
There've been a number of problems reported with gcc using _Bool -- in
native builds, gcc and the bootstrap compiler may not agree on the
size of the type; various bootstrap compilers have bugs with
arithmetic operations on _Bool; the fallback to unsigned char is
unsafe, because we might come to rely on _Bool's semantics.
Accordingly this patch causes 'bool' to be a macro for 'unsigned char'
and 'BOOL_BITFIELD' to be a macro for 'unsigned int', *unconditionally*.
This eliminates both of the uses of ACX_HEADER_STDBOOL, but I did not
take the macro out of acx.m4 because someone else might be using it.
The only bug I found by doing this was a missing use of BOOL_BITFIELD
in domwalk.h.
Bootstrapped i686-linux.
zw
gcc:
* configure.ac: Don't invoke ACX_HEADER_STDBOOL.
* configure, config.in: Regenerate.
* system.h: Unconditionally define bool as unsigned char,
BOOL_BITFIELD as unsigned int.
* domwalk.h: Use BOOL_BITFIELD.
libcpp:
* configure.ac: Don't invoke ACX_HEADER_STDBOOL.
* configure, config.in: Regenerate.
* system.h: Unconditionally define bool as unsigned char,
BOOL_BITFIELD as unsigned int.
* .cvsignore: New file.
===================================================================
Index: gcc/configure.ac
--- gcc/configure.ac 9 Jun 2004 08:17:15 -0000 2.41
+++ gcc/configure.ac 12 Jun 2004 05:47:50 -0000
@@ -810,7 +810,6 @@ AC_PROG_CPP_WERROR
AC_HEADER_STDC
AC_HEADER_TIME
-ACX_HEADER_STDBOOL
ACX_HEADER_STRING
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(limits.h stddef.h string.h strings.h stdlib.h time.h \
===================================================================
Index: gcc/domwalk.h
--- gcc/domwalk.h 13 May 2004 06:39:37 -0000 2.1
+++ gcc/domwalk.h 12 Jun 2004 05:47:50 -0000
@@ -38,7 +38,7 @@ struct dom_walk_data
to use the second statement walker for anything, so it's hard to
predict if we really need the ability to select their direction
independently. */
- bool walk_stmts_backward : 1;
+ BOOL_BITFIELD walk_stmts_backward : 1;
/* Function to initialize block local data.
===================================================================
Index: gcc/system.h
--- gcc/system.h 24 May 2004 10:50:40 -0000 1.213
+++ gcc/system.h 12 Jun 2004 05:47:50 -0000
@@ -372,13 +372,6 @@ extern int snprintf (char *, size_t, con
((GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L))
#endif
-/* 1 if we have _Bool. */
-#ifndef HAVE__BOOL
-# define HAVE__BOOL \
- ((GCC_VERSION >= 3000) || (__STDC_VERSION__ >= 199901L))
-#endif
-
-
#if HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
@@ -485,14 +478,6 @@ extern int snprintf (char *, size_t, con
#define ENUM_BITFIELD(TYPE) unsigned int
#endif
-/* We only use bool bitfields with gcc3. Some supposedly C99
- compilers don't handle them correctly. */
-#if (GCC_VERSION >= 3000)
-#define BOOL_BITFIELD _Bool
-#else
-#define BOOL_BITFIELD unsigned int
-#endif
-
#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
#endif
@@ -511,29 +496,27 @@ extern int snprintf (char *, size_t, con
#define __builtin_expect(a, b) (a)
#endif
-/* Provide some sort of boolean type. We use stdbool.h if it's
- available. This must be after all inclusion of system headers,
- as some of them will mess us up. */
+/* Provide a fake boolean type. We make no attempt to use the
+ C99 _Bool, as it may not be available in the bootstrap compiler,
+ and even if it is, it is liable to be buggy.
+ This must be after all inclusion of system headers, as some of
+ them will mess us up. */
#undef bool
#undef true
#undef false
#undef TRUE
#undef FALSE
-#ifdef HAVE_STDBOOL_H
-# include <stdbool.h>
-#else
-# if !HAVE__BOOL
-typedef char _Bool;
-# endif
-# define bool _Bool
-# define true 1
-# define false 0
-#endif
+#define bool unsigned char
+#define true 1
+#define false 0
#define TRUE true
#define FALSE false
+/* Some compilers do not allow the use of unsigned char in bitfields. */
+#define BOOL_BITFIELD unsigned int
+
/* As the last action in this file, we poison the identifiers that
shouldn't be used. Note, luckily gcc-3.0's token-based integrated
preprocessor won't trip on poisoned identifiers that arrive from
===================================================================
Index: libcpp/.cvsignore
--- libcpp/.cvsignore 1 Jan 1970 00:00:00 -0000
+++ libcpp/.cvsignore 12 Jun 2004 05:47:51 -0000
@@ -0,0 +1 @@
+autom4te.cache
===================================================================
Index: libcpp/configure.ac
--- libcpp/configure.ac 26 May 2004 06:58:53 -0000 1.2
+++ libcpp/configure.ac 12 Jun 2004 05:47:51 -0000
@@ -1,7 +1,7 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
-AC_PREREQ(2.57)
+AC_PREREQ(2.59)
AC_INIT(cpplib, [ ], gcc-bugs@gcc.gnu.org, cpplib)
AC_CONFIG_SRCDIR(ucnid.h)
AC_CANONICAL_SYSTEM
@@ -15,7 +15,6 @@ AC_PROG_RANLIB
# Checks for header files.
AC_HEADER_TIME
ACX_HEADER_STRING
-ACX_HEADER_STDBOOL
AC_CHECK_HEADERS(iconv.h locale.h fcntl.h limits.h stddef.h \
stdlib.h strings.h string.h sys/file.h unistd.h)
===================================================================
Index: libcpp/system.h
--- libcpp/system.h 24 May 2004 15:04:09 -0000 1.2
+++ libcpp/system.h 12 Jun 2004 05:47:51 -0000
@@ -275,13 +275,6 @@ extern void abort (void);
((GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L))
#endif
-/* 1 if we have _Bool. */
-#ifndef HAVE__BOOL
-# define HAVE__BOOL \
- ((GCC_VERSION >= 3000) || (__STDC_VERSION__ >= 199901L))
-#endif
-
-
/* Be conservative and only use enum bitfields with GCC.
FIXME: provide a complete autoconf test for buggy enum bitfields. */
@@ -291,14 +284,6 @@ extern void abort (void);
#define ENUM_BITFIELD(TYPE) unsigned int
#endif
-/* We only use bool bitfields with gcc3. Some supposedly C99
- compilers don't handle them correctly. */
-#if (GCC_VERSION >= 3000)
-#define BOOL_BITFIELD _Bool
-#else
-#define BOOL_BITFIELD unsigned int
-#endif
-
#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
#endif
@@ -310,26 +295,25 @@ extern void abort (void);
#define __builtin_expect(a, b) (a)
#endif
-/* Provide some sort of boolean type. We use stdbool.h if it's
- available. This must be after all inclusion of system headers,
- as some of them will mess us up. */
+/* Provide a fake boolean type. We make no attempt to use the
+ C99 _Bool, as it may not be available in the bootstrap compiler,
+ and even if it is, it is liable to be buggy.
+ This must be after all inclusion of system headers, as some of
+ them will mess us up. */
#undef bool
#undef true
#undef false
#undef TRUE
#undef FALSE
-#ifdef HAVE_STDBOOL_H
-# include <stdbool.h>
-#else
-# if !HAVE__BOOL
-typedef char _Bool;
-# endif
-# define bool _Bool
-# define true 1
-# define false 0
-#endif
+#define bool unsigned char
+#define true 1
+#define false 0
+/* Some compilers do not allow the use of unsigned char in bitfields. */
+#define BOOL_BITFIELD unsigned int
+
+/* Poison identifiers we do not want to use. */
#if (GCC_VERSION >= 3000)
#undef calloc
#undef strdup
@@ -359,5 +343,4 @@ typedef char _Bool;
#pragma GCC poison bcopy bzero bcmp rindex
#endif /* GCC >= 3.0 */
-
#endif /* ! LIBCPP_SYSTEM_H */
More information about the Gcc-patches
mailing list