This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

compiler warning in function with embedded assembly

Note: This was originally posted on 9th May 2012 at http://forums.arm.com

I'm using inline ARM assembly in C++ functions and I was wondering how to avoid "control reaches end of non-void function" warnings when my code is storing the final value in R0.

For example this function works fine, but the compiler will raise the warning:


int Math::test_iadd(int a, int B)
{  
  __asm volatile
(
  "add r0, %0, %1   \n\t"

  :
  : "r" (a), "r" (B)
  : "r0"
);
}

An easy fix is rewriting the function as:


int Math::test_iadd2(int a, int B)
{
int ret;

__asm volatile
(
  "add %0, %1, %2   \n\t"

  : "=r" (ret)
  : "r" (a), "r" (B)
  : "r0"
);


return ret;
}

But this shouldn't be required as the assembly generated by the compiler is basically the same code I use in the former function.

Any suggestion?
Parents
  • Note: This was originally posted on 10th May 2012 at http://forums.arm.com


    I could be wrong, but I believe that this code does not actually guarantee that the output ends up in r0. The register identities in the assembler are symbolic rather than actual register names, and I'm not sure how they actually get resolved to real registers. It's the logical output however, so it happens to work.
    Your second function is certainly the way I would write the return code.

    returning the value in R0 is defined in the AAPCS (ARM Architecture Procedure Call Standard) and even if R0 is just an alias for a physical register the mapping should be transparent to the coder.

    I do agree with spachner as the problem is generated by the C++ compiler, but I was wondering if there was a way to suppress it mixing ASM and C++, anyway better safe than sorry, so I'd go for the code style used in the second function, cheers.
Reply
  • Note: This was originally posted on 10th May 2012 at http://forums.arm.com


    I could be wrong, but I believe that this code does not actually guarantee that the output ends up in r0. The register identities in the assembler are symbolic rather than actual register names, and I'm not sure how they actually get resolved to real registers. It's the logical output however, so it happens to work.
    Your second function is certainly the way I would write the return code.

    returning the value in R0 is defined in the AAPCS (ARM Architecture Procedure Call Standard) and even if R0 is just an alias for a physical register the mapping should be transparent to the coder.

    I do agree with spachner as the problem is generated by the C++ compiler, but I was wondering if there was a way to suppress it mixing ASM and C++, anyway better safe than sorry, so I'd go for the code style used in the second function, cheers.
Children
No data