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 duplicate messages for illegal void pointer arithmetic. #563

Merged
merged 5 commits into from Sep 20, 2018

Conversation

dtarditi
Copy link
Contributor

@dtarditi dtarditi commented Sep 11, 2018

The compiler was emitting duplicate error messages for void pointer arithmetic using checked pointers in bounds expressions. The problem was that the logic for marking the expression as invalid is separate from actually emitting the diagnostic. The logic only looked for the language being C++. The fix is to look for the conditions related to Checked C also. This fixes issue #543.

This caused a duplicate error messages because the expression wasn't turned into an invalid expression. When a subsequent TreeTransform pass for bounds declaration checking ran, it emitted the diagnostic a second time when it encountered the expression again.

I noticed that we had some logic for handling pointer arithmetic involving function pointers. This is allowed by a GCC extension. For checked pointers, we never allow _Array_ptrs to function pointers. We only allow _Ptrs to function pointers. Pointer arithmetic is never allowed for _Ptrs, so we never reach this logic. I converted the logic to an assert and added some comments.

Testing:

  • I added a new Checked C clang regression test for these cases that checks hat only one error message is emitted.
  • Passed automated testing.

The compiler was emitting duplicate error messages for void pointer
arithmetic involving checking pointers in bounds expressions.  The problem
was that the logic for marking the expression is invalid is separate from
actually emitting the diagnostic.  The logic only looked for the language
being C++.  The fix is to look for the conditions related to Checked C also.

This caused a duplicate error messages beccause the expression wasn't turned
into an invalid expression.  When a subsequent TreeTransform pass for bounds
declaration checking ran, it emitted the diagnostic a second time when it
encountered the expression again.

I noticed that we had some logic for handling pointer arithmetic involving
function pointers.  This is allowed by a GCC extension.  For checked pointers,
we never allow _Array_ptrs to function pointers.  We only allow _Ptrs to
function pointers.  Pointer arithmetic is never allowed for _Ptrs, so we
never reach this logic.  I converted the logic to an assert and added
some comments.

Testing:
- I added a new Checked C clang regression test for these cases that checks
 that only   one error message is emitted.
I wrote some additional tests. It turns out the code paths where
I added assert are reached even for checked pointers.  Remove
asserts and add test casss that make sure that other errors
that should logically preclude the pointer arithmetic actually
occur.
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

1 participant