Fix gtCloneExpr when cloning during R2R compilation a GT_ALLOCOBJ node (#59395)
authorDavid Wrighton <davidwr@microsoft.com>
Tue, 21 Sep 2021 17:55:38 +0000 (10:55 -0700)
committerGitHub <noreply@github.com>
Tue, 21 Sep 2021 17:55:38 +0000 (10:55 -0700)
* Fix gtCloneExpr when cloning during R2R compilation a GT_ALLOCOBJ node
- Without this fix cloned expressions with allocations will fail
- This is most common in profile guided code around devirtualization, but I believe it can occur in other where gtCloneExpr is used
- Symptom of the failure is a compilation failure during crossgen2

src/coreclr/jit/gentree.cpp
src/coreclr/jit/objectalloc.cpp

index d67fd0f..48a1e04 100644 (file)
@@ -7461,6 +7461,7 @@ GenTreeAllocObj* Compiler::gtNewAllocObjNode(CORINFO_RESOLVED_TOKEN* pResolvedTo
 #ifdef FEATURE_READYTORUN
     if (usingReadyToRunHelper)
     {
+        assert(lookup.addr != nullptr);
         allocObj->gtEntryPoint = lookup;
     }
 #endif
@@ -7865,6 +7866,9 @@ GenTree* Compiler::gtCloneExpr(
                 copy                        = new (this, GT_ALLOCOBJ)
                     GenTreeAllocObj(tree->TypeGet(), asAllocObj->gtNewHelper, asAllocObj->gtHelperHasSideEffects,
                                     asAllocObj->gtAllocObjClsHnd, asAllocObj->gtOp1);
+#ifdef FEATURE_READYTORUN
+                copy->AsAllocObj()->gtEntryPoint = asAllocObj->gtEntryPoint;
+#endif
             }
             break;
 
index 422eaae..fc238be 100644 (file)
@@ -481,6 +481,11 @@ GenTree* ObjectAllocator::MorphAllocObjNodeIntoHelperCall(GenTreeAllocObj* alloc
         assert(comp->opts.IsReadyToRun());
         helperCall->AsCall()->setEntryPoint(entryPoint);
     }
+    else
+    {
+        assert(helper != CORINFO_HELP_READYTORUN_NEW); // If this is true, then we should have collected a non-null
+                                                       // entrypoint above
+    }
 #endif
 
     return helperCall;