From 4f53c2f7e62df44f07cf410df8a0d439f42a0a71 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Fri, 25 Nov 2022 23:27:26 +0100 Subject: [PATCH] Fix asserts in Vector<> (#78765) --- src/coreclr/jit/hwintrinsic.cpp | 5 ++++- src/coreclr/jit/simdashwintrinsic.cpp | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/hwintrinsic.cpp b/src/coreclr/jit/hwintrinsic.cpp index 9ae717f9b0163..cb7c69d82793f 100644 --- a/src/coreclr/jit/hwintrinsic.cpp +++ b/src/coreclr/jit/hwintrinsic.cpp @@ -561,7 +561,10 @@ GenTree* Compiler::getArgForHWIntrinsic(var_types argType, arg = impPopStack().val; assert(varTypeIsArithmetic(arg->TypeGet()) || ((argType == TYP_BYREF) && arg->TypeIs(TYP_BYREF))); - assert(genActualType(arg->gtType) == genActualType(argType)); + if (!impCheckImplicitArgumentCoercion(argType, arg->gtType)) + { + BADCODE("the hwintrinsic argument has a type that can't be implicitly converted to the signature type"); + } } return arg; diff --git a/src/coreclr/jit/simdashwintrinsic.cpp b/src/coreclr/jit/simdashwintrinsic.cpp index 1682981eda47f..32be7a17c81a3 100644 --- a/src/coreclr/jit/simdashwintrinsic.cpp +++ b/src/coreclr/jit/simdashwintrinsic.cpp @@ -213,7 +213,13 @@ GenTree* Compiler::impSimdAsHWIntrinsic(NamedIntrinsic intrinsic, if (retType == TYP_STRUCT) { simdBaseJitType = getBaseJitTypeAndSizeOfSIMDType(sig->retTypeSigClass, &simdSize); - retType = getSIMDTypeForSize(simdSize); + if ((simdBaseJitType == CORINFO_TYPE_UNDEF) || !varTypeIsArithmetic(JitType2PreciseVarType(simdBaseJitType)) || + (simdSize == 0)) + { + // Unsupported type + return nullptr; + } + retType = getSIMDTypeForSize(simdSize); } else if (numArgs != 0) {