defMAC construction up a scope to make it live long enough. (#54702)
authorJeremy Koritzinsky <jekoritz@microsoft.com>
Thu, 24 Jun 2021 23:40:40 +0000 (16:40 -0700)
committerGitHub <noreply@github.com>
Thu, 24 Jun 2021 23:40:40 +0000 (23:40 +0000)
Fixes #54649

src/coreclr/jit/morph.cpp

index 6d7f8c7..e53c2d9 100644 (file)
@@ -6046,6 +6046,10 @@ GenTree* Compiler::fgMorphField(GenTree* tree, MorphAddrContext* mac)
     }
 #endif
 
+    // Create a default MorphAddrContext early so it doesn't go out of scope
+    // before it is used.
+    MorphAddrContext defMAC(MACK_Ind);
+
     /* Is this an instance data member? */
 
     if (objRef)
@@ -6136,7 +6140,6 @@ GenTree* Compiler::fgMorphField(GenTree* tree, MorphAddrContext* mac)
 
         // NULL mac means we encounter the GT_FIELD first.  This denotes a dereference of the field,
         // and thus is equivalent to a MACK_Ind with zero offset.
-        MorphAddrContext defMAC(MACK_Ind);
         if (mac == nullptr)
         {
             mac = &defMAC;