summaryrefslogtreecommitdiff
path: root/source/slang/slang-check-expr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-check-expr.cpp')
-rw-r--r--source/slang/slang-check-expr.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp
index 48f32952b..d151d37be 100644
--- a/source/slang/slang-check-expr.cpp
+++ b/source/slang/slang-check-expr.cpp
@@ -1972,9 +1972,14 @@ IntVal* SemanticsVisitor::tryConstantFoldDeclRef(
// The values of specialization constants aren't known at compile time even
// if they're marked `const`.
- if (decl->hasModifier<SpecializationConstantAttribute>() ||
- decl->hasModifier<VkConstantIdAttribute>())
- return nullptr;
+ if ((decl->hasModifier<SpecializationConstantAttribute>() ||
+ decl->hasModifier<VkConstantIdAttribute>()) &&
+ kind == ConstantFoldingKind::SpecializationConstant)
+ {
+ return m_astBuilder->getOrCreate<DeclRefIntVal>(
+ declRef.substitute(m_astBuilder, declRef.getDecl()->getType()),
+ declRef);
+ }
if (decl->hasModifier<ExternModifier>())
{
@@ -1982,7 +1987,7 @@ IntVal* SemanticsVisitor::tryConstantFoldDeclRef(
if (kind == ConstantFoldingKind::CompileTime)
return nullptr;
// But if we are OK with link-time constants, we can still fold it into a val.
- auto rs = m_astBuilder->getOrCreate<GenericParamIntVal>(
+ auto rs = m_astBuilder->getOrCreate<DeclRefIntVal>(
declRef.substitute(m_astBuilder, declRef.getDecl()->getType()),
declRef);
return rs;
@@ -2067,7 +2072,7 @@ IntVal* SemanticsVisitor::tryConstantFoldExpr(
if (auto genericValParamRef = declRef.as<GenericValueParamDecl>())
{
- Val* valResult = m_astBuilder->getOrCreate<GenericParamIntVal>(
+ Val* valResult = m_astBuilder->getOrCreate<DeclRefIntVal>(
declRef.substitute(m_astBuilder, genericValParamRef.getDecl()->getType()),
genericValParamRef);
valResult = valResult->substitute(m_astBuilder, expr.getSubsts());
@@ -2383,7 +2388,7 @@ Expr* SemanticsExprVisitor::visitIndexExpr(IndexExpr* subscriptExpr)
subscriptExpr->indexExprs[0],
IntegerConstantExpressionCoercionType::AnyInteger,
nullptr,
- ConstantFoldingKind::LinkTime);
+ ConstantFoldingKind::SpecializationConstant);
// Validate that array size is greater than zero
if (auto constElementCount = as<ConstantIntVal>(elementCount))