Allocation of records inside another record is miscompiled with memalloc optimization
type vec1 = {
arg: int
}
type record = {
vec1: vec1;
vec2: vec1;
vec3: vec1
}
node assign_records(v1, v2, v3: int)
returns (rec: record);
let
rec = { vec1 = {arg = v1};
vec2 = {arg = v2};
vec3 = {arg = v3}};
tel
The above code generates the following buggy C
code when compiled with the -only-memalloc
flag:
void Libel__assign_records_step(int v1, int v2, int v3,
Libel__assign_records_out* _out) {
_out->rec.vec1.arg = v3;
_out->rec.vec2.arg = v2;
_out->rec.vec3.arg = v1;
_out->rec.vec1 = _out->rec.vec3;
_out->rec.vec2 = _out->rec.vec2;
_out->rec.vec3 = _out->rec.vec1;
}
Here, the vec1
record types are reverse assigned and vec3
ends up reading the value v1
instead of v3
which is incorrect.