leaningtech/cheerp-meta

crash in shouldDiscardValueNames

zyz9740 opened this issue · 3 comments

crash_shouldDiscardValueNames.zip

You can try this case.

A more consice version:

#include <stdio.h>

int main() {
  strcpy(0, "cd");
  return 0;
}

It's indeed invalid usage of strcpy function but may not cause crash

Hi, here there are two separate problems:

  1. the implicit assumption that IRBuilder<>::CreateGEP will actually create a GEP (e.g. https://github.com/leaningtech/cheerp-compiler/blob/master/llvm/lib/CheerpUtils/StructMemFuncLowering.cpp#L103), while potentially it might get folded into a Constant, and for the the solution is using IRBuilder (see leaningtech/cheerp-compiler@9e9e527, but I have to review it before committing).

  2. the implicit assumption in the JavaScript writer that no malformed code will get there, in this case since the call to strcpy requires a non-null argument, I am unsure whether we should be robust to that case or accept a runtime failure
    (currently the output looks like this: null[0][0]=HEAP16[(Lgeptoindexphi<<1)+1050858>>1]|0;, and will trigger a JavaScript TypeError: Cannot read properties of null (reading 0) when executing that code)

I will check with the team on both. Thanks

Although neither crashes seemed to be happening anymore, the case attached in the zip did cause a hang, which was fixed in: leaningtech/cheerp-compiler@0efaba0