This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: Darwin pragmas and pragma doc, rev 2
- To: gcc-patches at gcc dot gnu dot org
- Subject: PATCH: Darwin pragmas and pragma doc, rev 2
- From: Stan Shebs <shebs at apple dot com>
- Date: Wed, 27 Jun 2001 14:08:04 -0700
OK, this version incorporates all suggestions (I think), bootstraps
with powerpc-apple-darwin1.3, etc. I've tested the manual addition
with "make info" but not "make dvi" because I don't have the right
bits here right now, but I won't commit it until it's been checked.
As a special bonus :-), I added a subsection for the ARM pragmas,
but there are six other architectures with target-specific pragmas
that somebody needs to describe. Probably worthwhile to have
an additional subsection for #pragma weak and #pragma pack, they're
hinted at in several places but not formally described anywhere.
Stan
2001-06-27 Stan Shebs <shebs@apple.com>
* config/darwin.h (REGISTER_TARGET_PRAGMAS): Define.
* config/darwin-c.c: New file.
* config/darwin-protos.h: Declare new functions.
* config/rs6000/t-darwin (darwin-c.o): New rule.
* config.gcc (powerpc-*-darwin*): Define c_target_objs and
cxx_target_objs.
* doc/extend.texi (Pragmas): New section.
2001-06-27 Stan Shebs <shebs@apple.com>
* gcc.dg/pragma-darwin.c: New test.
Index: config.gcc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config.gcc,v
retrieving revision 1.69
diff -c -3 -p -r1.69 config.gcc
*** config.gcc 2001/06/26 03:50:47 1.69
--- config.gcc 2001/06/27 20:56:16
*************** powerpc-*-darwin*)
*** 2569,2574 ****
--- 2569,2576 ----
# fixed and we can get rid of this silliness.
xm_defines="HAVE_DESIGNATED_INITIALIZERS=0"
extra_objs="darwin.o"
+ c_target_objs="darwin-c.o"
+ cxx_target_objs="darwin-c.o"
# Darwin linker does collect2 functionality
use_collect2=no
;;
Index: doc/extend.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/extend.texi,v
retrieving revision 1.12
diff -c -3 -p -r1.12 extend.texi
*** extend.texi 2001/06/27 15:04:15 1.12
--- extend.texi 2001/06/27 20:56:17
*************** extensions, accepted by GCC in C89 mode
*** 73,78 ****
--- 73,79 ----
function.
* Return Address:: Getting the return or frame address of a function.
* Other Builtins:: Other built-in functions.
+ * Pragmas:: Pragmas accepted by GCC.
@end menu
@end ifset
@ifclear INTERNALS
*************** extensions, accepted by GCC in C89 mode
*** 125,130 ****
--- 126,132 ----
function.
* Return Address:: Getting the return or frame address of a function.
* Other Builtins:: Other built-in functions.
+ * Pragmas:: Pragmas accepted by GCC.
@end menu
@end ifclear
*************** if (__builtin_expect (ptr != NULL, 1))
*** 3908,3913 ****
--- 3910,3992 ----
@noindent
when testing pointer or floating-point values.
@end deftypefn
+
+ @node Pragmas
+ @section Pragmas Accepted by GCC
+ @cindex pragmas
+ @cindex #pragma
+
+ GCC supports several types of pragmas, primarily in order to compile
+ code originally written for other compilers. Note that in general
+ we do not recommend the use of pragmas; @xref{Function Attributes},
+ for further explanation.
+
+ @menu
+ * ARM Pragmas::
+ * Darwin Pragmas::
+ @end menu
+
+ @node ARM Pragmas
+ @subsection ARM Pragmas
+
+ The ARM target defines pragmas for controlling the default addition of
+ @code{long_call} and @code{short_call} attributes to functions.
+ @xref{Function Attributes}, for information about the effects of these
+ attributes.
+
+ @table @code
+ @item long_calls
+ @cindex pragma, long_calls
+ Set all subsequent functions to have the @code{long_call} attribute.
+
+ @item no_long_calls
+ @cindex pragma, no_long_calls
+ Set all subsequent functions to have the @code{short_call} attribute.
+
+ @item long_calls_off
+ @cindex pragma, long_calls_off
+ Do not affect the @code{long_call} or @code{short_call} attributes of
+ subsequent functions.
+ @end table
+
+ @c Describe c4x pragmas here.
+ @c Describe h8300 pragmas here.
+ @c Describe i370 pragmas here.
+ @c Describe i960 pragmas here.
+ @c Describe sh pragmas here.
+ @c Describe v850 pragmas here.
+
+ @node Darwin Pragmas
+ @subsection Darwin Pragmas
+
+ The following pragmas are available for all architectures running the
+ Darwin operating system. These are useful for compatibility with other
+ MacOS compilers.
+
+ @table @code
+ @item mark @var{tokens}@dots{}
+ @cindex pragma, mark
+ This pragma is accepted, but has no effect.
+
+ @item options align=@var{alignment}
+ @cindex pragma, options align
+ This pragma sets the alignment of fields in structures. The values of
+ @var{alignment} may be @code{mac68k}, to emulate m68k alignment, or
+ @code{power}, to emulate PowerPC alignment. Uses of this pragma nest
+ properly; to restore the previous setting, use @code{reset} for the
+ @var{alignment}.
+
+ @item segment @var{tokens}@dots{}
+ @cindex pragma, segment
+ This pragma is accepted, but has no effect.
+
+ @item unused (@var{var} [, @var{var}]@dots{})
+ @cindex pragma, unused
+ This pragma declares a variable to be possibly unused. GCC will not
+ produce a warning for this variable. The effect is similar to that
+ of the unused attribute, except that this pragma may appear anywhere
+ within the variable's scope.
+ @end table
@node C++ Extensions
@chapter Extensions to the C++ Language
Index: config/darwin-c.c
===================================================================
RCS file: darwin-c.c
diff -N darwin-c.c
*** /dev/null Tue May 5 13:32:27 1998
--- darwin-c.c Wed Jun 27 13:56:17 2001
***************
*** 0 ****
--- 1,153 ----
+ /* Darwin support needed only by C/C++ frontends.
+ Copyright (C) 2001
+ Free Software Foundation, Inc.
+ Contributed by Apple Computer Inc.
+
+ This file is part of GNU CC.
+
+ GNU CC is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ GNU CC is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNU CC; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+ #include "config.h"
+ #include "system.h"
+ #include "cpplib.h"
+ #include "tree.h"
+ #include "c-pragma.h"
+ #include "c-lex.h"
+ #include "c-tree.h"
+ #include "toplev.h"
+ #include "tm_p.h"
+
+ /* Pragmas. */
+
+ #define BAD(msgid) do { warning (msgid); return; } while (0)
+
+ /* Maintain a small stack of alignments. This is similar to pragma
+ pack's stack, but simpler. */
+
+ static void push_field_alignment PARAMS ((int));
+ static void pop_field_alignment PARAMS ((void));
+
+ typedef struct align_stack
+ {
+ int alignment;
+ struct align_stack * prev;
+ } align_stack;
+
+ static struct align_stack * field_align_stack = NULL;
+
+ static void
+ push_field_alignment (bit_alignment)
+ int bit_alignment;
+ {
+ align_stack *entry = (align_stack *) xmalloc (sizeof (align_stack));
+
+ entry->alignment = maximum_field_alignment;
+ entry->prev = field_align_stack;
+ field_align_stack = entry;
+
+ maximum_field_alignment = bit_alignment;
+ }
+
+ static void
+ pop_field_alignment ()
+ {
+ if (field_align_stack)
+ {
+ align_stack *entry = field_align_stack;
+
+ maximum_field_alignment = entry->alignment;
+ field_align_stack = entry->prev;
+ free (entry);
+ }
+ else
+ error ("too many #pragma options align=reset");
+ }
+
+ /* Handlers for Darwin-specific pragmas. */
+
+ void
+ darwin_pragma_ignore (pfile)
+ cpp_reader *pfile ATTRIBUTE_UNUSED;
+ {
+ /* Do nothing. */
+ }
+
+ /* #pragma options align={mac68k|power|reset} */
+
+ void
+ darwin_pragma_options (pfile)
+ cpp_reader *pfile ATTRIBUTE_UNUSED;
+ {
+ char *arg;
+ tree t, x;
+
+ if (c_lex (&t) != CPP_NAME)
+ BAD ("malformed '#pragma options', ignoring");
+ arg = IDENTIFIER_POINTER (t);
+ if (strcmp (arg, "align"))
+ BAD ("malformed '#pragma options', ignoring");
+ if (c_lex (&t) != CPP_EQ)
+ BAD ("malformed '#pragma options', ignoring");
+ if (c_lex (&t) != CPP_NAME)
+ BAD ("malformed '#pragma options', ignoring");
+
+ if (c_lex (&x) != CPP_EOF)
+ warning ("junk at end of '#pragma options'");
+
+ arg = IDENTIFIER_POINTER (t);
+ if (!strcmp (arg, "mac68k"))
+ push_field_alignment (16);
+ else if (!strcmp (arg, "power"))
+ push_field_alignment (0);
+ else if (!strcmp (arg, "reset"))
+ pop_field_alignment ();
+ else
+ warning ("malformed '#pragma options align={mac68k|power|reset}', ignoring");
+ }
+
+ /* #pragma unused ([var {, var}*]) */
+
+ void
+ darwin_pragma_unused (pfile)
+ cpp_reader *pfile ATTRIBUTE_UNUSED;
+ {
+ tree decl, x;
+ int tok;
+
+ if (c_lex (&x) != CPP_OPEN_PAREN)
+ BAD ("missing '(' after '#pragma unused', ignoring");
+
+ while (1)
+ {
+ tok = c_lex (&decl);
+ if (tok == CPP_NAME && decl)
+ {
+ tree local = IDENTIFIER_LOCAL_VALUE (decl);
+ if (local && (TREE_CODE (local) == PARM_DECL
+ || TREE_CODE (local) == VAR_DECL))
+ TREE_USED (local) = 1;
+ tok = c_lex (&x);
+ if (tok != CPP_COMMA)
+ break;
+ }
+ }
+
+ if (tok != CPP_CLOSE_PAREN)
+ BAD ("missing ')' after '#pragma unused', ignoring");
+
+ if (c_lex (&x) != CPP_EOF)
+ warning ("junk at end of '#pragma unused'");
+ }
Index: config/darwin-protos.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/darwin-protos.h,v
retrieving revision 1.2
diff -c -3 -p -r1.2 darwin-protos.h
*** darwin-protos.h 2001/06/08 02:28:04 1.2
--- darwin-protos.h 2001/06/27 20:56:17
*************** extern void darwin_encode_section_info P
*** 56,58 ****
--- 56,65 ----
#endif /* TREE_CODE */
extern void machopic_finish PARAMS ((FILE *));
+
+ #ifdef GCC_C_PRAGMA_H
+ extern void darwin_init_pragma PARAMS ((int (*) (tree *)));
+ extern void darwin_pragma_ignore PARAMS ((cpp_reader *));
+ extern void darwin_pragma_options PARAMS ((cpp_reader *));
+ extern void darwin_pragma_unused PARAMS ((cpp_reader *));
+ #endif
Index: config/darwin.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/darwin.h,v
retrieving revision 1.6
diff -c -3 -p -r1.6 darwin.h
*** darwin.h 2001/06/12 00:27:31 1.6
--- darwin.h 2001/06/27 20:56:17
*************** enum machopic_addr_class {
*** 780,782 ****
--- 780,789 ----
} \
} while (0)
+ #define REGISTER_TARGET_PRAGMAS(PFILE) \
+ do { \
+ cpp_register_pragma (PFILE, 0, "mark", darwin_pragma_ignore); \
+ cpp_register_pragma (PFILE, 0, "options", darwin_pragma_options); \
+ cpp_register_pragma (PFILE, 0, "segment", darwin_pragma_ignore); \
+ cpp_register_pragma (PFILE, 0, "unused", darwin_pragma_unused); \
+ } while (0)
Index: config/rs6000/t-darwin
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/t-darwin,v
retrieving revision 1.3
diff -c -3 -p -r1.3 t-darwin
*** t-darwin 2001/05/25 19:50:50 1.3
--- t-darwin 2001/06/27 20:56:18
*************** fp-bit.c: $(srcdir)/config/fp-bit.c
*** 12,20 ****
darwin.o: $(srcdir)/config/darwin.c $(CONFIG_H) $(SYSTEM_H) $(RTL_BASE_H) \
$(REGS_H) hard-reg-set.h insn-config.h conditions.h output.h \
! insn-attr.h flags.h $(TREE_H) $(EXPR_H) reload.h $(C_TREE_H) \
function.h $(GGC_H) $(TM_P_H)
! $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(srcdir)/config/darwin.c
# Build the libraries for both hard and soft floating point
--- 12,25 ----
darwin.o: $(srcdir)/config/darwin.c $(CONFIG_H) $(SYSTEM_H) $(RTL_BASE_H) \
$(REGS_H) hard-reg-set.h insn-config.h conditions.h output.h \
! insn-attr.h flags.h $(TREE_H) $(EXPR_H) reload.h \
function.h $(GGC_H) $(TM_P_H)
! $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $<
!
! darwin-c.o: $(srcdir)/config/darwin-c.c $(CONFIG_H) $(SYSTEM_H) \
! $(TREE_H) $(C_TREE_H) c-lex.h c-pragma.h toplev.h cpplib.h \
! $(TM_P_H)
! $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $<
# Build the libraries for both hard and soft floating point
Index: testsuite/gcc.dg/pragma-darwin.c
===================================================================
RCS file: pragma-darwin.c
diff -N pragma-darwin.c
*** /dev/null Tue May 5 13:32:27 1998
--- pragma-darwin.c Wed Jun 27 13:56:19 2001
***************
*** 0 ****
--- 1,59 ----
+ /* Darwin (Mac OS X) pragma exercises. */
+
+ /* { dg-do run { target powerpc-*-darwin* } } */
+ /* { dg-options "-O -Wunused" } */
+
+ /* The mark pragma is to help decorate IDEs. */
+
+ #pragma mark hey hey ho
+
+ /* The options pragma used to do a lot, now it's only for emulating
+ m68k alignment rules in structs. */
+
+ #pragma options 23 /* { dg-error "malformed '#pragma options'" } */
+ #pragma options align /* { dg-error "malformed '#pragma options'" } */
+ #pragma options align mac68k /* { dg-error "malformed '#pragma options'" } */
+ #pragma options align=45 /* { dg-error "malformed '#pragma options'" } */
+ #pragma options align=foo /* { dg-error "malformed '#pragma options align" } */
+
+ #pragma options align=mac68k
+ struct s1 { short f1; int f2; };
+ #pragma options align=power
+ struct s2 { short f1; int f2; };
+ #pragma options align=mac68k
+ struct s3 { short f1; int f2; };
+ #pragma options align=reset
+ struct s4 { short f1; int f2; };
+
+ #pragma options align=mac68k foo /* { dg-warning "junk at end of '#pragma options'" } */
+
+ /* Segment pragmas don't do anything anymore. */
+
+ #pragma segment foo
+
+ int
+ main ()
+ {
+ int x, z; /* { dg-warning "unused variable" } */
+ #pragma unused (x, y)
+
+ if (sizeof (struct s1) != 6)
+ abort ();
+ if (sizeof (struct s2) != 8)
+ abort ();
+ if (sizeof (struct s3) != 6)
+ abort ();
+ if (sizeof (struct s4) != 8)
+ abort ();
+ return 0;
+ }
+
+ void
+ unused_err_test ()
+ {
+ int a, b;
+ /* Trying to match on '(' or ')' gives regexp headaches, use . instead. */
+ #pragma unused /* { dg-error "missing '.' after '#pragma unused" } */
+ #pragma unused (a /* { dg-error "missing '.' after '#pragma unused" } */
+ #pragma unused (b) foo /* { dg-warning "junk at end of '#pragma unused'" } */
+ }