From 46f3c107cc00d8406a7c147b1f21a95ab0717c2c Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 7 Oct 2024 15:05:53 -0700 Subject: [PATCH] Don't call HasCustomModifier when the argument type is something normalized to ELEMENT_TYPE_PTR or ELEMENT_TYPE_BYREF (#108610) --- src/coreclr/vm/jitinterface.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 28d95e523f6cd..f13286a675ab7 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -9539,7 +9539,17 @@ CorInfoTypeWithMod CEEInfo::getArgType ( FALLTHROUGH; case ELEMENT_TYPE_BYREF: - IfFailThrow(ptr.GetElemType(NULL)); + // PeekElemTypeClosed above normalized ELEMENT_TYPE_INTERNAL back to the underlying type handle's signature representation. + // This normalization can also occur for generic instantiatations, but we don't support pointer or byref types + // as generic arguments. + // All of the element types that can be normalized above can't have custom modifiers embedded in this location, + // so we don't need to check for them here. + CorElementType nonNormalizedType; + IfFailThrow(ptr.GetElemType(&nonNormalizedType)); + if (type != nonNormalizedType) + { + break; + } if (ptr.HasCustomModifier(pModule, "Microsoft.VisualC.NeedsCopyConstructorModifier", ELEMENT_TYPE_CMOD_REQD) || ptr.HasCustomModifier(pModule, "System.Runtime.CompilerServices.IsCopyConstructed", ELEMENT_TYPE_CMOD_REQD)) {