vnmakarov/mir

Assertion error in 'get_uptodate_def_insn' relating to division by `sizeof(char)`

andy-hanson opened this issue · 3 comments

#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 of unsigned long for the size.
  • There's no error if you remove convert (which isn't used) or remove either member of string2 (also unused).
  • There's no error if you remove / sizeof(char) or replace it with / 1.

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.

Thank you for reporting this issue which is actually a bug in code selection pass.
I've fixed it on master by b79c0ee.

Thanks, I confirmed it's working now.