Skip to content

Don't add void prototypes on functions that would otherwise not need to be rewritten #688

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

Merged
merged 3 commits into from
Aug 26, 2021

Conversation

john-h-kastner
Copy link
Collaborator

This is a fix for an issue I observed while working on adding itypes to bodyless functions. A function that does not otherwise need to be rewritten will sometimes be rewritten in order to replace a missing prototype with (void). This was causing rewriting errors when an undefined function in an unwritable file was constrained to WILD in order to not add itypes on unwritable function, but it was still rewritten to use a void prototype. That particular issue doesn't exist on main prior to other change I made, but the test in this PR demonstrates another rewriting error that can be triggered.

The function is defined in a macro, so it cannot be rewritten without 3C raising an error. Constraints are generated so that the return type solve to WILD, but 3C still tries to rewrite it to insert a void prototype.

#define test_macro0 int *test_macro0()
test_macro0 {
  return 0;
}

This is fixed by only rewriting to insert the void prototype if the function already had to be rewritten for another reason.

@john-h-kastner john-h-kastner changed the title Don't add void prototypes on functions that would otherwise not neet to be rewritten Don't add void prototypes on functions that would otherwise not need to be rewritten Aug 25, 2021
@kyleheadley
Copy link
Member

Checked C will not allow a function without a prototype within a checked scope. It was my understanding that this is why 3C adds the void to explicitly indicate the empty parameter list. Could you modify this to add it to all checked/safe functions?

@john-h-kastner
Copy link
Collaborator Author

john-h-kastner commented Aug 26, 2021

Checked C will not allow a function without a prototype within a checked scope. It was my understanding that this is why 3C adds the void to explicitly indicate the empty parameter list. Could you modify this to add it to all checked/safe functions?

After these changes, 3C still adds a prototype for functions with checked or itype return types, so int *foo() { return 0; } will still convert to _Ptr<int> foo(void) { return 0; } as is required by Checked C.

CheckedC also requires that a functions has a prototype for it to be called from inside a checked scope, but this is not handled by 3C; see issue #382. The status of this issue has not changed.

Copy link
Member

@kyleheadley kyleheadley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification about the other issue. I guess the tests added here will help that one to be more thorough once we work on it.

This change looks good.

@john-h-kastner john-h-kastner merged commit 16f7573 into main Aug 26, 2021
@john-h-kastner john-h-kastner deleted the dont_add_prototype branch August 26, 2021 20:58
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.

2 participants