Bug 16651 – atomicOp!"-="(ulong, uint) = wrong result/codegen

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-10-30T23:35:00Z
Last change time
2017-01-16T23:24:04Z
Keywords
pull
Assigned to
ag0aep6g
Creator
2krnk

Comments

Comment #0 by 2krnk — 2016-10-30T23:35:16Z
wrong result/codegen for atomicOp!"-="(ulong, uint) using DMD -m64. tested on win64 only, using DMD-2.071.2. problem does not occur with DMD -m32 or ldc2-1.1.0-b3 -m64. ----- version(DigitalMars)version(D_LP64){ import std.stdio : writeln; import core.atomic : atomicOp; shared ulong foo = 2; uint bar = 1; atomicOp!"-="( foo, bar ); writeln( "foo = ", foo ); // foo = 4294967297 }
Comment #1 by ag0aep6g — 2016-11-01T13:24:22Z
Same happens with -m32 and smaller types: ---- void main() { import std.stdio : writeln; import core.atomic : atomicOp; shared uint foo = 2; ubyte bar = 1; atomicOp!"-="( foo, bar ); writeln( "foo = ", foo ); // foo = 257 } ---- Also happens on Linux. Looks like a bug in druntime code (core.atomic) rather than dmd. I think it works with LDC because they've added a path of their own to druntime [1]. [1] https://github.com/ldc-developers/druntime/blob/049b8efdf0daebcc1cfe690c5cf7585125c1ff72/src/core/atomic.d#L177
Comment #2 by safety0ff.bugz — 2016-11-01T21:05:37Z
(In reply to ag0aep6g from comment #1) > > Looks like a bug in druntime code (core.atomic) rather than dmd. Yup, atomicFetchSub [1] doesn't widen the modifier before negating it. This is necessary when the modifier is unsigned and narrower than the value's type. [1] https://github.com/dlang/druntime/blob/master/src/core/atomic.d#L684
Comment #3 by ag0aep6g — 2016-11-06T13:13:15Z
Comment #4 by github-bugzilla — 2016-11-11T10:21:31Z
Commits pushed to stable at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/44f45280b7fe308731611801385f8c6226214682 fix issue 16651 - atomicOp!"-="(ulong, uint) = wrong result/codegen https://github.com/dlang/druntime/commit/422c8f7b0f0e6598910737981074e0c45a4eb1b9 Merge pull request #1690 from aG0aep6G/16651 fix issue 16651 - atomicOp!"-="(ulong, uint) = wrong result/codegen
Comment #5 by github-bugzilla — 2016-12-09T00:27:11Z
Commits pushed to master at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/44f45280b7fe308731611801385f8c6226214682 fix issue 16651 - atomicOp!"-="(ulong, uint) = wrong result/codegen https://github.com/dlang/druntime/commit/422c8f7b0f0e6598910737981074e0c45a4eb1b9 Merge pull request #1690 from aG0aep6G/16651
Comment #6 by github-bugzilla — 2016-12-27T13:10:53Z
Commits pushed to scope at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/44f45280b7fe308731611801385f8c6226214682 fix issue 16651 - atomicOp!"-="(ulong, uint) = wrong result/codegen https://github.com/dlang/druntime/commit/422c8f7b0f0e6598910737981074e0c45a4eb1b9 Merge pull request #1690 from aG0aep6G/16651
Comment #7 by github-bugzilla — 2017-01-16T23:24:04Z
Commits pushed to newCTFE at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/44f45280b7fe308731611801385f8c6226214682 fix issue 16651 - atomicOp!"-="(ulong, uint) = wrong result/codegen https://github.com/dlang/druntime/commit/422c8f7b0f0e6598910737981074e0c45a4eb1b9 Merge pull request #1690 from aG0aep6G/16651