LLVM 提供的 main() 类型无效 return

LLVM Invalid return type of main() supplied

我正在用 OCaml 编写一个编译器,它可以编译为 LLVM IR。目前的程序很简单:

num main() {
    return 0;
}

当我用我的编译器 运行 时,我得到以下 LLVM IR 代码:

; ModuleID = 'PixMix'
source_filename = "PixMix"

@fmt = private unnamed_addr constant [4 x i8] c"%d[=12=]A[=12=]"
@fmt.1 = private unnamed_addr constant [4 x i8] c"%s[=12=]A[=12=]"

declare i32 @printf(i8*, ...)

define double @main() {
entry:
  ret double 0.000000e+00
}

但是,如果我将它传递给 lli,我会被告知 return 类型无效。查看该代码,main 被定义为 double 并且它是 returning 一个 double,那么为什么 lli 告诉我 return类型乱了?

问题在于入口点函数(默认为main,但名称可由-entry-function标志控制)预期具有特定签名,类似于main 看起来像在 C 或 C++ 中。特别是,它应该是 return void 或整数类型。您可以阅读 the implementation of the check 以确保您生成的 IR 满足它。