diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-check-expr.cpp | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index 9472138c3..1e052a553 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -1976,26 +1976,31 @@ 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>()) && - kind == ConstantFoldingKind::SpecializationConstant) - { - // Float-to-inst casts cannot be`OpSpecConstOp` operations in SPIR-V, - // which means they need to be local instructions can cannot be hoisted to the - // global scope. Deduplication logic is run for `IntVal`s however and without hoisting - // instructions using this `IntVal` will trigger error. Hence we emit error here - // to not allow such cases. - // - // Note that float-to-inst casts for non-`IntVal`s are allowed. - if (!isScalarIntegerType(decl->getType())) + if (decl->hasModifier<SpecializationConstantAttribute>() || + decl->hasModifier<VkConstantIdAttribute>()) + { + if (kind == ConstantFoldingKind::SpecializationConstant) { - getSink()->diagnose(declRef, Diagnostics::intValFromNonIntSpecConstEncountered); - return nullptr; - } + // Float-to-inst casts cannot be`OpSpecConstOp` operations in SPIR-V, + // which means they need to be local instructions can cannot be hoisted to the + // global scope. Deduplication logic is run for `IntVal`s however and without hoisting + // instructions using this `IntVal` will trigger error. Hence we emit error here + // to not allow such cases. + // + // Note that float-to-inst casts for non-`IntVal`s are allowed. + if (!isScalarIntegerType(decl->getType())) + { + getSink()->diagnose(declRef, Diagnostics::intValFromNonIntSpecConstEncountered); + return nullptr; + } - return m_astBuilder->getOrCreate<DeclRefIntVal>( - declRef.substitute(m_astBuilder, decl->getType()), - declRef); + return m_astBuilder->getOrCreate<DeclRefIntVal>( + declRef.substitute(m_astBuilder, decl->getType()), + declRef); + } + // Don't fold on other folding passes, we don't actually know the + // values. + return nullptr; } if (decl->hasModifier<ExternModifier>()) |
