Reputation: 1645
I'm breaking my mind on my problem with a micro compiler wrote with the llvm and OCaml binding.
During the code generation function of my program, I have the error error: Invalid record
from llc
when I'm trying to compile a program that has some function with void type. However, it works well with all function with int type (my language support the only int).
This is a program that with LLC I have error: Invalid record
; ModuleID = 'MicrocC-module'
source_filename = "MicrocC-module"
declare i32 @print(i32)
declare i32 @getint()
define void @printem(i32 %0, i32 %1, i32 %2, i32 %3) {
entry:
%a = alloca i32
store i32 %0, i32* %a
%b = alloca i32
store i32 %1, i32* %b
%c = alloca i32
store i32 %2, i32* %c
%d = alloca i32
store i32 %3, i32* %d
%acc_var = load i32, i32* %a
%print = call i32 @print(i32 %acc_var)
%acc_var1 = load i32, i32* %b
%print2 = call i32 @print(i32 %acc_var1)
%acc_var3 = load i32, i32* %c
%print4 = call i32 @print(i32 %acc_var3)
%acc_var5 = load i32, i32* %d
%print6 = call i32 @print(i32 %acc_var5)
ret void
}
define i32 @main() {
entry:
%printem = call void @printem(i32 42, i32 17, i32 192, i32 8)
ret i32 0
}
and this is the program with all int functions, and it works without error
; ModuleID = 'MicrocC-module'
source_filename = "MicrocC-module"
declare i32 @print(i32)
declare i32 @getint()
define i32 @add(i32 %0, i32 %1) {
entry:
%a = alloca i32
store i32 %0, i32* %a
%b = alloca i32
store i32 %1, i32* %b
%acc_var = load i32, i32* %a
%acc_var1 = load i32, i32* %b
%tmp = add i32 %acc_var, %acc_var1
ret i32 %tmp
}
define i32 @main() {
entry:
%a = alloca i32
%add = call i32 @add(i32 39, i32 3)
store i32 %add, i32* %a
%acc_var = load i32, i32* %a
%print = call i32 @print(i32 %acc_var)
ret i32 0
}
My LLVM version is the 10
Upvotes: 1
Views: 1454
Reputation: 1645
I found an answer and the solution is really stupid, but I want to add an answer because some new people on LLVM can have the same problem.
as in all language does not make sense store a result on a void function, in fact, in the main of my function there is the following code
%add = call i32 @add(i32 39, i32 3)
When a function is a Void the system call in OCaml, and I think also in C++ needs an empty string as a name function (in C++ I think it is null). So the correct call is without the name %add.
In addition, I don't know why during the Ocaml build I received the error: Invalid record
error, but I download the last version of LLVM from github and run directly the llvm compiler (llc), It has given me a very well description of the error, such as
./llc: error: ./llc: /media/vincent/VincentHDD/SandBoxDev/test_llvm.ll:35:3: error: instructions returning void cannot have a name
%printem = call void @printem.1(i32 42, i32 17, i32 192, i32 8)
^
Upvotes: 4