clang - error: non-ASM statement in naked function is not supported

clang - error: non-ASM statement in naked function is not supported

$ clang --version
clang version 5.0.0 (tags/RELEASE_500/final)  

.

CC ../../py/nlrthumb.c
../../py/nlrthumb.c:79:5: error: non-ASM statement in naked function is not supported
    return 0; // needed to silence compiler warning

为什么 Clang 不支持 non-ASM statement in naked function

这适用于 gcc

mailing list explains it as

Naked functions don't have prologues or epilogues, so doing codegen for anything other than inline assembly would be completely hit or miss.

那么gcc怎么做呢?

我应该把它写成答案而不是评论。问题是:

为什么Clang不支持裸函数中的非ASM语句?这在 gcc 上运行良好。

答案是 在 gcc 中 不能正常工作。从 gcc docs 中引用 naked 属性:

Only basic asm statements can safely be included in naked functions. While using extended asm or a mixture of basic asm and C code may appear to work, they cannot be depended upon to work reliably and are not supported.

如果有更明确的表达方式,我想不出。

请注意,虽然上面的特定 link 是针对 ARM 的(我猜 OP 正在使用它),但我相信相同的文本适用于支持 naked 的所有平台。