函数属性noclone的用途

Purpose of function attribute noclone

根据gnu (https://gcc.gnu.org/onlinedocs/gcc-4.9.2/gcc/Function-Attributes.html) noclone 属性定义为:

This function attribute prevents a function from being considered for cloning—a mechanism that produces specialized copies of functions and which is (currently) performed by interprocedural constant propagation.

关于whenwhere我们应该使用这个函数属性,上面的定义意味着什么?

我知道这个属性的两个用例,都是 gcc 特有的。它们是:

  1. 如果你取一个标签的地址(GNU扩展),地址将 如果函数体是 克隆。如果您希望地址是 一样。

  2. __builtin_return_address 可能 return 个不同的 return 地址,但如果不进行克隆,它们将是相同的。

我建议不要使用这个属性,让优化器来完成它的工作。