Skip to content

Commit fe8de3b

Browse files
committed
Fix cachekey for intLitType.
1 parent a5ee747 commit fe8de3b

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

source/slang/slang-check-conversion.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1919,7 +1919,7 @@ bool SemanticsVisitor::canCoerce(
19191919

19201920
BasicTypeKeyPair cacheKey;
19211921
cacheKey.type1 = makeBasicTypeKey(toType);
1922-
cacheKey.type2 = makeBasicTypeKey(fromType, fromExpr);
1922+
cacheKey.type2 = makeBasicTypeKey(fromType);
19231923

19241924
if (cacheKey.isValid())
19251925
{

source/slang/slang-check-impl.h

+14-8
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,25 @@ SLANG_FORCE_INLINE BasicTypeKey makeBasicTypeKey(
102102
0};
103103
}
104104

105-
inline BasicTypeKey makeBasicTypeKey(QualType typeIn, Expr* exprIn = nullptr)
105+
inline BasicTypeKey makeBasicTypeKey(QualType typeIn)
106106
{
107107
if (auto basicType = as<BasicExpressionType>(typeIn))
108108
{
109109
auto rs = makeBasicTypeKey(basicType->getBaseType());
110-
if (auto constInt = as<IntegerLiteralExpr>(exprIn))
110+
rs.isLValue = typeIn.isLeftValue ? 1u : 0u;
111+
return rs;
112+
}
113+
else if (auto litType = as<IntLiteralType>(typeIn))
114+
{
115+
auto constInt = litType->getValue();
116+
auto baseType = as<BasicExpressionType>(constInt->getType())->getBaseType();
117+
auto rs = makeBasicTypeKey(baseType);
118+
if (constInt->getValue() < 0 &&
119+
baseType != BaseType::UInt64)
111120
{
112-
if (constInt->value < 0)
113-
{
114-
rs.knownNegative = 1;
115-
}
116-
rs.knownConstantBitCount = getIntValueBitSize(constInt->value);
121+
rs.knownNegative = 1;
117122
}
123+
rs.knownConstantBitCount = getIntValueBitSize(constInt->getValue());
118124
rs.isLValue = typeIn.isLeftValue ? 1u : 0u;
119125
return rs;
120126
}
@@ -195,7 +201,7 @@ struct OperatorOverloadCacheKey
195201

196202
for (Index i = 0; i < opExpr->arguments.getCount(); i++)
197203
{
198-
auto key = makeBasicTypeKey(opExpr->arguments[i]->type, opExpr->arguments[i]);
204+
auto key = makeBasicTypeKey(opExpr->arguments[i]->type);
199205
if (key.getRaw() == BasicTypeKey::invalid().getRaw())
200206
{
201207
return false;

0 commit comments

Comments
 (0)