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

Fix compiler crash on inline arrays in conditions #58

Merged
merged 1 commit into from Aug 28, 2016

Conversation

peace-maker
Copy link
Member

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.

@Fyren
Copy link
Contributor

Fyren commented Apr 27, 2016

Other places in spcomp uses "-unknown-" for situations like this.

@dvander
Copy link
Member

dvander commented Apr 27, 2016

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.

@Fyren
Copy link
Contributor

Fyren commented Apr 27, 2016

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.

@dvander
Copy link
Member

dvander commented Apr 27, 2016

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.

@peace-maker peace-maker force-pushed the const_array_cond branch 3 times, most recently from 6625d28 to 9b451e3 Compare June 12, 2016 16:12
@peace-maker
Copy link
Member Author

Changed it to print "array or string literal does not have boolean value" when there is no symbol associated.

@Fyren
Copy link
Contributor

Fyren commented Jun 12, 2016

I think if you try to do something like if ({0, 1}) then the existing invalid expression error is fine instead of a new, specific one.

@peace-maker
Copy link
Member Author

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 */
Copy link
Member

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.
@peace-maker
Copy link
Member Author

Nits picked here 🎱

@dvander dvander merged commit 79366c7 into alliedmodders:master Aug 28, 2016
@peace-maker peace-maker deleted the const_array_cond branch August 28, 2016 02:25
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

Successfully merging this pull request may close these issues.

None yet

3 participants