From 95a61ab5e49134e87584ca302b90bd78a5a58864 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 5 Apr 2021 13:40:45 -0700 Subject: Fix a bug in the "operator cache" (#1784) In order to speed up compilation, the semantic checking step uses a cache for overload resolution in the case of an operator being applied to operations of basic scalar types and vectors/matrices thereof. The logic for construct keys for that cache was defensive against the case of, e.g., `vector` where the element count `N` of the vector was not a literal value but a generic parameter. For some reason it did not have equivalent safeguards for a case like `vector` where the element type was not a basic type, and it would instead assume all vector/matrix types had basic types as their element type. This change fixes the logic to make it properly defensive against this case. Co-authored-by: jsmall-nvidia --- source/slang/slang-check-impl.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'source') diff --git a/source/slang/slang-check-impl.h b/source/slang/slang-check-impl.h index bc265b1b4..623f18b22 100644 --- a/source/slang/slang-check-impl.h +++ b/source/slang/slang-check-impl.h @@ -44,8 +44,10 @@ namespace Slang { if (auto elemCount = as(vectorType->elementCount)) { - auto elemBasicType = as(vectorType->elementType); - return makeBasicTypeKey(elemBasicType->baseType, elemCount->value); + if( auto elemBasicType = as(vectorType->elementType) ) + { + return makeBasicTypeKey(elemBasicType->baseType, elemCount->value); + } } } else if (auto matrixType = as(typeIn)) @@ -54,8 +56,10 @@ namespace Slang { if (auto elemCount2 = as(matrixType->getColumnCount())) { - auto elemBasicType = as(matrixType->getElementType()); - return makeBasicTypeKey(elemBasicType->baseType, elemCount1->value, elemCount2->value); + if( auto elemBasicType = as(matrixType->getElementType()) ) + { + return makeBasicTypeKey(elemBasicType->baseType, elemCount1->value, elemCount2->value); + } } } } -- cgit v1.2.3