corrode
corrode copied to clipboard
Corrode does'nt handle `int q[sizeof(int)]`
So can't compile this:
#include <stdio.h>
int main() {
fprintf(stdout, "Hello, world\n");
return 0;
}
The error is:
<command-line>:0:1: warning: undefining "__LINE__"
("/usr/include/libio.h": line 310): Corrode doesn't handle this yet:
15 * sizeof(int) - 4 * sizeof(void *) - sizeof(size_t)
The snippet of code in /usr/include/libio.h
:
struct _IO_FILE_complete
{
struct _IO_FILE _file;
#endif
#if defined _G_IO_IO_FILE_VERSION && _G_IO_IO_FILE_VERSION == 0x20001
_IO_off64_t _offset;
# if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
/* Wide character stream stuff. */
struct _IO_codecvt *_codecvt;
struct _IO_wide_data *_wide_data;
struct _IO_FILE *_freeres_list;
void *_freeres_buf;
size_t _freeres_size;
# else
void *__pad1;
void *__pad2;
void *__pad3;
void *__pad4;
size_t __pad5;
# endif
int _mode;
/* Make sure we don't get into trouble again. */
char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)];
#endif
};
I expect it to be some sort of a static assert.
It could be a different error, though this:
int main(void) {
int test[1 + 1];
return 0;
}
also fails with:
("test.c": line 2): Corrode doesn't handle this yet:
1 + 1
So it seems corrode doesn't know how to deal with these constant expressions yet. It seems to be a more basic issue with arrays rather than sizeof. It's also been noted before in this issue
So I think I've found what the issue is, though with my limited haskell knowledge I'm not entirely sure how to actually implement it.
The Array
variant of CType
is currently only defined to store the size as an Int. Now, array declarations are processed in derivedTypeOf
, and the size is calculated by calling interpretConstExpr
on the array size expression. This function currently only handles expressions that consist of a single constant integer, anything else will return unimplemented
.
I would think the ideal solution is to let the Array
variant store an expression. Something similar is already implemented for array indexes, though for the size one would have to validate that the size is actually a constant expression.