D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21578 - core.atomic.atomicFetchSub for pointers incorrectly calls wrong function from core.internal.atomic
Summary: core.atomic.atomicFetchSub for pointers incorrectly calls wrong function from...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D2
Hardware: All All
: P1 major
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2021-01-24 23:16 UTC by ZombineDev
Modified: 2021-02-13 03:32 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description ZombineDev 2021-01-24 23:16:37 UTC
Likely due to a copy-paste bug `core.atomic.atomicFetchSub` wrongly calls `core.internal.atomic.atomicFetchAdd` instead of `core.internal.atomic.atomicFetchSub`.
Comment 1 ZombineDev 2021-01-24 23:22:21 UTC
Test case:

import core.atomic;
shared(ulong)[] array = [2, 4, 6, 8, 10, 12, 14, 16, 19, 20];
{
    shared ulong* ptr = &array[0];
    shared(ulong)* prevPtr = atomicFetchAdd(ptr, 3); 
    assert(prevPtr == &array[0]); // OK
    assert(*prevPtr == 2); // OK
    assert(*ptr == 8); // OK
}
{
    shared ulong* ptr = &array[5];
    shared(ulong)* prevPtr = atomicFetchSub(ptr, 4); 
    assert(prevPtr == &array[5]); // OK
    assert(*prevPtr == 12); // OK
    assert(*ptr == 4); //fails
}
Comment 2 Dlang Bot 2021-01-25 09:18:27 UTC
@rymrg created dlang/druntime pull request #3343 "Fix issue 21578 - core.atomic.atomicFetchSub for pointers incorrectly…" fixing this issue:

- Fix issue 21578 - core.atomic.atomicFetchSub for pointers incorrectly calls wrong function from core.internal.atomic

https://github.com/dlang/druntime/pull/3343
Comment 3 Dlang Bot 2021-01-27 02:34:39 UTC
dlang/druntime pull request #3343 "Fix issue 21578 - core.atomic.atomicFetchSub for pointers incorrectly…" was merged into stable:

- fbf5f525756e51879578c2663643449a5c9c4040 by rymrg:
  Fix issue 21578 - core.atomic.atomicFetchSub for pointers incorrectly calls wrong function from core.internal.atomic

https://github.com/dlang/druntime/pull/3343
Comment 4 Dlang Bot 2021-02-13 03:32:44 UTC
dlang/druntime pull request #3374 "merge stable" was merged into master:

- 2d1f8efbe72c2a9712e055e617285a0f5661f9f3 by rymrg:
  Fix issue 21578 - core.atomic.atomicFetchSub for pointers incorrectly calls wrong function from core.internal.atomic

https://github.com/dlang/druntime/pull/3374