Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silent bad codegen when returning a modified struct #8185

Closed
briansull opened this issue May 23, 2017 · 4 comments
Closed

Silent bad codegen when returning a modified struct #8185

briansull opened this issue May 23, 2017 · 4 comments
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI bug

Comments

@briansull
Copy link
Contributor

Repro:

Compile MutateStructArg.cs below:

.\Tools\dotnetcli\dotnet.exe Tools\csc.exe /o+ /out:Program.exe MutateStructArg.cs /r:.\bin\tests\Windows_NT.x64.Checked\Tests\Core_Root\System.Private.CoreLib.dll /r:.\bin\tests\Windows_NT.x64.Checked\Tests\Core_Root\System.Console.dll
/r:.\bin\tests\Windows_NT.x64.Checked\Tests\Core_Root\System.Runtime.dll

MutateStructArg.cs

using System;
class MutateStructArg
{
   public struct P
   {
      public string S;
      public int    X;
   }

   public static int Main()
   {
      P l1 = new P();
      l1.S = "Hello World";
      l1.X = 42;
      P l2 = foo(l1);
      Console.WriteLine(l2.S); // Print modified value "Goodbye World"
      if ((l2.S == "Goodbye World") && (l2.X == 100))
      {
         return 100;   // success
      }
      else
      {
         Console.WriteLine("**** Test FAILED ***");
         return 1;  // failure
      }
   }

   public static P foo(P a)
   {
      Console.WriteLine(a.S);   // Print the incoming value "Hello World"
      a.S = "Goodbye World";    // Mutate the incoming value
      a.X = 100;
      return a;                 // Copy the modified value to the return value 
   }
}

Run the Repro:
.\bin\tests\Windows_NT.x64.Checked\Tests\Core_Root\CoreRun.exe MutateStructArg.exe
Hello World
Hello World
**** Test FAILED ***

@briansull
Copy link
Contributor Author

This is a recent regression

@briansull
Copy link
Contributor Author

@JosephTremoulet Can you take a look at this one

@briansull
Copy link
Contributor Author

Note that this test failure corresponds to desktop test failure:

runbaseline_simple2_jit64-gc-misc-simple2.txt
jit\jit64\gc\misc\simple2.exe

@briansull
Copy link
Contributor Author

@dotnet/jit-contrib FYI

JosephTremoulet referenced this issue in JosephTremoulet/coreclr May 24, 2017
Update fgMorphImplicitByRefArgs to rewrite references to struct-promoted
implicit-by-reference parameters as references to the new struct temps
created in fgRetypeImplicitByRefArgs; fgMorphStructField isn't updating
these because it's only interested in field references, and runs upstream
of fgRetypeImplicitByRefArgs where the full struct temp is created,
anyway.
Invert the sense of lvPromoted for implicit byref args in the interim
between fgRetypeImplicitByRefArgs and fgMarkDemotedImplicitByRefArgs,
since now fgMarkDemotedImplicitByRefArgs needs to update both and would
look horribly backwards the other way around.

Fixes #11814.
@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI bug
Projects
None yet
Development

No branches or pull requests

1 participant