summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-check-decl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-check-decl.cpp')
-rw-r--r--source/slang/slang-check-decl.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp
index e94a3eb10..e2af70fa9 100644
--- a/source/slang/slang-check-decl.cpp
+++ b/source/slang/slang-check-decl.cpp
@@ -90,6 +90,10 @@ struct SemanticsDeclAttributesVisitor : public SemanticsDeclVisitorBase,
void checkPrimalSubstituteOfAttribute(
FunctionDeclBase* funcDecl,
PrimalSubstituteOfAttribute* attr);
+
+ void checkVarDeclCommon(VarDeclBase* varDecl);
+
+ void visitVarDecl(VarDecl* varDecl) { checkVarDeclCommon(varDecl); }
};
struct SemanticsDeclHeaderVisitor : public SemanticsDeclVisitorBase,
@@ -11712,6 +11716,43 @@ bool tryCheckDerivativeOfAttributeImpl(
return tempSink.getErrorCount() == 0;
}
+void SemanticsDeclAttributesVisitor::checkVarDeclCommon(VarDeclBase* varDecl)
+{
+ bool hasSpecConstAttr = false;
+ bool hasPushConstAttr = false;
+ for (auto modifier : varDecl->modifiers)
+ {
+ if (as<SpecializationConstantAttribute>(modifier) || as<VkConstantIdAttribute>(modifier))
+ {
+ // Specialization constant.
+ // Check that type is basic type.
+ if (!as<BasicExpressionType>(varDecl->getType()) && !as<ErrorType>(varDecl->getType()))
+ {
+ getSink()->diagnose(modifier, Diagnostics::specializationConstantMustBeScalar);
+ }
+ hasSpecConstAttr = true;
+ }
+ else if (as<PushConstantAttribute>(modifier))
+ {
+ hasPushConstAttr = true;
+ }
+ }
+ if (hasSpecConstAttr && hasPushConstAttr)
+ {
+ getSink()->diagnose(
+ varDecl,
+ Diagnostics::variableCannotBePushAndSpecializationConstant,
+ varDecl->getName());
+ }
+ if (hasSpecConstAttr || hasPushConstAttr)
+ {
+ if (varDecl->findModifier<HLSLStaticModifier>())
+ {
+ getSink()->diagnose(varDecl, Diagnostics::pushOrSpecializationConstantCannotBeStatic);
+ }
+ }
+}
+
void SemanticsDeclAttributesVisitor::checkForwardDerivativeOfAttribute(
FunctionDeclBase* funcDecl,
ForwardDerivativeOfAttribute* attr)