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 checking of function pointer casts involving lvalues. #482

Merged
merged 1 commit into from
Apr 24, 2018
Merged

Conversation

dtarditi
Copy link
Member

A programmer reported that an indirect function call via a const member resulted in an unexpected compiler error message (Github issue #481). The problem was that the compiler was too restrictive when handling lvalue-to-rvalue casts. The lvalue-to-rvalue casts removes qualifiers on the type. The compiler was checking for the exact type.

I reworked the code for checking a function pointer cast expression. The existing code was hard to follow and there were some bugs in it. The code now has 3 distinct steps:

  1. Handle casts to checked function pointers that are valid by default.
    This includes lvalue-to-rvalue casts and bounds-safe interface casts.
  2. Otherwise, skip over value-preserving casts and value-preserving
    operations involving function pointers. Stop when you reach an expression E
    that has checked pointer type or that isn't a value-preserving cast
    or cast-like operation.
  3. Check that E is guaranteed to produce a valid function pointer:
  • E is a reference to a function name.
  • E is a null pointer.
  • E is checked pointer.

Testing:

  • Add additional tests to the Checked C repo for function pointer casts.
  • Passed local testing on Windows.
  • Passed automated testing on Linux.

A programmer reported that an indirect function call via a const
member resulted in an unexpected compiler error message (Github issue #481).
The problem was that the compiler was too restrictive when handling
lvalue-to-rvalue casts.  The lvalue-to-rvalue casts removes qualifiers
on the type.  The compiler was checking for the exact type.

I reworked the code for checking a function pointer cast expression.
The existing code was hard to follow and there were some bugs in it.
The code now has 3 distinct steps:
1. Handle casts to checked function pointers that are valid by default.
   This includes lvalue-to-rvalue casts and bounds-safe interface casts.
2. Otherwise, skip over value-preserving casts and value-preserving
   operations involving function pointers. Stop when you reach an expression E
   that has checked pointer type or that isn't a value-preserving cast
   or cast-like operation.
3. Check that E is guaranteed to produce a valid function pointer:
- E is a reference to a function name.
- E is a null pointer.
- E is checked pointer.

Testing:
- Add additional tests to the Checked C repo for function pointer casts.
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