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

    [color=#222222][size=2]
    returning the value in R0 is defined in the AAPCS
    [/size][/color]
    [color=#222222][size=2]
    [/size][/color]
    [color=#222222][size=2]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.[/size][/color]
    [color=#222222][size=2]
    [/size][/color]
    [color=#222222][size=2]In this case it happens to work because the output of the function is trivial, so the compiler has been sensible, but for a more complex "non trivial" example I'm not sure what guarantees you get from the compiler in terms of it deciding to reallocate registers to something it deems more optimal.[/size][/color]
    [size=2]
    [/size]
Reply
  • Note: This was originally posted on 10th May 2012 at http://forums.arm.com

    [color=#222222][size=2]
    returning the value in R0 is defined in the AAPCS
    [/size][/color]
    [color=#222222][size=2]
    [/size][/color]
    [color=#222222][size=2]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.[/size][/color]
    [color=#222222][size=2]
    [/size][/color]
    [color=#222222][size=2]In this case it happens to work because the output of the function is trivial, so the compiler has been sensible, but for a more complex "non trivial" example I'm not sure what guarantees you get from the compiler in terms of it deciding to reallocate registers to something it deems more optimal.[/size][/color]
    [size=2]
    [/size]
Children
No data