Hi Jakub,
But what will this do on targets where POINTER_SIZE is smaller than
BITS_PER_WORD? E.g. I think some options on s390 or ppc.
If you want it to be always 5 pointers, then you want
tmp = size_int (4);
and not something else, otherwise it really depends on how exactly it is
used, perhaps it can be 5 * MAX (BITS_PER_WORD / POINTER_SIZE, 1) - 1
or whatever else, but 5 * POINTER_SIZE / BITS_PER_WORD is definitely wrong.
Ah -I had not considered this.
OK - how about this revision ? It allocates a buffer big enough to hold
5 things, either pointers or words, whichever is bigger. The comments
are suitably adjusted as well.
Cheers
Nick
Index: gcc/except.c
===================================================================
--- gcc/except.c (revision 210096)
+++ gcc/except.c (working copy)
@@ -286,8 +286,9 @@
tmp = size_int (FIRST_PSEUDO_REGISTER + 2 - 1);
#endif
#else
- /* builtin_setjmp takes a pointer to 5 words. */
- tmp = size_int (5 * BITS_PER_WORD / POINTER_SIZE - 1);
+ /* builtin_setjmp uses a buffer big enough to hold
+ 5 pointers or 5 words, whichever is bigger. */
+ tmp = size_int ((5 * MAX (POINTER_SIZE, BITS_PER_WORD)) /
BITS_PER_WORD - 1);
#endif
tmp = build_index_type (tmp);
tmp = build_array_type (ptr_type_node, tmp);
Index: gcc/builtins.c
===================================================================
--- gcc/builtins.c (revision 210096)
+++ gcc/builtins.c (working copy)
@@ -977,10 +977,10 @@
emit_insn (gen_blockage ());
}
-/* __builtin_longjmp is passed a pointer to an array of five words (not
- all will be used on all machines). It operates similarly to the C
- library function of the same name, but is more efficient. Much of
- the code below is copied from the handling of non-local gotos. */
+/* __builtin_longjmp is passed a pointer to an array of five word/pointer
+ sized entries, not all will be used on all machines. It operates
similarly
+ to the C library function of the same name, but is more efficient. Much
+ of the code below is copied from the handling of non-local gotos. */
static void
expand_builtin_longjmp (rtx buf_addr, rtx value)
@@ -1204,10 +1204,10 @@
return const0_rtx;
}
-/* __builtin_update_setjmp_buf is passed a pointer to an array of five
words
- (not all will be used on all machines) that was passed to
__builtin_setjmp.
- It updates the stack pointer in that block to correspond to the current
- stack pointer. */
+/* __builtin_update_setjmp_buf is passed a pointer to an array of five
+ entries (not all will be used on all machines) that was passed to
+ __builtin_setjmp. It updates the stack pointer in that block to
+ correspond to the current stack pointer. */
static void
expand_builtin_update_setjmp_buf (rtx buf_addr)
@@ -6205,8 +6205,8 @@
gcc_unreachable ();
case BUILT_IN_SETJMP_SETUP:
- /* __builtin_setjmp_setup is passed a pointer to an array of five
words
- and the receiver label. */
+ /* __builtin_setjmp_setup is passed a pointer to an array of five
+ entries and the receiver label. */
if (validate_arglist (exp, POINTER_TYPE, POINTER_TYPE, VOID_TYPE))
{
rtx buf_addr = expand_expr (CALL_EXPR_ARG (exp, 0), subtarget,
@@ -6239,9 +6239,9 @@
}
break;
- /* __builtin_longjmp is passed a pointer to an array of five words.
- It's similar to the C library longjmp function but works with
- __builtin_setjmp above. */
+ /* __builtin_longjmp is passed a pointer to an array of five
+ entries. It's similar to the C library longjmp function
+ but works with __builtin_setjmp above. */
case BUILT_IN_LONGJMP:
if (validate_arglist (exp, POINTER_TYPE, INTEGER_TYPE, VOID_TYPE))
{
Index: gcc/doc/md.texi
===================================================================
--- gcc/doc/md.texi (revision 210096)
+++ gcc/doc/md.texi (working copy)
@@ -6112,10 +6112,15 @@
A typical reason why you might need this pattern is if some value, such
as a pointer to a global table, must be restored. Though it is
preferred that the pointer value be recalculated if possible (given the
-address of a label for instance). The single argument is a pointer to
-the @code{jmp_buf}. Note that the buffer is five words long and that
-the first three are normally used by the generic mechanism.
+address of a label for instance).
+The single argument is a pointer to the @code{jmp_buf}. This buffer
+is big enough to hold five @code{word_mode} or @code{Pmode} sized
+entries, whichever is bigger. The generic machanism uses just the
+first three entries, (to hold the frame pointer, return address and
+stack pointer respectively), but target specific code can use all five
+of them.
+
@cindex @code{builtin_setjmp_receiver} instruction pattern
@item @samp{builtin_setjmp_receiver}
This pattern, if defined, contains code needed at the site of a