Assertion error in 'get_uptodate_def_insn' relating to division by `sizeof(char)`
andy-hanson opened this issue · 3 comments
andy-hanson commented
#include <stdio.h>
struct string { char* begin; char* end; };
unsigned long size(struct string a) {
return (a.end - a.begin) / sizeof(char);
}
struct string2 {
char* begin;
unsigned long size;
};
struct string2 convert(struct string a) {
return (struct string2) {a.begin, size(a)};
}
void main(void) {
char c[3] = "foo";
struct string s = {c, c + 3};
printf("%lu\n", size(s));
}
Running c2m a.c -eg
, I get:
c2m: mir-gen.c:4600: get_uptodate_def_insn: Assertion `!gen_ctx->selection_ctx->hreg_refs_addr[hr].del_p' failed.
I've done my best to reduce this error, but it seems to depend on a pretty specific scenario.
- There's no error if you use
unsigned
instead ofunsigned long
for the size. - There's no error if you remove
convert
(which isn't used) or remove either member ofstring2
(also unused). - There's no error if you remove
/ sizeof(char)
or replace it with/ 1
.
andy-hanson commented
Update: It's not the sizeof
that's the problem, but the type of the divisor. It breaks the same if you replace sizeof(char)
with 1uLL
.
vnmakarov commented
Thank you for reporting this issue which is actually a bug in code selection pass.
I've fixed it on master by b79c0ee.
andy-hanson commented
Thanks, I confirmed it's working now.