From 36aa98bfc5fa80fda2cefbbe2140cdef2e9ac000 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Wed, 14 Sep 2022 12:36:39 +0200 Subject: [PATCH] fix debug assert around string literals (#75576) --- src/coreclr/jit/ee_il_dll.cpp | 14 +++++++++++++- src/coreclr/jit/morph.cpp | 5 +++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/coreclr/jit/ee_il_dll.cpp b/src/coreclr/jit/ee_il_dll.cpp index ccbf6d69b4b8b3..fedbae80a624c4 100644 --- a/src/coreclr/jit/ee_il_dll.cpp +++ b/src/coreclr/jit/ee_il_dll.cpp @@ -1628,7 +1628,19 @@ const WCHAR* Compiler::eeGetCPString(size_t strHandle) return (nullptr); } - CORINFO_String* asString = *((CORINFO_String**)strHandle); + CORINFO_String* asString = nullptr; + if (impGetStringClass() == *((CORINFO_CLASS_HANDLE*)strHandle)) + { + // strHandle is a frozen string + // We assume strHandle is never an "interior" pointer in a frozen string + // (jit is not expected to perform such foldings) + asString = (CORINFO_String*)strHandle; + } + else + { + // strHandle is a pinned handle to a string object + asString = *((CORINFO_String**)strHandle); + } if (ReadProcessMemory(GetCurrentProcess(), asString, buff, sizeof(buff), nullptr) == 0) { diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 3b72edc3f912e9..5920fee68cf1d5 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -11161,6 +11161,11 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac, bool* optA // if (!tree->AsIndir()->IsVolatile()) { + if (op1->IsIconHandle(GTF_ICON_STR_HDL)) + { + tree->gtFlags |= (GTF_IND_INVARIANT | GTF_IND_NONFAULTING | GTF_IND_NONNULL); + } + /* Try to Fold *(&X) into X */ if (op1->gtOper == GT_ADDR) {