[patch] pragma for __attribute__ ((__ms_struct__))

Eric Christopher echristo@apple.com
Mon Apr 24 22:05:00 GMT 2006


Customer of ours wants a pragma for the attribute so they can turn it  
on for a good chunk of their code, but not all since -mms-bitfields  
would interfere with the system headers. I made it a darwin only  
pragma since the consensus on #gcc was that it wasn't a useful pragma  
in general.

I don't like the #if TARGET_MACHO in the target config files, but I  
can't think of a less intrusive way to do it.

OK? Should I wait for 4.2 to branch? I'd prefer not since that could  
be a while and this is mostly OS specific, but I can. FWIW I've got a  
large bugfix patch for the ms_struct stuff coming shortly.

-eric

2006-04-24  Eric Christopher  <echristo@apple.com>

	* config/darwin-c.c (darwin_pragma_ms_struct): New.
	* config/darwin-protos.h (darwin_pragma_ms_struct): Declare.
	* config/darwin.c (darwin_ms_struct): New.
	* config/darwin.h (DARWIN_REGISTER_TARGET_PRAGMAS): Use
	darwin_pragma_ms_struct.
	(darwin_ms_struct): Declare.
	* config/i386/i386.c (ix86_ms_bitfield_layout_p): Use darwin_ms_struct.
	* config/rs6000/rs6000.c (rs6000_ms_bitfield_layout_p): Ditto.

Index: gcc/config/darwin-c.c
===================================================================
--- gcc/config/darwin-c.c	(revision 113224)
+++ gcc/config/darwin-c.c	(working copy)
@@ -159,6 +159,27 @@ darwin_pragma_unused (cpp_reader *pfile
      warning (0, "junk at end of '#pragma unused'");
}
+void
+darwin_pragma_ms_struct (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+  const char *arg;
+  tree t;
+
+  if (pragma_lex (&t) != CPP_NAME)
+    BAD ("malformed '#pragma ms_struct', ignoring");
+  arg = IDENTIFIER_POINTER (t);
+
+  if (!strcmp (arg, "on"))
+    darwin_ms_struct = true;
+  else if (!strcmp (arg, "off") || !strcmp (arg, "reset"))
+    darwin_ms_struct = false;
+  else
+    warning (0, "malformed '#pragma ms_struct {on|off|reset}',  
ignoring");
+
+  if (pragma_lex (&t) != CPP_EOF)
+    warning (0, "junk at end of '#pragma ms_struct'");
+}
+
static struct {
    size_t len;
    const char *name;
Index: gcc/config/i386/i386.c
===================================================================
--- gcc/config/i386/i386.c	(revision 113224)
+++ gcc/config/i386/i386.c	(working copy)
@@ -17278,6 +17278,9 @@ ix86_ms_bitfield_layout_p (tree record_t
{
    return (TARGET_MS_BITFIELD_LAYOUT &&
	  !lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (record_type)))
+#if TARGET_MACHO
+    || darwin_ms_struct
+#endif
      || lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (record_type));
}
Index: gcc/config/darwin-protos.h
===================================================================
--- gcc/config/darwin-protos.h	(revision 113224)
+++ gcc/config/darwin-protos.h	(working copy)
@@ -65,6 +65,7 @@ extern void darwin_emit_except_table_lab
extern void darwin_pragma_ignore (struct cpp_reader *);
extern void darwin_pragma_options (struct cpp_reader *);
extern void darwin_pragma_unused (struct cpp_reader *);
+extern void darwin_pragma_ms_struct (struct cpp_reader *);
extern void darwin_file_start (void);
extern void darwin_file_end (void);
Index: gcc/config/rs6000/rs6000.c
===================================================================
--- gcc/config/rs6000/rs6000.c	(revision 113224)
+++ gcc/config/rs6000/rs6000.c	(working copy)
@@ -17601,6 +17601,9 @@ rs6000_ms_bitfield_layout_p (tree record
{
    return (TARGET_USE_MS_BITFIELD_LAYOUT &&
            !lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES  
(record_type)))
+#if TARGET_MACHO
+    || darwin_ms_struct
+#endif
      || lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (record_type));
}
Index: gcc/config/darwin.c
===================================================================
--- gcc/config/darwin.c	(revision 113224)
+++ gcc/config/darwin.c	(working copy)
@@ -46,6 +46,9 @@ Boston, MA 02110-1301, USA.  */
#include "toplev.h"
#include "hashtab.h"
+/* Pragma for __attribute__ ((__ms_struct__)) */
+int darwin_ms_struct = false;
+
/* Darwin supports a feature called fix-and-continue, which is used
     for rapid turn around debugging.  When code is compiled with the
     -mfix-and-continue flag, two changes are made to the generated code
Index: gcc/config/darwin.h
===================================================================
--- gcc/config/darwin.h	(revision 113224)
+++ gcc/config/darwin.h	(working copy)
@@ -80,6 +80,9 @@ Boston, MA 02110-1301, USA.  */
#undef	DEFAULT_PCC_STRUCT_RETURN
#define DEFAULT_PCC_STRUCT_RETURN 0
+/* True if pragma ms_struct is in effect.  */
+extern GTY(()) int darwin_ms_struct;
+
/* This table intercepts weirdo options whose names would interfere
     with normal driver conventions, and either translates them into
     standardly-named options, or adds a 'Z' so that they can get to
@@ -830,6 +833,7 @@ enum machopic_addr_class {
      c_register_pragma (0, "options", darwin_pragma_options);	\
      c_register_pragma (0, "segment", darwin_pragma_ignore);	\
      c_register_pragma (0, "unused", darwin_pragma_unused);	\
+    c_register_pragma (0, "ms_struct", darwin_pragma_ms_struct); \
    } while (0)
#undef ASM_APP_ON



More information about the Gcc-patches mailing list