__attribute __((force))的作用是什么?

Har*_*nry 5 c attributes arm clang

听起来我应该可以使用Google,但找不到很好的参考。到底是__attribute__((force))做什么的?如:

 return (__attribute__((force)) uint32_t) *p
Run Code Online (Sandbox Code Playgroud)

(这是针对使用clang交叉编译的ARM系统,但是即使在clang / arm特定页面中,我也找不到此属性的任何引用。)

kal*_*ann 7

__attribute__((force)) 用于抑制 sparse 中的警告,Linux 内核的 c 语义检查器。

sparse维基百科文章列出了 sparse 定义的以下属性:

  • 地址空间(数量)
  • 按位
  • 力量
  • 上下文(表达式,in_context,out_context)

如果您需要有关这些的更多信息,可以查看sparse 的手册页

在 linux 内核中,一些这些属性在linux/include/linux/compiler_types.h中重新定义。例如__force扩展到__attribute__((force))__bitwise__attribute__((bitwise))

但是关于 sparselinux 文档告诉我们,gcc 忽略了这些属性:

有了 gcc,所有的“__bitwise”/“__force 东西”都消失了,最终看起来就像 gcc 的整数一样。