Skip to content

[stdlib] add overflow checks for some pointer arithmetic #60613

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

Merged
merged 2 commits into from
Aug 25, 2022

Conversation

glessard
Copy link
Contributor

@glessard glessard commented Aug 17, 2022

  • Pointer arithmetic uses operations that can overflow.
  • This adds overflow checks added for recent additions to pointer arithmetic (rounding and property pointers).
  • The basic advanced(by:) functions will be dealt with separately.

@glessard
Copy link
Contributor Author

@swift-ci please benchmark

@glessard
Copy link
Contributor Author

As expected, these changes have no real effect on current benchmarks:

Performance (x86_64): -O

Regression OLD NEW DELTA RATIO
FlattenListLoop 1001 1623 +62.1% 0.62x (?)

Code size: -O

Performance (x86_64): -Osize

Regression OLD NEW DELTA RATIO
FlattenListFlatMap 3020 4350 +44.0% 0.69x (?)
 
Improvement OLD NEW DELTA RATIO
SequenceAlgosRange 2390 2170 -9.2% 1.10x (?)
SequenceAlgosArray 2400 2180 -9.2% 1.10x (?)
DictionaryKeysContainsCocoa 15 14 -6.7% 1.07x (?)

Code size: -Osize

Performance (x86_64): -Onone

Code size: -swiftlibs

How to read the data The tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.

If you see any unexpected regressions, you should consider fixing the
regressions before you merge the PR.

Noise: Sometimes the performance results (not code size!) contain false
alarms. Unexpected regressions which are marked with '(?)' are probably noise.
If you see regressions which you cannot explain you can try to run the
benchmarks again. If regressions still show up, please consult with the
performance team (@eeckstein).

Hardware Overview
  Model Name: Mac mini
  Model Identifier: Macmini8,1
  Processor Name: 6-Core Intel Core i7
  Processor Speed: 3.2 GHz
  Number of Processors: 1
  Total Number of Cores: 6
  L2 Cache (per Core): 256 KB
  L3 Cache: 12 MB
  Memory: 32 GB

@glessard glessard requested a review from stephentyrone August 18, 2022 00:42
- Overflow checks added for recent additions to pointer arithmetic (rounding and property pointers).
- The basic `advanced(by:)` functions will need to be dealt with separately.
@glessard glessard force-pushed the pointer-arithmetic-overflow-checks branch from 0dae2cb to 3fcf2a2 Compare August 23, 2022 20:30
@glessard
Copy link
Contributor Author

@swift-ci please test

1 similar comment
@glessard
Copy link
Contributor Author

@swift-ci please test

@glessard glessard marked this pull request as ready for review August 25, 2022 10:35
@Catfish-Man Catfish-Man self-requested a review August 25, 2022 20:34
Copy link
Contributor

@Catfish-Man Catfish-Man left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, I appreciate the thorough tests

@glessard glessard merged commit 1bba62e into swiftlang:main Aug 25, 2022
@glessard glessard deleted the pointer-arithmetic-overflow-checks branch August 25, 2022 20:37
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