Uh oh!
There was an error while loading. Please reload this page.
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.ghost
commented
Nov 11, 2022
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.
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
CyrusNajmabadi
left a comment
There was a problem hiding this comment.
i dont' see any issue on the IG side.
stephentoub
commented
Nov 11, 2022
Great, thanks for looking |
| private static void EmitRegexDerivedTypeRunnerFactory(IndentedTextWriter writer, RegexMethod rm, Dictionary<string, string[]> requiredHelpers) | ||
| private static void EmitRegexDerivedTypeRunnerFactory(IndentedTextWriter writer, RegexMethod rm, Dictionary<string, string[]> requiredHelpers, bool checkOverflow) | ||
| { | ||
| void EnterCheckOverflow() |
There was a problem hiding this comment.
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)
joperezr
commented
Nov 11, 2022
I'm not very familiar with |
stephentoub
commented
Nov 11, 2022
yup |
stephentoub
commented
Nov 11, 2022
/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