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

Compilation timeout #127

Closed zyz9740 closed 1 year ago

zyz9740 commented 1 year ago

I find a strange situation when compiling a C program with both infinite loop and printf . Code is as follows:

#include <stdio.h>

int a = 1;
int main() {
  printf("%d",a);
  for (;;) {}
  return 0;
}
# It works well
gcc random.c 
# CPU 100% in opt process, also in O3
/opt/cheerp/bin/clang -target cheerp-wasm random.c -O3 -o random_cheerp.js

GCC compiles it well. But when using cheerp, I wait for a long time but it is still compiling. "top" shows that it is stuck in opt process. I think it may relate to some infinite loop optimization ? Note that printf and an infinite loop must both occur.

Can you reproduce this ?

carlopi commented 1 year ago

I can't reproduce, as in with most update version of Cheerp this seems to work as expected.

This is potentially connected to a fix that was added a few months back to fix this sort of situation: https://github.com/leaningtech/cheerp-compiler/commit/1db4772a01b70821f0038140702155cd8f2c78b4, which version of the compiler are you using? Can you give it another try with the nightly packages?

zyz9740 commented 1 year ago

I excuted /opt/cheerp/bin/clang -v and I got this:

Cheerp 1658127505-1~focal clang version 15.0.0
Target: cheerp-leaningtech-webbrowser-wasm
Thread model: posix
InstalledDir: /opt/cheerp/./bin

What's the meaning of "1658127505-1~focal" ? I don't know how to get the version number like "2.7"

As to the result of nightly version, I will update my cheerp and come soon.

carlopi commented 1 year ago

I think that refers to the identifier of the build, as in here: https://launchpad.net/~leaningtech-dev/+archive/ubuntu/cheerp-nightly-ppa/+packages.

So probably you are actually already using nightly's PPA, and should be just a matter of running apt upgrade

carlopi commented 1 year ago

Just checked again, this is fixed in the current nightly version of Cheerp, thanks.