Bug 21363 – [REG2.094] Implementation of core.bitop.ror(x,0) is using UB

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-11-04T00:33:01Z
Last change time
2021-05-12T16:37:33Z
Keywords
industry, pull
Assigned to
No Owner
Creator
johanengelen

Comments

Comment #0 by johanengelen — 2020-11-04T00:33:01Z
This is a long-standing bug (in practice it doesn't result in UB), and now comes out due to better CTFE checking of UB. Testcase: ``` import core.bitop; enum a = ror(uint(1), 0); // rotate by 0, should be allowed. ``` The test case no longer compiles with 2.094.0: core/bitop.d(961): Error: shift by 32 is outside the range 0..31 rortest.d(1): called from here: ror(1u, 0u) The problem is that the implementation of `ror` is indeed shifting by a too large amount. Note that `rol` has the same problem.
Comment #1 by dlang-bot — 2021-05-01T23:20:43Z
@Chigusa0w0 created dlang/druntime pull request #3457 "Fix Issue 21363 - [REG2.094] Implementation of core.bitop.ror(x,0) is…" fixing this issue: - Fix Issue 21363 - [REG2.094] Implementation of core.bitop.ror(x,0) is using UB This is a quick fix to Issue 21363. When `count` is set to `0`, `T.sizeof * 8 - count` will always be `T.sizeof * 8` therefore fails compiler check here: https://github.com/dlang/dmd/blob/81f9f57257da8733cf741355524bb8a3ec9c45ce/src/dmd/dinterpret.d#L3018-L3024 https://github.com/dlang/druntime/pull/3457
Comment #2 by dlang-bot — 2021-05-02T04:10:44Z
dlang/druntime pull request #3457 "Fix Issue 21363 - [REG2.094] Implementation of core.bitop.ror(x,0) is…" was merged into stable: - e6619623a8205a33251ebc5f64e34aedc1b2189c by Chigusa0w0: Fix Issue 21363 - [REG2.094] Implementation of core.bitop.ror(x,0) is using UB This is a quick fix to Issue 21363. When `count` is set to `0`, `T.sizeof * 8 - count` will always be `T.sizeof * 8` therefore fails compiler check here: https://github.com/dlang/dmd/blob/81f9f57257da8733cf741355524bb8a3ec9c45ce/src/dmd/dinterpret.d#L3018-L3024 https://github.com/dlang/druntime/pull/3457
Comment #3 by dlang-bot — 2021-05-12T16:37:33Z
dlang/druntime pull request #3468 "merge stable" was merged into master: - fdda230e2a41ba4723a424f31cf29b99e705b4ec by Chigusa0w0: Fix Issue 21363 - [REG2.094] Implementation of core.bitop.ror(x,0) is using UB This is a quick fix to Issue 21363. When `count` is set to `0`, `T.sizeof * 8 - count` will always be `T.sizeof * 8` therefore fails compiler check here: https://github.com/dlang/dmd/blob/81f9f57257da8733cf741355524bb8a3ec9c45ce/src/dmd/dinterpret.d#L3018-L3024 https://github.com/dlang/druntime/pull/3468