https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69979

Ramana Radhakrishnan <ramana at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P4
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |ramana at gcc dot gnu.org
         Resolution|---                         |INVALID

--- Comment #2 from Ramana Radhakrishnan <ramana at gcc dot gnu.org> ---
The documentation says :

This attribute allows the compiler to construct the
requisite function declaration, while allowing the body of the
function to be assembly code. The specified function will not have
prologue/epilogue sequences generated by the compiler. Only basic
@code{asm} statements can safely be included in naked functions
(@pxref{Basic Asm}). While using extended @code{asm} or a mixture of
basic @code{asm} and C code may appear to work, they cannot be
depended upon to work reliably and are not supported.


To indicate that parameters work properly with naked functions one has to
indicate to the compiler that the register parameters are being used by the
body of the inline assembler - thus I think this falls under the category of
mixing extended inline assembler and C code in the documentation above.

struct test {
  int a;
  int b;
};

void __attribute__((naked))
foo (struct test t, int a, int b)
{
  __asm ("mov r0, r3\n\t"
         "bx  lr"
         :
         :"r" (b), "r" (a), "r"(t.a), "r"(t.b)
         :);
}

Out of academic interest - the compiler does the following with recent trunk.

foo:
        @ Naked Function: prologue and epilogue provided by programmer.
        @ args = 0, pretend = 0, frame = 8
        @ frame_needed = 0, uses_anonymous_args = 0
        add      lr, sp, #8
        stmdb   lr, {r0, r1}
        ldr     r1, [sp]
        ldr      r0, [sp, #4]
         .syntax unified
      @ 9 "/tmp/r3.c" 1
        mov r0, r3
        bx  lr
       @ 0 "" 2
        .syntax unified
        .size   foo, .-foo

Hence I think invalid.

Reply via email to