This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Darwin] Patch: new flag -mone-byte-bool


I can't say I'm thrilled with this feature, but, unfortunately, it's necessary. gcc on Darwin/PowerPC defines sizeof(bool) to be 4. Changing this isn't a viable option: ABI stability is too important. This flag is for those few developers who absolutely need bool to have a particular size and who are sophisticated enough to be able to deal with an ABI-changing flag. Think of it as something like -fshort-wchar.

Bootstrapped and tested on Darwin/PowerPC (of course). Documentation, test cases, and ChangeLog entries included.

OK to commit to mainline?

--Matt


Index: gcc/ChangeLog =================================================================== RCS file: /cvs/gcc/gcc/gcc/ChangeLog,v retrieving revision 2.4718 diff -p -r2.4718 ChangeLog *** gcc/ChangeLog 28 Jul 2004 05:13:05 -0000 2.4718 --- gcc/ChangeLog 28 Jul 2004 05:53:38 -0000 *************** *** 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 Diego Novillo <dnovillo@redhat.com>

  	* tree-optimize.c (init_tree_optimization_passes): Schedule
Index: gcc/config/darwin.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/darwin.c,v
retrieving revision 1.72
diff -p -r1.72 darwin.c
*** gcc/config/darwin.c	23 Jul 2004 04:35:14 -0000	1.72
--- gcc/config/darwin.c	28 Jul 2004 05:53:38 -0000
*************** Boston, MA 02111-1307, USA.  */
*** 44,49 ****
--- 44,53 ----
  #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: gcc/config/darwin.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/darwin.h,v
retrieving revision 1.86
diff -p -r1.86 darwin.h
*** gcc/config/darwin.h	23 Jul 2004 04:35:15 -0000	1.86
--- gcc/config/darwin.h	28 Jul 2004 05:53:40 -0000
*************** Boston, MA 02111-1307, USA.  */
*** 130,136 ****
--- 130,147 ----
    { "-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: gcc/config/rs6000/darwin.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/darwin.h,v
retrieving revision 1.54
diff -p -r1.54 darwin.h
*** gcc/config/rs6000/darwin.h	1 Jul 2004 04:09:05 -0000	1.54
--- gcc/config/rs6000/darwin.h	28 Jul 2004 05:53:40 -0000
*************** do {									\
*** 321,328 ****
  #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

  #undef REGISTER_TARGET_PRAGMAS
  #define REGISTER_TARGET_PRAGMAS DARWIN_REGISTER_TARGET_PRAGMAS
--- 321,330 ----
  #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. 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: gcc/doc/invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.492
diff -p -r1.492 invoke.texi
*** gcc/doc/invoke.texi	25 Jul 2004 22:52:18 -0000	1.492
--- gcc/doc/invoke.texi	28 Jul 2004 05:53:44 -0000
*************** in the following sections.
*** 423,429 ****
  -single_module  -static  -sub_library  -sub_umbrella @gol
  -twolevel_namespace  -umbrella  -undefined @gol
  -unexported_symbols_list  -weak_reference_mismatches @gol
! -whatsloaded -F -gused -gfull}

  @emph{DEC Alpha Options}
  @gccoptlist{-mno-fp-regs  -msoft-float  -malpha-as  -mgas @gol
--- 423,429 ----
  -single_module  -static  -sub_library  -sub_umbrella @gol
  -twolevel_namespace  -umbrella  -undefined @gol
  -unexported_symbols_list  -weak_reference_mismatches @gol
! whatsloaded -F -gused -gfull -mone-byte-bool}

  @emph{DEC Alpha Options}
  @gccoptlist{-mno-fp-regs  -msoft-float  -malpha-as  -mgas @gol
*************** This is by default ON.
*** 6930,6935 ****
--- 6930,6948 ----
  @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: gcc/testsuite/ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/ChangeLog,v
retrieving revision 1.4061
diff -p -r1.4061 ChangeLog
*** gcc/testsuite/ChangeLog	28 Jul 2004 05:13:09 -0000	1.4061
--- gcc/testsuite/ChangeLog	28 Jul 2004 05:53:48 -0000
***************
*** 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  Diego Novillo  <dnovillo@redhat.com>

* gcc.dg/tree-ssa/20030714-2.c: Adjust number of expected
Index: gcc/testsuite/gcc.dg/darwin-bool-1.c
===================================================================
RCS file: gcc/testsuite/gcc.dg/darwin-bool-1.c
diff -N gcc/testsuite/gcc.dg/darwin-bool-1.c
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- gcc/testsuite/gcc.dg/darwin-bool-1.c 28 Jul 2004 05:53:52 -0000
***************
*** 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;
+ }
Index: gcc/testsuite/gcc.dg/darwin-bool-2.c
===================================================================
RCS file: gcc/testsuite/gcc.dg/darwin-bool-2.c
diff -N gcc/testsuite/gcc.dg/darwin-bool-2.c
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- gcc/testsuite/gcc.dg/darwin-bool-2.c 28 Jul 2004 05:53:52 -0000
***************
*** 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;
+ }



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]