title: FillChar and StringOfChar under Delphi 10.2 for Win64 Release Target
body: <p>I have a question about a specific programming problem in Delphi 10.2 Pascal programming language.</p>
  
  <p>The StringOfChar and FillChar don’t work properly under Win64 Release build on CPUs released before year 2012.</p>
  
  <ul>
  <li><p>Expected result of FillChar is just plain sequence of just repeating 8-bit characters in a given memory buffer.</p></li>
  <li><p>Expected result of StringOfChar is the same, but the result is stored inside a string type.</p></li>
  </ul>
  
  <p>But, in fact, when I compile our applications that worked in Delphi prior to 10.2 by the 10.2 version of Delphi, our applications compiled for Win64 stop working properly on CPUs released before year 2012.</p>
  
  <p>The StringOfChar and FillChar don’t work properly – they return a string of different characters, although in a repeating pattern – not just a sequence of the same character as they should.</p>
  
  <p>Here is the minimal code enough to demonstrate the issue. Please note that the length of the sequence should be at least 16 characters, and the character should not be nul (#0). The code is below:</p>
  
  <pre><code>procedure TestStringOfChar;
  var
    a: AnsiString;
    ac: AnsiChar;
  begin
    ac := #1;
    a := StringOfChar(ac, 43);
    if a &lt;&gt; #1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1#1 then
    begin
      raise Exception.Create('ANSI StringOfChar Failed!!');
    end;
  end;
  </code></pre>
  
  <p>I know that there are lots of Delphi programmers at StackOverflow. Are you experiencing the same problem? If yes, how you resolve it? What is the solution? By the way, <a href="https://quality.embarcadero.com/browse/RSP-18071" rel="nofollow noreferrer">I have contacted the developers of Delphi but they didn’t confirm nor deny the issue so far</a>. I'm using Embarcadero Delphi 10.2 Version 25.0.26309.314.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>If your CPU is manufactured in 2012 or later, additionally include the following lines before calling StringOfChar to reproduce the issue:</p>
  
  <pre><code>const
    ERMSBBit    = 1 shl 9; //$0200
  begin
    CPUIDTable[7].EBX := CPUIDTable[7].EBX and not ERMSBBit;
  </code></pre>
  
  <p>As about the <a href="https://community.embarcadero.com/blogs/entry/april-2017-rad-studio-10-2-hotfix-for-toolchain-issues" rel="nofollow noreferrer">April 2017 RAD Studio 10.2 Hotfix for Toolchain Issues</a> - have tried with it and without it - it didn't help. The issue exists regardless of the Hotfix.</p>
  
  <p><strong>Update #2</strong></p>
  
  <p>Embarcadero has confirmed and resolved this issue on 08/Aug/17 6:03 PM. So, in Delphi 10.2 Tokyo Release 1 (released on August 8, 2017) this bug is fixed.</p>