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

Parsing of unprototyped function types in casts #431

Merged
merged 1 commit into from
May 9, 2022

Conversation

xavierleroy
Copy link
Contributor

Currently, in the context of casts, the unprotototyped function type int (*)() is parsed like the prototyped function type int (*)(void). This causes the following example to be rejected:

int f(int x) { return x; }

int main() { return ((int (*)()) &f)(42); }

CompCert complains that a function of zero arguments is applied to one argument. This example is accepted by GCC and Clang, and seems correct according to the ISO C standards.

This is probably a leftover from the days when CompCert didn't fully support unprototyped functions.

It's only casts that have this problem; declarations are correctly parsed, e.g. int (*f)(); and int (*f)(void); have different types.

This PR is the trivial fix for this problem. It needs some testing, though.

Before, in casts, `int (*)()` was parsed like `int (*)(void)`.
Declarations were correctly parsed.
@xavierleroy
Copy link
Contributor Author

Testing came back positive. Merging!

@xavierleroy xavierleroy merged commit 1d572b3 into master May 9, 2022
@xavierleroy xavierleroy deleted the unprototyped-function-types branch May 9, 2022 12:48
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.

1 participant