我有一些用gcc交叉编译器编译的PowerPC汇编代码,其中包含以下函数:
uint32_t fill_cache(void)
{
__asm__ ("addi 3, 0, 0\n"); /* R3 = 0 */
/* More asm here modifying R3 and filling the cache lines. */
}
在PowerPC EABI下,它返回在R3中计算的值。在编译时,我得到
foo.c:105: warning: control reaches end of non-void function
有没有一种方法可以教会gcc,一个值实际上是返回的?或者有没有办法抑制警告(无需删除-Wall或添加-Wno-*)?我想有选择地仅对此函数取消此警告,以便将常规警告级别保持在尽可能高的水平。
不能让此函数返回void,因为调用者需要计算出的值。
发布于 2017-03-07 07:49:22
函数可以声明为naked
,在这种情况下,编译器不会生成prolog和epilog,并假设程序员保留了所有必要的寄存器,并在返回之前将输出值放入正确的寄存器中。
uint32_t fill_cache(void) __attribute__((naked)); // Declaration
// attribute should be specified in declaration not in implementation
uint32_t fill_cache(void)
{
__asm__ ("addi 3, 0, 0\n"); /* R3 = 0 */
/* More asm here modifying R3 and filling the cache lines. */
}
有点晚了,但也许会有人插手这件事:)
PS:据我所知,__asm__
和__volatile__
都是std=c89
语法。实际上,在GNU GCC中,__asm__
和asm
是没有区别的。但现代的方法是无底线的风格:asm volatile
。
https://stackoverflow.com/questions/15927583
复制相似问题