-
Notifications
You must be signed in to change notification settings - Fork 165
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
Missing return value in initialize_lexer #196
Comments
I didn't manage to reproduce this with master. Here is how I tried: bnfc CPP.cf -o tmp --cpp -m
make -C tmp CC=clang++ CCFLAGS='' -B But it seems that |
You need to run the parser. My output is:
|
What version of bnfc are you using? It seem that using master, the problem has been fixed. This is what I have in void initialize_lexer(FILE *inp) { yyrestart(inp); BEGIN YYINITIAL; } |
I got the bug using the latest release, but I can't reproduce the actual crash in master, so I guess that's fixed. However,
It seems g++/clang++ can handle this and generate correct code, so it's not really a critical bug. |
Thanks for looking at it. We should nonetheless make them consistent 👍 |
Couldn't reproduce the problem, but fixed the return type of |
Generating a C++ parser from this grammar[1] produces code that crashes under clang++. The reason is that bnfc it doesn't write a return statement in the initialize_lexer function:
BEGIN is #defined as
#define BEGIN (yy_start) = 1 + 2 *
and YYINITIAL as#define YYINITIAL 1
.So there is no return in this function which will result in SIGILL when compiled with clang++ (because it's undefined behavior in C++).
A simple fix for me was to add a simple "return 0;" at the end because the return value is never used in my parser. Looking at the code in bfnc that generates the lexer that doesn't seem like a reuseable fix though.
[1] http://www.cse.chalmers.se/edu/year/2016/course/DAT151_Programming_Language_Technology/laborations/lab2/CPP.cf
The text was updated successfully, but these errors were encountered: