18022, "ShreyasKhandekar", "LLVM Assertion Error in C interoperability example", "2021-07-01T20:20:39Z"
There seems to be some issue with the LLVM back-end on a case I am coming across with an example to demonstrate Chapel's interoperability with C.
I was trying a simple struct example:
The Chapel file is:
extern record data{
var x: c_int;
}
extern proc getNewData() : data;
var d :data;
d = getNewData();
The .h file is:
typedef struct _data data;
data getNewData(void);
and the .c file is:
struct _data {
int x;
};
data getNewData(){
data *d = malloc(sizeof(data));
d->x = 5;
return *d;
}
I have omitted some boilerplate code from all files like #ifndef
s and the necessarry includes
With the above files, I got the following error during compilation:
internal error: assertion error [llvm/clangUtil.cpp:2922]
It does not matter if I return a pointer (and use the ref intent) or just return the struct itself. I get the same error.
The way to fix this was to move the struct definition completely into the header file instead of the C file.
But I believe it should also work if the struct definition is in the C file.