On Wed, Aug 19, 2015 at 9:58 AM, Segher Boessenkool <seg...@kernel.crashing.org> wrote: > On Wed, Aug 19, 2015 at 08:25:49AM -0700, H.J. Lu wrote: >> Here is a patch to add __builtin_argument_pointer. I only have > > Sorry to be a pain but... all the other builtins use _address > instead of _pointer, it's probably best to follow that. > >> -- Built-in Function: void * __builtin_argument_pointer (void) >> This function returns the argument pointer. >> >> as documentation. Can you suggest a better description so that it can >> be implemented also by other compilers? > > Maybe something like (heavily cut'n'pasted): > > > @deftypefn {Built-in Function} {void *} __builtin_argument_address (void) > This function is similar to @code{__builtin_frame_address} with an > argument of 0, but it returns the address of the incoming arguments to > the current function rather than the address of its frame.
This doesn't make senses when there is no argument or arguments are passed in registers. To me, argument pointer is a virtual concept and an implementation detail internal to GCC. I am not sure if another compiler can implement it based on this description. > The exact definition of this address depends upon the processor and the > calling convention. Usually some arguments are passed in registers and > the rest on the stack, and this builtin returns the address of the first > argument that is on the stack. > > >> + /* Can't use DRAP if the stack address has been taken. */ >> + if (cfun->argument_pointer_taken) >> + sorry ("%<__builtin_argument_pointer%> not supported with stack" >> + " realignment. This may be worked around by adding" >> + " -maccumulate-outgoing-args."); > > This doesn't work with DRAP? Pity :-( With DRAP, we do /* Replicate the return address on the stack so that return address can be reached via (argp - 1) slot. This is needed to implement macro RETURN_ADDR_RTX and intrinsic function expand_builtin_return_addr etc. */ t = plus_constant (Pmode, crtl->drap_reg, -UNITS_PER_WORD); t = gen_frame_mem (word_mode, t); insn = emit_insn (gen_push (t)); RTX_FRAME_RELATED_P (insn) = 1; /* For the purposes of frame and register save area addressing, we've started over with a new frame. */ m->fs.sp_offset = INCOMING_FRAME_SP_OFFSET; m->fs.realigned = true; which doesn't work for __builtin_argument_pointer. > The patch looks plausible, but I of course can not approve it. > Thanks. -- H.J.