Skip to content

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.

2 participants