leaningtech / cheerp-meta

Cheerp - a C/C++ compiler for Web applications - compiles to WebAssembly and JavaScript
https://labs.leaningtech.com/cheerp
Other
1.02k stars 50 forks source link

Floating point exception #134

Closed zyz9740 closed 7 months ago

zyz9740 commented 1 year ago
int a, b, c;
int main() {
  c = b;
  long long d, e;
  int f = b;
  _Bool g;
  for (;; b++) {
    long h = g / e;
    for (; f; ++e)
      for (; c;) {
        f = g = a;
        if (h)
          for (c = 0; d;)
            ;
      }
  }
  return 0;
}

This case has a long-term compilation in O0, works well in O1 and O2, crashes and reports "Floating point exception" on O3. You can have a try.

carlopi commented 1 year ago

Hi, here the problem I see is triggered by Assertion RHS.U.VAL != 0 && "Divide by zero?" while the code g / e is visited as part of the PartialInterpreter. e in this case will be 0, so it seems the check is right, and I expect it should be a matter of hoisting that check into visitOuter, but I will need to do also a review of other similar cases.

Hyxogen commented 7 months ago

Cannot reproduce