Branch: refs/heads/master
Revision: 92038bb
Author: bradcray
Log Message:
Merge pull request #17816 from bradcray/fix-size-overflow-checks
Fix size overflow checks
[reviewed by @ronawho]
While preparing a demo of #17628 today, I realized that .sizeAs()
had a bug in computing whether or not the size would overflow the specified type. Specifically, it computed ah - al
(the difference between the aligned high and low bounds) using the native idxType
which meant that for cases > max(int(width))
but less than max(uint(width))
we'd get a negative number which would then promote to a terrible uint(64)
value when upcast.
This PR fixes that issue by calculating the width as a uint(width)
difference before promoting. It relies on the fact that subtraction operators will generate the same value whether working on signed or unsigned values.
Modified Files:
A test/types/integral/smallIntSizeQueriesOverflow.chpl
A test/types/integral/smallIntSizeQueriesOverflow.compopts
A test/types/integral/smallIntSizeQueriesOverflow.good
M modules/internal/ChapelRange.chpl
Compare: https://github.com/chapel-lang/chapel/compare/771bb876db67...92038bb1654a