Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi    [ Add a report in this area ]  
Report #:  133709   Status: Resolved
AtomicIncrement func corrupt "Increment" param
Project:  Delphi Build #:  Embarcadero┬« De
Version:    18.1 Submitted By:   Dmitrij K
Report Type:  Crash / Data loss / Total failure Date Reported:  9/21/2015 1:48:48 AM
Severity:    Critical / Show Stopper Last Updated: 11/30/2015 11:18:37 AM
Platform:    All platforms Internal Tracking #:   70332
Resolution: Fixed (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: (1 Total Rating)
5.00 out of 5
Total Votes: 10
Description
RELEASE config
AtomicIncrement() corrupt second param
const "B" changed

program Project2;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils;

var a : integer;

procedure test(const B: Integer);
begin
  AtomicIncrement(a, b);
  Writeln(a, ' ', b); //!!!!! 11 11
end;

begin
  try
    a := 1;
    test(10);
    readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
Steps to Reproduce:
None
Workarounds
None
Attachment
None
Comments

Ilya S at 10/26/2015 5:42:01 AM -
The output 11 11 reproduced if optimization is on. Release config allows 11 11 output, DEBUG show 11 10.
Generated ASM is different:

Release:
Project3.dpr.12: AtomicIncrement(a, b);
0041874F 8BC3             mov eax,ebx
00418751 F00FC11DC82E4200 lock xadd [$00422ec8],ebx
00418759 03D8             add ebx,eax
Project3.dpr.13: Writeln(a, ' ', b); //!!!!! 11 11
0041875B A18CD54100       mov eax,[$0041d58c]
00418760 8B15C82E4200     mov edx,[$00422ec8]
00418766 E81DCBFEFF       call @Write0Long
0041876B 66BA2000         mov dx,$0020
0041876F E8F4CDFEFF       call @Write0WChar
00418774 8BD3             mov edx,ebx
00418776 E80DCBFEFF       call @Write0Long
0041877B E8F4CEFEFF       call @WriteLn

Debug:
Project3.dpr.12: AtomicIncrement(a, b);
00418753 8B45FC           mov eax,[ebp-$04]
00418756 F00FC105C82E4200 lock xadd [$00422ec8],eax
0041875E 0345FC           add eax,[ebp-$04]
Project3.dpr.13: Writeln(a, ' ', b); //!!!!! 11 10
00418761 A18CD54100       mov eax,[$0041d58c]
00418766 8B15C82E4200     mov edx,[$00422ec8]
0041876C E817CBFEFF       call @Write0Long
00418771 66BA2000         mov dx,$0020
00418775 E8EECDFEFF       call @Write0WChar
0041877A 8B55FC           mov edx,[ebp-$04]
0041877D E806CBFEFF       call @Write0Long
00418782 E8EDCEFEFF       call @WriteLn

Server Response from: ETNACODE01