I have a problem using the printf()
function from within LLVM IR. I just want to print the value of a float but I just get 0.000000
. It works fine for integers and strings but not floats.
Simple example:
@.fstr = private unnamed_addr constant [4 x i8] c"%f\0A\00"
declare i32 @printf(i8*, ...)
define i32 @main() {
%1 = getelementptr [4 x i8],[4 x i8]* @.fstr, i64 0, i64 0
%2 = call i32 @printf(i8* %1, double 2.0)
%3 = call i32 @printf(i8* %1, float 2.0)
ret i32 0
}
When I compile this with LLVM and link it with Clang and run the executable I get:
0.000000
0.000000
Same result if I run the .bc file with lli
. I have read this relevant post but as you see it doesn't work with doubles either.