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
Fix compiler crash on inline arrays in conditions #58
Conversation
Other places in spcomp uses "-unknown-" for situations like this. |
For something like this, we could probably add a better error message entirely. The language doesn't allow these arrays to be indexed in-line (I think, I could be wrong), so the message is misleading. When there's no variable name it could just be "array or string literal does not have boolean value" or something like that. |
If you change it to index (something like "foo"[0]) then the error you get is "invalid expression." If you want it to error in the first place it should be something like "indexing array literals is not allowed" since you can't do like {true, false}[0] either. |
Ah, okay. So indeed by saying "array must be indexed", the compiler is suggesting you do something that cannot be done. Using a different error message entirely when no symname exists is better. |
6625d28
to
9b451e3
Compare
Changed it to print "array or string literal does not have boolean value" when there is no symbol associated. |
I think if you try to do something like |
9b451e3
to
8153433
Compare
Alright, throwing an "invalid expression" error now instead of a new one. |
const char *ptr=sym->name; | ||
error(33,ptr); /* array must be indexed */ | ||
if (sym) | ||
error(33, (const char *)sym->name); /* array must be indexed */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: no cast needed here.
Code like: if ("") // blabla or if ({1,2}) // bla causes an "array must be indexed" error and crashes when it tries to print the variable name of the array - because there is none for a constant inline array. This patch throws an "invalid expression" error instead.
8153433
to
f81a19c
Compare
Nits picked here 🎱 |
Code like:
if ("") // blabla
or
if ({1,2}) // bla
causes an "array must be indexed" error and crashes when it tries to
print the variable name of the array - because there is none for a
constant inline array.
This patch just prints nothing for the variable name.