-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
React to CheckForOverflowUnderflow in regex source generator #78228
Conversation
The regex source generator uses code patterns that might have arithmetic overflows, e.g. a bounds check with `(uint)index < span.Length`. These are intentional, and they're benign... unless the project/compilation has opted-in to overflow/underflow checking (CheckForOverflowUnderflow). In that case, the code for many patterns can start throwing false positive overflow exceptions, making the source generator unusable. This commit causes the generator to look at the CheckOverflow setting in the compilation options, and if it's set, to emit `unchecked { ... }` around all the relevant code.
Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions Issue DetailsThe regex source generator uses code patterns that might have arithmetic overflows, e.g. a bounds check with This commit causes the generator to look at the CheckOverflow setting in the compilation options, and if it's set, to emit We'll want to backport this to release/7.0.
|
src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i dont' see any issue on the IG side.
Great, thanks for looking |
{ | ||
void EnterCheckOverflow() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: no need to reset CI for this, but I think it is a bit more readable in general when we have local funcs at the end of the method (even better if they are after a return statement)
I'm not very familiar with |
yup |
/backport to release/7.0 |
Started backporting to release/7.0: https://github.com/dotnet/runtime/actions/runs/3448484399 |
The regex source generator uses code patterns that might have arithmetic overflows, e.g. a bounds check with
(uint)index < span.Length
. These are intentional, and they're benign... unless the project/compilation has opted-in to overflow/underflow checking (CheckForOverflowUnderflow). In that case, the code for many patterns can start throwing false positive overflow exceptions, making the source generator unusable.This commit causes the generator to look at the CheckOverflow setting in the compilation options, and if it's set, to emit
unchecked { ... }
around all the relevant code.We'll want to backport this to release/7.0.
#78214