summaryrefslogtreecommitdiffstats
path: root/source/slang/check.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-03-05 17:24:44 -0500
committerGitHub <noreply@github.com>2019-03-05 17:24:44 -0500
commitdcd9e574782b87d6280f1db8ee9ba6dbb7c96c8b (patch)
treedcb900ec86c6454ff2fcbe16dea6512fdec49413 /source/slang/check.cpp
parent3d5546600fb4c585b6f6f6dcdb5e122698d1225e (diff)
Hotfix/crash invalid vk binding (#875)
* Add diagnostic for vk::binding failure. * Add test for vk::binding failure. * Add the expected output for glsl-layout-define.hlsl * * Copy over initialize expr if available when validating unchecked * Fix unloop - because now it always has one parameter (when before it could have none) * Split vk::binding and layout tests with invalid parameters * Removed the diagnostic for 2 ints expected * Added vk::binding that doesn't specify set in vk-bindings.slang * * Fix typo * Improve comments.
Diffstat (limited to 'source/slang/check.cpp')
-rw-r--r--source/slang/check.cpp27
1 files changed, 25 insertions, 2 deletions
diff --git a/source/slang/check.cpp b/source/slang/check.cpp
index 998324612..37c0d5baf 100644
--- a/source/slang/check.cpp
+++ b/source/slang/check.cpp
@@ -2603,10 +2603,24 @@ namespace Slang
}
else if (auto bindingAttr = as<GLSLBindingAttribute>(attr))
{
- SLANG_ASSERT(attr->args.Count() == 2);
+ // This must be vk::binding or gl::binding (as specified in core.meta.slang under vk_binding/gl_binding)
+ // Must have 2 int parameters. Ideally this would all be checked from the specification
+ // in core.meta.slang, but that's not completely implemented. So for now we check here.
+ if (attr->args.Count() != 2)
+ {
+ return false;
+ }
+
+ // TODO(JS): Prior validation currently doesn't ensure both args are ints (as specified in core.meta.slang), so check here
+ // to make sure they both are
auto binding = checkConstantIntVal(attr->args[0]);
auto set = checkConstantIntVal(attr->args[1]);
+ if (binding == nullptr || set == nullptr)
+ {
+ return false;
+ }
+
bindingAttr->binding = int32_t(binding->value);
bindingAttr->set = int32_t(set->value);
}
@@ -2703,6 +2717,13 @@ namespace Slang
return false;
}
}
+ else if (auto unrollAttr = as<UnrollAttribute>(attr))
+ {
+ // Check has an argument. We need this because default behavior is to give an error
+ // if an attribute has arguments, but not handled explicitly (and the default param will come through
+ // as 1 arg if nothing is specified)
+ SLANG_ASSERT(attr->args.Count() == 1);
+ }
else if (auto userDefAttr = as<UserDefinedAttribute>(attr))
{
// check arguments against attribute parameters defined in attribClassDecl
@@ -2813,7 +2834,6 @@ namespace Slang
{
// TODO: support checking the argument against the declared
// type for the parameter.
-
}
else
{
@@ -2826,6 +2846,9 @@ namespace Slang
//
// TODO: we need to figure out how to hook up
// default arguments as needed.
+ // For now just copy the expression over.
+
+ attr->args.Add(paramDecl->initExpr);
}
else
{