vlang / c2v

C/C++ to V translator
GNU General Public License v3.0
223 stars 31 forks source link

UB program gets wrongly converted #143

Open trufae opened 1 year ago

trufae commented 1 year ago

This program should not even compile, but i tried it for fun because gcc/clang show 0 warnings with -Wall to see how c2v behaved with this code and resulted in some interesting bugs in the transpiler:

int
main ()
{
  char r = -1;
  unsigned s = r;
  unsigned t = (unsigned char)r;
  if (s != -1)
    return 2;
  if (t != 255)
    return 1;
  return 0;
}

is translated to:

[translated]
module main

fn main() {
    r := -1
    s := r
    t := u8(r)
    if s != -1 {
        return
    }
    if t != 255 {
        return
    }
    return
}

Note: