2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
6 .. index:: arguments on stack, stack arguments
10 Passing Function Arguments on the Stack
11 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13 The macros in this section control how arguments are passed
14 on the stack. See the following section for other macros that
15 control passing certain arguments in registers.
17 .. function:: bool TARGET_PROMOTE_PROTOTYPES (const_tree fntype)
19 .. hook-start:TARGET_PROMOTE_PROTOTYPES
21 This target hook returns ``true`` if an argument declared in a
22 prototype as an integral type smaller than ``int`` should actually be
23 passed as an ``int``. In addition to avoiding errors in certain
24 cases of mismatch, it also makes for better code on certain machines.
25 The default is to not promote prototypes.
29 .. function:: bool TARGET_PUSH_ARGUMENT (unsigned int npush)
31 .. hook-start:TARGET_PUSH_ARGUMENT
33 This target hook returns ``true`` if push instructions will be
34 used to pass outgoing arguments. When the push instruction usage is
35 optional, :samp:`{npush}` is nonzero to indicate the number of bytes to
36 push. Otherwise, :samp:`{npush}` is zero. If the target machine does not
37 have a push instruction or push instruction should be avoided,
38 ``false`` should be returned. That directs GCC to use an alternate
39 strategy: to allocate the entire argument block and then store the
40 arguments into it. If this target hook may return ``true``,
41 ``PUSH_ROUNDING`` must be defined.
45 .. c:macro:: PUSH_ARGS_REVERSED
47 A C expression. If nonzero, function arguments will be evaluated from
48 last to first, rather than from first to last. If this macro is not
49 defined, it defaults to ``PUSH_ARGS`` on targets where the stack
50 and args grow in opposite directions, and 0 otherwise.
52 .. c:macro:: PUSH_ROUNDING (npushed)
54 A C expression that is the number of bytes actually pushed onto the
55 stack when an instruction attempts to push :samp:`{npushed}` bytes.
57 On some machines, the definition
61 #define PUSH_ROUNDING(BYTES) (BYTES)
63 will suffice. But on other machines, instructions that appear
64 to push one byte actually push two bytes in an attempt to maintain
65 alignment. Then the definition should be
69 #define PUSH_ROUNDING(BYTES) (((BYTES) + 1) & ~1)
71 If the value of this macro has a type, it should be an unsigned type.
73 .. index:: outgoing_args_size, crtl->outgoing_args_size
75 .. c:macro:: ACCUMULATE_OUTGOING_ARGS
77 A C expression. If nonzero, the maximum amount of space required for outgoing arguments
78 will be computed and placed into
79 ``crtl->outgoing_args_size``. No space will be pushed
80 onto the stack for each call; instead, the function prologue should
81 increase the stack frame size by this amount.
83 Setting both ``PUSH_ARGS`` and ``ACCUMULATE_OUTGOING_ARGS``
86 .. c:macro:: REG_PARM_STACK_SPACE (fndecl)
88 Define this macro if functions should assume that stack space has been
89 allocated for arguments even when their values are passed in
92 The value of this macro is the size, in bytes, of the area reserved for
93 arguments passed in registers for the function represented by :samp:`{fndecl}`,
94 which can be zero if GCC is calling a library function.
95 The argument :samp:`{fndecl}` can be the FUNCTION_DECL, or the type itself
98 This space can be allocated by the caller, or be a part of the
99 machine-dependent stack frame: ``OUTGOING_REG_PARM_STACK_SPACE`` says
102 .. above is overfull. not sure what to do. -mew 5feb93 did
104 .. something, not sure if it looks good. -mew 10feb93
106 .. c:macro:: INCOMING_REG_PARM_STACK_SPACE (fndecl)
108 Like ``REG_PARM_STACK_SPACE``, but for incoming register arguments.
109 Define this macro if space guaranteed when compiling a function body
110 is different to space required when making a call, a situation that
111 can arise with K&R style function definitions.
113 .. c:macro:: OUTGOING_REG_PARM_STACK_SPACE (fntype)
115 Define this to a nonzero value if it is the responsibility of the
116 caller to allocate the area reserved for arguments passed in registers
117 when calling a function of :samp:`{fntype}`. :samp:`{fntype}` may be NULL
118 if the function called is a library function.
120 If ``ACCUMULATE_OUTGOING_ARGS`` is defined, this macro controls
121 whether the space for these arguments counts in the value of
122 ``crtl->outgoing_args_size``.
124 .. c:macro:: STACK_PARMS_IN_REG_PARM_AREA
126 Define this macro if ``REG_PARM_STACK_SPACE`` is defined, but the
127 stack parameters don't skip the area specified by it.
129 .. i changed this, makes more sens and it should have taken care of the
131 .. overfull.. not as specific, tho. -mew 5feb93
133 Normally, when a parameter is not passed in registers, it is placed on the
134 stack beyond the ``REG_PARM_STACK_SPACE`` area. Defining this macro
135 suppresses this behavior and causes the parameter to be passed on the
136 stack in its natural location.
138 .. function:: poly_int64 TARGET_RETURN_POPS_ARGS (tree fundecl, tree funtype, poly_int64 size)
140 .. hook-start:TARGET_RETURN_POPS_ARGS
142 This target hook returns the number of bytes of its own arguments that
143 a function pops on returning, or 0 if the function pops no arguments
144 and the caller must therefore pop them all after the function returns.
146 :samp:`{fundecl}` is a C variable whose value is a tree node that describes
147 the function in question. Normally it is a node of type
148 ``FUNCTION_DECL`` that describes the declaration of the function.
149 From this you can obtain the ``DECL_ATTRIBUTES`` of the function.
151 :samp:`{funtype}` is a C variable whose value is a tree node that
152 describes the function in question. Normally it is a node of type
153 ``FUNCTION_TYPE`` that describes the data type of the function.
154 From this it is possible to obtain the data types of the value and
155 arguments (if known).
157 When a call to a library function is being considered, :samp:`{fundecl}`
158 will contain an identifier node for the library function. Thus, if
159 you need to distinguish among various library functions, you can do so
160 by their names. Note that 'library function' in this context means
161 a function used to perform arithmetic, whose name is known specially
162 in the compiler and was not mentioned in the C code being compiled.
164 :samp:`{size}` is the number of bytes of arguments passed on the
165 stack. If a variable number of bytes is passed, it is zero, and
166 argument popping will always be the responsibility of the calling function.
168 On the VAX, all functions always pop their arguments, so the definition
169 of this macro is :samp:`{size}`. On the 68000, using the standard
170 calling convention, no functions pop their arguments, so the value of
171 the macro is always 0 in this case. But an alternative calling
172 convention is available in which functions that take a fixed number of
173 arguments pop them but other functions (such as ``printf``) pop
174 nothing (the caller pops all). When this convention is in use,
175 :samp:`{funtype}` is examined to determine whether a function takes a fixed
180 .. c:macro:: CALL_POPS_ARGS (cum)
182 A C expression that should indicate the number of bytes a call sequence
183 pops off the stack. It is added to the value of ``RETURN_POPS_ARGS``
184 when compiling a function call.
186 :samp:`{cum}` is the variable in which all arguments to the called function
187 have been accumulated.
189 On certain architectures, such as the SH5, a call trampoline is used
190 that pops certain registers off the stack, depending on the arguments
191 that have been passed to the function. Since this is a property of the
192 call site, not of the called function, ``RETURN_POPS_ARGS`` is not