问题描述
在 LLVM IR 中,如果我将 printf 定义为单个 arg func,我就可以使用它。但是,如果我将其定义为 vararg,则会出现错误:
@msg = constant [13 x i8] c"hello world\0A\00"
declare i32 @printf(i8*) ; works
;declare i32 @printf(i8*,...) ; error: '@printf' defined with type 'i32 (i8*,...)*'
; call i32 @printf(i8* %msg)
define i32 @main () {
%msg = getelementptr [13 x i8]* @msg,i64 0,i64 0
call i32 @printf(i8* %msg)
ret i32 0
}
我如何告诉 LLVM IR printf
是可变参数,但只用一个参数调用它?
解决方法
注意 description of the call
instruction in the LLVM Language Reference 中的这段话(强调我的):
- 'fnty':应该是被调用函数的签名。参数类型必须与此签名隐含的类型相匹配。 如果函数不是可变参数,则可以省略此类型。
因此,如果函数是可变参数,则您确实需要在调用指令中提供函数类型。