MrSmith33 / vox

Vox language compiler. AOT / JIT / Linker. Zero dependencies
Boost Software License 1.0
327 stars 18 forks source link

ICE(be.reg_alloc.move_solver:64): Internal error: getInfo(g1) #28

Closed rempas closed 2 years ago

rempas commented 2 years ago

I'm having a function that takes an i32 and return an u8. I will list the code that produces the error. Keep attention to the comment:

u8* i32_to_str(i32 num) {
  // These two lines both produce the error message
  if (num == 0) return "0";
  if (num == 0) return cast(u8*)'0'; // This worked in a previous commit

  u64 digit_count = 0;

  if (num < 0) {
    num = -num;
    digit_count++;
  }

  i32 tmp_num = num;
  while (tmp_num > 0) {
    digit_count++;
    tmp_num /= 10;
  }

  u8 *str = cast(u8*)malloc(digit_count + 1);
  // Same piece of code so it's commented out
  /* if (str == null) */
    /* return cast(u8*)'E'; */

  while (num > 0) {
    --digit_count;
    str[digit_count] = cast(u8)(num % 10 + '0');
    num /= 10;
  }

  if (digit_count == 1) str[0] = '-';
  /* return str; */ // Don't worry about this one, I was just testing the function
  return "174"; // Hmmmmm. This is like the first line but it works down here...
}

Also it is worth noted that this function compiled normally in a previous commit but it doesn't in the latest CI build.

MrSmith33 commented 2 years ago

Aside from the bug, some comments about the code:

This line is incorrect, because it casts the value of '0' into the pointer, so you will get the pointer with the value of 0x30.

return cast(u8*)'0';

This one is correct and returns pointer to the global memory

return "0";

Also, for int printing I use static buffers https://github.com/MrSmith33/voxelman2/blob/master/plugins/core/src/core/utils.vx#L355-L436

rempas commented 2 years ago

Man you are a genius I'm not joking!!!