For this code in my language:
type Struct:
x: Bool
Struct { x: true }
My frontend generates the following LLVM IR:
%Struct = type { i1 }
define %Struct @execute() {
%1 = alloca %Struct, align 8
%Struct.x = getelementptr inbounds %Struct, ptr %1, i32 0, i32 0
store i1 true, ptr %Struct.x, align 1
%2 = load %Struct, ptr %1, align 1
ret %Struct %2
}
However, calling this function leads to 63069 bus error
.
But if I'll write Struct { x: true }.x
, it will generate:
%Struct = type { i1 }
define i1 @execute() {
%1 = alloca %Struct, align 8
%Struct.x = getelementptr inbounds %Struct, ptr %1, i32 0, i32 0
store i1 true, ptr %Struct.x, align 1
%x = getelementptr inbounds %Struct, ptr %1, i32 0, i32 0
%2 = load i1, ptr %x, align 1
ret i1 %2
}
And this code executes correctly.
What's wrong when I return a struct?
The generated IR can be compiled by clang and executed without issues, hence it should be correct.
Looks like the error was caused by an internal bug in
llvm 16.0
, which was used to JIT-compile and run the code