Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
fix issue 16651 - atomicOp!"-="(ulong, uint) = wrong result/codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
aG0aep6G committed Nov 6, 2016
1 parent 1394e0a commit 44f4528
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/core/atomic.d
Expand Up @@ -166,10 +166,10 @@ version( CoreDdoc )
else version( AsmX86_32 )
{
// Uses specialized asm for fast fetch and add operations
private HeadUnshared!(T) atomicFetchAdd(T, V1)( ref shared T val, V1 mod ) pure nothrow @nogc @safe
if( T.sizeof <= 4 && V1.sizeof <= 4)
private HeadUnshared!(T) atomicFetchAdd(T)( ref shared T val, size_t mod ) pure nothrow @nogc @safe
if( T.sizeof <= 4 )
{
size_t tmp = mod; // convert all operands to size_t
size_t tmp = mod;
asm pure nothrow @nogc @trusted
{
mov EAX, tmp;
Expand All @@ -187,8 +187,8 @@ else version( AsmX86_32 )
return cast(T)tmp;
}

private HeadUnshared!(T) atomicFetchSub(T, V1)( ref shared T val, V1 mod ) pure nothrow @nogc @safe
if( T.sizeof <= 4 && V1.sizeof <= 4)
private HeadUnshared!(T) atomicFetchSub(T)( ref shared T val, size_t mod ) pure nothrow @nogc @safe
if( T.sizeof <= 4)
{
return atomicFetchAdd(val, -mod);
}
Expand Down Expand Up @@ -654,15 +654,15 @@ else version( AsmX86_32 )
else version( AsmX86_64 )
{
// Uses specialized asm for fast fetch and add operations
private HeadUnshared!(T) atomicFetchAdd(T, V1)( ref shared T val, V1 mod ) pure nothrow @nogc @trusted
if( __traits(isIntegral, T) && __traits(isIntegral, V1) )
private HeadUnshared!(T) atomicFetchAdd(T)( ref shared T val, size_t mod ) pure nothrow @nogc @trusted
if( __traits(isIntegral, T) )
in
{
assert( atomicValueIsProperlyAligned(val));
}
body
{
size_t tmp = mod; // convert all operands to size_t
size_t tmp = mod;
asm pure nothrow @nogc @trusted
{
mov RAX, tmp;
Expand All @@ -681,8 +681,8 @@ else version( AsmX86_64 )
return cast(T)tmp;
}

private HeadUnshared!(T) atomicFetchSub(T, V1)( ref shared T val, V1 mod ) pure nothrow @nogc @safe
if( __traits(isIntegral, T) && __traits(isIntegral, V1) )
private HeadUnshared!(T) atomicFetchSub(T)( ref shared T val, size_t mod ) pure nothrow @nogc @safe
if( __traits(isIntegral, T) )
{
return atomicFetchAdd(val, -mod);
}
Expand Down Expand Up @@ -1532,4 +1532,17 @@ version( unittest )
assert(atomicOp!"-="(i64, 1) == 7);
}
}

pure nothrow @nogc @safe unittest // issue 16651
{
shared ulong a = 2;
uint b = 1;
atomicOp!"-="( a, b );
assert(a == 1);

shared uint c = 2;
ubyte d = 1;
atomicOp!"-="( c, d );
assert(c == 1);
}
}

0 comments on commit 44f4528

Please sign in to comment.