为什么 Module::getOrInsertFunction returns 指向常量的指针

Why Module::getOrInsertFunction returns a pointer to Constant

在 LLVM 中 Module::getOrInsertFunction 有 4 个如下所示的变体,并且全部 returns Constant*。为什么创建 Function 时返回指向 Constant 的指针?

Constant * getOrInsertFunction (StringRef Name, FunctionType *T, AttributeSet AttributeList)

documentation 内容为:

Four possibilities: 1. If it does not exist, add a prototype for the function and return it. 2. If it exists, and has a local linkage, the existing function is renamed and a new one is inserted. 3. Otherwise, if the existing function has the correct prototype, return the existing function. 4. Finally, the function exists but has the wrong prototype: return the function with a constantexpr cast to the right prototype.

对于情况 4,return 的值是 ConstantExpr*,而不是 Function*。因此,return 类型是 Constant*,公共超类。