From: Matt Austern Date: Wed, 28 Jul 2004 23:57:28 +0000 (+0000) Subject: darwin.c (darwin_one_byte_bool): New global variable. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8f4220dc9270f29f40fe5d7f3647eaa10511934b;p=gcc.git darwin.c (darwin_one_byte_bool): New global variable. * config/darwin.c (darwin_one_byte_bool): New global variable. * config/darwin.h (darwin_one_byte_bool): Declare. (SUBTARGET_OPTIONS): Define macro. (for -mone-byte-bool flag.) * config/rs6000/darwin.h (BOOL_TYPE_SIZE): Conditionalize on value of darwin_one_byte_bool. * doc/invoke.texi: Document -mone-byte-bool flag. * testsuite/gcc.dg/darwin-bool-1.c: New test. * testsuite/gcc.dg/darwin-bool-2.c: New test. From-SVN: r85277 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4bd3a7d1acc..3c2117284f5 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2004-07-28 Matt Austern + + * config/darwin.c (darwin_one_byte_bool): New global variable. + * config/darwin.h (darwin_one_byte_bool): Declare. + (SUBTARGET_OPTIONS): Define macro. (for -mone-byte-bool flag.) + * config/rs6000/darwin.h (BOOL_TYPE_SIZE): Conditionalize on + value of darwin_one_byte_bool. + * doc/invoke.texi: Document -mone-byte-bool flag. + 2004-07-28 Eric Christopher * c-common.c (c_common_unsafe_for_reeval): Delete. diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index e3bf3a25aeb..111abfc465a 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -44,6 +44,10 @@ Boston, MA 02111-1307, USA. */ #include "errors.h" #include "hashtab.h" +/* Nonzero if the user passes the -mone-byte-bool switch, which forces + sizeof(bool) to be 1. */ +const char *darwin_one_byte_bool = 0; + int name_needs_quotes (const char *name) { diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h index 14fa7a15e8e..cb84eb12473 100644 --- a/gcc/config/darwin.h +++ b/gcc/config/darwin.h @@ -130,7 +130,18 @@ Boston, MA 02111-1307, USA. */ { "-single_module", "-Zsingle_module" }, \ { "-unexported_symbols_list", "-Zunexported_symbols_list" }, \ SUBTARGET_OPTION_TRANSLATE_TABLE + +/* Nonzero if the user has chosen to force sizeof(bool) to be 1 + by providing the -mone-byte-bool switch. It would be better + to use SUBTARGET_SWITCHES for this instead of SUBTARGET_OPTIONS, + but there are no more bits in rs6000 TARGET_SWITCHES. Note + that this switch has no "no-" variant. */ +extern const char *darwin_one_byte_bool; +#undef SUBTARGET_OPTIONS +#define SUBTARGET_OPTIONS \ + {"one-byte-bool", &darwin_one_byte_bool, N_("Set sizeof(bool) to 1"), 0 } + /* These compiler options take n arguments. */ #undef WORD_SWITCH_TAKES_ARG diff --git a/gcc/config/rs6000/darwin.h b/gcc/config/rs6000/darwin.h index ae65eb26851..e09e86b892d 100644 --- a/gcc/config/rs6000/darwin.h +++ b/gcc/config/rs6000/darwin.h @@ -321,8 +321,10 @@ do { \ #define DOUBLE_INT_ASM_OP "\t.quad\t" /* For binary compatibility with 2.95; Darwin C APIs use bool from - stdbool.h, which was an int-sized enum in 2.95. */ -#define BOOL_TYPE_SIZE INT_TYPE_SIZE + stdbool.h, which was an int-sized enum in 2.95. Users can explicitly + choose to have sizeof(bool)==1 with the -mone-byte-bool switch. */ +extern const char *darwin_one_byte_bool; +#define BOOL_TYPE_SIZE (darwin_one_byte_bool ? CHAR_TYPE_SIZE : INT_TYPE_SIZE) #undef REGISTER_TARGET_PRAGMAS #define REGISTER_TARGET_PRAGMAS DARWIN_REGISTER_TARGET_PRAGMAS diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 204c27bca7b..58eaaa3e9e5 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -423,7 +423,7 @@ in the following sections. -single_module -static -sub_library -sub_umbrella @gol -twolevel_namespace -umbrella -undefined @gol -unexported_symbols_list -weak_reference_mismatches @gol --whatsloaded -F -gused -gfull} +-whatsloaded -F -gused -gfull -mone-byte-bool} @emph{DEC Alpha Options} @gccoptlist{-mno-fp-regs -msoft-float -malpha-as -mgas @gol @@ -6931,6 +6931,19 @@ This is by default ON. @opindex -gfull Emit debugging information for all symbols and types. +@item -mone-byte-bool +@opindex -mone-byte-bool +Override the defaults for @samp{bool} so that @samp{sizeof(bool)==1}. +By default @samp{sizeof(bool)} is @samp{4} when compiling for +Darwin/PowerPC and @samp{1} when compiling for Darwin/x86, so this +option has no effect on x86. + +@strong{Warning:} The @option{-mone-byte-bool} switch causes GCC +to generate code that is not binary compatible with code generated +without that switch. Using this switch may require recompiling all +other modules in a program, including system libraries. Use this +switch to conform to a non-default data model. + @item -all_load @opindex all_load Loads all members of static archive libraries. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8cbd3dd8a51..2bb525981ec 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-07-27 Matt Austern + + * gcc.dg/darwin-bool-1.c: New test. + * gcc.dg/darwin-bool-2.c: New test. + 2004-07-28 Richard Henderson * gfortran.fortran-torture/execute/intrinsic_spacing.f90: Pass diff --git a/gcc/testsuite/gcc.dg/darwin-bool-1.c b/gcc/testsuite/gcc.dg/darwin-bool-1.c new file mode 100644 index 00000000000..ef1e98b6ef2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/darwin-bool-1.c @@ -0,0 +1,11 @@ +/* Check that sizeof(bool) is 4 if we don't use special options. */ +/* Matt Austern */ +/* { dg-do run { target powerpc*-*-darwin* } } */ + +int dummy1[sizeof(_Bool) - 3]; +int dummy2[5 - sizeof(_Bool)]; + +int main() +{ + return sizeof(_Bool) == 4 ? 0 : 1; +} diff --git a/gcc/testsuite/gcc.dg/darwin-bool-2.c b/gcc/testsuite/gcc.dg/darwin-bool-2.c new file mode 100644 index 00000000000..fdbe1a2a4b8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/darwin-bool-2.c @@ -0,0 +1,12 @@ +/* Check that sizeof(bool) is 1 if we use the -mone-byte-bool option. */ +/* Matt Austern */ +/* { dg-do run { target powerpc*-*-darwin* } } */ +/* { dg-options "-mone-byte-bool" } */ + +int dummy1[sizeof(_Bool)]; +int dummy2[2 - sizeof(_Bool)]; + +int main() +{ + return sizeof(_Bool) == 1 ? 0 : 1; +}