Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The compiler runs into Stack Overflow if compiled using CLANG on Windows or Visual Studio C++ and set to compile Analog Clock #5

Open
FlatAssembler opened this issue Jul 15, 2021 · 4 comments

Comments

@FlatAssembler
Copy link
Owner

FlatAssembler commented Jul 15, 2021

AECforWebAssembly v1.5 crashes if compiled with CLANG on Windows or Visual Studio C++ and is set to compile Analog Clock. It runs into Stack Overflow. Here is what the debugger in Visual Studio outputs:

image

So, the error appears to occur in Analog Clock program on line 358, when compiling the 60 token. convertToInteger64 calls compile, which in turns calls convertTo which again calls convertToInteger64. I do not think this loop is infinite, as the error disappears on CLANG if the program is compiled with -O3 (although I could be triggering some Undefined Behavior again leading to my program behaving unpredictably). But, obviously, the recursion runs deep enough to cause Stack Overflow in some cases under some compilers.

This problem appears not to exist (or at least obviously show up, if my C++ code is again triggering some undefined behavior as the parsing code once used to) under any version of GCC, be it under Windows, Linux or FreeDOS.

@FlatAssembler
Copy link
Owner Author

FlatAssembler commented Jul 16, 2021

A Discord user called @zero9178 commented the following:

Do you know what a stackoverflow is? Chances are you got a recursive function and/or some very large objects that causes your stack to overflow. Optimizations will make the code and functions and such smaller hence it working when using optimizations. Debuggers should halt on stack overflow, check the recursive functions there. If it's easy, try turning the recursive algorithm into an iterative one, otherwise try reducing the size of some classes or allocate some things on the heap. Hard to tell where the issue is. There is also -fstack-usage in GCC that will tell you how many bytes a function occupies
Should help with the search

@FlatAssembler
Copy link
Owner Author

Perhaps we can at least make the problem less severe by outputting a sensible error message in that case. I have started a forum thread asking how to do that: https://atheistforums.org/thread-63150.html

@FlatAssembler
Copy link
Owner Author

I have tweaked it into working when compiled using CLANG on Windows, but I still have not managed to make it work if compiled using Visual Studio: 8e70e2f

@FlatAssembler
Copy link
Owner Author

Unfortunately, I just tried compiling AECforWebAssembly with the latest version of Emscripten, and I get the same "Stack Overflow" error when compiling the Analog Clock program. This time, compiling with -O3 optimisation does not help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant