+2008-05-23 Paul Brook <paul@codesourcery.com>
+ Carlos O'Donell <carlos@codesourcery.com>
+
+ * doc/extend.texi: Clarify use of __attribute__((naked)).
+ * doc/tm.texi: Document TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS.
+ * target.h (gcc_target): Add allocate_stack_slots_for_args.
+ * function.c (use_register_for_decl): Use
+ targetm.calls.allocate_stack_slots_for_args.
+ * target-def.h (TARGET_CALLS): Add
+ TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS.
+ * config/arm/arm.c (arm_allocate_stack_slots_for_args):
+ New function.
+ (TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS): Define.
+
2008-05-23 Eric Botcazou <ebotcazou@adacore.com>
* expr.c (highest_pow2_factor) <BIT_AND_EXPR>: New case.
static bool arm_tls_symbol_p (rtx x);
static int arm_issue_rate (void);
static void arm_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED;
+static bool arm_allocate_stack_slots_for_args (void);
\f
/* Initialize the GCC target structure. */
#undef TARGET_SETUP_INCOMING_VARARGS
#define TARGET_SETUP_INCOMING_VARARGS arm_setup_incoming_varargs
+#undef TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS
+#define TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS arm_allocate_stack_slots_for_args
+
#undef TARGET_DEFAULT_SHORT_ENUMS
#define TARGET_DEFAULT_SHORT_ENUMS arm_default_short_enums
return cfun->machine->func_type;
}
+
+bool
+arm_allocate_stack_slots_for_args (void)
+{
+ /* Naked functions should not allocate stack slots for arguments. */
+ return !IS_NAKED (arm_current_func_type ());
+}
+
\f
/* Return 1 if it is possible to return using a single instruction.
If SIBLING is non-null, this is a test for a return before a sibling
@cindex function without a prologue/epilogue code
Use this attribute on the ARM, AVR, IP2K and SPU ports to indicate that
the specified function does not need prologue/epilogue sequences generated by
-the compiler. It is up to the programmer to provide these sequences.
+the compiler. It is up to the programmer to provide these sequences. The
+only statements that can be safely included in naked functions are
+@code{asm} statements that do not have operands. All other statements,
+including declarations of local variables, @code{if} statements, and so
+forth, should be avoided. Naked functions should be used to implement the
+body of an assembly function, while allowing the compiler to construct
+the requisite function declaration for the assembler.
@item near
@cindex functions which do not handle memory bank switching on 68HC11/68HC12
call stack unwinding. It is used in declarations in @file{unwind-generic.h}
and the associated definitions of those functions.
@end defmac
+
+@deftypefn {Target Hook} {bool} TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS (void)
+When optimization is disabled, this hook indicates whether or not
+arguments should be allocated to stack slots. Normally, GCC allocates
+stacks slots for arguments when not optimizing in order to make
+debugging easier. However, when a function is declared with
+@code{__attribute__((naked))}, there is no stack frame, and the compiler
+cannot safely move arguments from the registers in which they are passed
+to the stack. Therefore, this hook should return true in general, but
+false for naked functions. The default implementation always returns true.
+@end deftypefn
bool
use_register_for_decl (const_tree decl)
{
+ if (!targetm.calls.allocate_stack_slots_for_args())
+ return true;
+
/* Honor volatile. */
if (TREE_SIDE_EFFECTS (decl))
return false;
#define TARGET_FUNCTION_VALUE default_function_value
#define TARGET_INTERNAL_ARG_POINTER default_internal_arg_pointer
+#define TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS hook_bool_void_true
#define TARGET_CALLS { \
TARGET_PROMOTE_FUNCTION_ARGS, \
TARGET_ARG_PARTIAL_BYTES, \
TARGET_INVALID_ARG_FOR_UNPROTOTYPED_FN, \
TARGET_FUNCTION_VALUE, \
- TARGET_INTERNAL_ARG_POINTER \
+ TARGET_INTERNAL_ARG_POINTER, \
+ TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS \
}
#ifndef TARGET_UNWIND_TABLES_DEFAULT
/* Return an rtx for the argument pointer incoming to the
current function. */
rtx (*internal_arg_pointer) (void);
+
+ /* Return true if all function parameters should be spilled to the
+ stack. */
+ bool (*allocate_stack_slots_for_args) (void);
+
} calls;
/* Return the diagnostic message string if conversion from FROMTYPE
+2008-05-23 Paul Brook <paul@codesourcery.com>
+ Carlos O'Donell <carlos@codesourcery.com>
+
+ * gcc.target/arm/naked-1.c: New test.
+ * gcc.target/arm/naked-2.c: New test.
+
2008-05-23 Tobias Burnus <burnus@net-b.de>
PR fortran/36314
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O0" } */
+/* Check that function arguments aren't assigned and copied to stack slots
+ in naked functions. This ususally happens at -O0 (presumably for
+ better debugging), but is highly undesirable if we haven't created
+ a stack frame. */
+void __attribute__((naked))
+foo(int n)
+{
+ __asm__ volatile ("frob r0\n");
+}
+/* { dg-final { scan-assembler "\tfrob r0" } } */
+/* { dg-final { scan-assembler-not "\tstr" } } */
--- /dev/null
+/* Verify that __attribute__((naked)) produces a naked function
+ that does not use bx to return. Naked functions could be used
+ to implement interrupt routines and must not return using bx. */
+/* { dg-do compile } */
+/* { dg-options "-O0" } */
+/* Use more arguments than we have argument registers. */
+int __attribute__((naked)) foo(int a, int b, int c, int d, int e, int f)
+{
+ __asm__ volatile ("@ naked");
+}
+/* { dg-final { scan-assembler "\t@ naked" } } */
+/* { dg-final { scan-assembler-not "\tbx\tlr" } } */