OSDN Git Service

* config/darwin.c (darwin_one_byte_bool): New global variable.
authoraustern <austern@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 28 Jul 2004 23:57:28 +0000 (23:57 +0000)
committeraustern <austern@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 28 Jul 2004 23:57:28 +0000 (23:57 +0000)
        * 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@85277 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/config/darwin.c
gcc/config/darwin.h
gcc/config/rs6000/darwin.h
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/darwin-bool-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/darwin-bool-2.c [new file with mode: 0644]

index 4bd3a7d..3c21172 100644 (file)
@@ -1,3 +1,12 @@
+2004-07-28  Matt Austern  <austern@apple.com>
+
+       * 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  <echristo@redhat.com>
 
        * c-common.c (c_common_unsafe_for_reeval): Delete.
index e3bf3a2..111abfc 100644 (file)
@@ -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)
 {
index 14fa7a1..cb84eb1 100644 (file)
@@ -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
index ae65eb2..e09e86b 100644 (file)
@@ -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
index 204c27b..58eaaa3 100644 (file)
@@ -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.
index 8cbd3dd..2bb5259 100644 (file)
@@ -1,3 +1,8 @@
+2004-07-27  Matt Austern <austern@apple.com>
+
+       * gcc.dg/darwin-bool-1.c: New test.
+       * gcc.dg/darwin-bool-2.c: New test.
+       
 2004-07-28  Richard Henderson  <rth@redhat.com>
 
        * 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 (file)
index 0000000..ef1e98b
--- /dev/null
@@ -0,0 +1,11 @@
+/* Check that sizeof(bool) is 4 if we don't use special options. */
+/* Matt Austern  <austern@apple.com> */
+/* { 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 (file)
index 0000000..fdbe1a2
--- /dev/null
@@ -0,0 +1,12 @@
+/* Check that sizeof(bool) is 1 if we use the -mone-byte-bool option. */
+/* Matt Austern  <austern@apple.com> */
+/* { 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;
+}