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 11th May 2012 at http://forums.arm.com


      Yes, but you are assuming the compiler (which parses the inline assembler and can shove it through the optimizer) actually assigns the "real" r0 to the symbolic r0 in your program and hasn't reordered any of the instructions in the instruction stream.

    I am, cause the volatile keyword should prevent that.
Reply
  • Note: This was originally posted on 11th May 2012 at http://forums.arm.com


      Yes, but you are assuming the compiler (which parses the inline assembler and can shove it through the optimizer) actually assigns the "real" r0 to the symbolic r0 in your program and hasn't reordered any of the instructions in the instruction stream.

    I am, cause the volatile keyword should prevent that.
Children
No data