Skip to content

Commit

Permalink
Merge pull request #523 from tannergooding/main
Browse files Browse the repository at this point in the history
Fix operand order for NativeMemory.Copy
  • Loading branch information
tannergooding committed Jan 19, 2024
2 parents 0c89b5a + 27ce5c6 commit 663dab5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Expand Up @@ -17,7 +17,7 @@
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageVersion Include="NUnit" Version="3.14.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta3.22114.1" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>

</Project>
Expand Up @@ -191,18 +191,28 @@ private void VisitCallExpr(CallExpr callExpr)
{
case "memcpy":
{
var args = callExpr.Args;

if (Config.GenerateLatestCode)
{
outputBuilder.AddUsingDirective("System.Runtime.InteropServices");
outputBuilder.Write("NativeMemory.Copy");

if (args.Count == 3)
{
// Swap the operands around:
// * NativeMemory.Copy takes: source, dest, count
// * memcpy takes: dest, source, count
args = [args[1], args[0], args[2]];
}
}
else
{
outputBuilder.AddUsingDirective("System.Runtime.CompilerServices");
outputBuilder.Write("Unsafe.CopyBlockUnaligned");
}

VisitArgs(callExpr);
VisitArgs(callExpr, args);
break;
}

Expand Down

0 comments on commit 663dab5

Please sign in to comment.