-
Notifications
You must be signed in to change notification settings - Fork 38.1k
Document intentional and unintentional unsigned integer overflows (wraparounds) using annotations #14224
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
Document intentional and unintentional unsigned integer overflows (wraparounds) using annotations #14224
Conversation
Concept ACK. |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
c65df56
to
2946881
Compare
there are a few nit: technically unsigned integers don't overflow, all operators on unsigned have modulo-2 arithmetic, so all results will always fit in the resulting variable. |
2946881
to
3ac1dd2
Compare
Please don't just blindly permit existing cases that might actually be bugs. If we must do this with bypasses, the annotation macro should be different for cases where the modular arithmetic is intentional (e.g. hash functions) and where we're just silencing the warning in order to get something merged. |
@arvidn Yes, the include sorting was deliberate. Yes, the idea is to make it so that new code that relies on unsigned wrap-around semantics is annotated. I've now added the following to the developer notes to clarify:
Looks good? |
I don't agree that it is error prone. I'm aware of no study which shows as much, and it's not my experience that intentional use of modular arithmetic results in bugs. The comment should state that intentional use of it needs to be annotated because unintended wraps are often bugs and we use instrumentation to look for those bugs. But so long as the patch just papers over behaviour that is probably buggy-- or only not buggy by chance--, I think my position is NAK. |
@gmaxwell The bulk of the existing ones were handled in #11535 which was submitted almost a year ago :-) My main goal with this PR is to make sure we're not introducing new unintentional integer wrap arounds. Until #11535 is merged I'm afraid we need Please advice on how to proceed :-) |
@gmaxwell Yes, intentional use of wraparound semantics (e.g. hashing code) is obviously not problematic. I'll update the developer note to make that crystal clear. |
From the paper "Understanding Integer Overflow in C/C++" co-authored by Regehr: IOC’s instrumentation is designed to be semantically transparent for programs that conform to the C or C++ language standards, except in the case where a user requests additional checking for conforming but error-prone operations, e.g., wraparound with unsigned integer types. .-) |
ff10e92
to
3fb4531
Compare
93c466a
to
20a9c4d
Compare
20a9c4d
to
4611afc
Compare
4611afc
to
0892040
Compare
e62e22d
to
5038581
Compare
5038581
to
65c3629
Compare
…nal) or WARNING_UNINTENTIONAL_WRAPAROUND (unintentional)
65c3629
to
0373038
Compare
Add-fsanitize=integer
Travis jobALLOW_WRAPAROUND
(intentional) orWARNING_UNINTENTIONAL_WRAPAROUND
(unintentional).