summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-check-type.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2020-02-25 08:12:16 -0800
committerGitHub <noreply@github.com>2020-02-25 08:12:16 -0800
commit6308a1224672944220a1fee34ae22f70212703a0 (patch)
tree25d2011e23e64d2794dc1b07e2fa70785e13700f /source/slang/slang-check-type.cpp
parentc4a32e34f68c5d202b8a4a867963a1ecbb03b96e (diff)
Fix a crash when a generic value argument isn't constant (#1241)
This arose when a user tried to specialize the DXR 1.1 `RayQuery` type to a local variable: ```hlsl RAY_FLAG rayFlags = RAY_FLAG_CULL_FRONT_FACING_TRIANGLES | RAY_FLAG_CULL_NON_OPAQUE; RayQuery<rayFlags> query; ``` In this case, we issued an error around `rayFlags` not being a constant as expected, but then we also crashes later on in checking because the `DeclRef` that was being used for the type had a null pointer for the generic argument corresponding to `rayFlags`. The main fix here was thus to add an `ErrorIntVal` case that can be used to represent something that should be an `IntVal` but where there was some kind of error in the input code so that the actual value isn't known to the compiler. A secondary fix here is that we were issuing error messages about expecting a constant for a parameter like `rayFlags` there *twice*, and one of those times was during the `JustChecking` part of overload resolution (when we are not supposed to emit any diagnostics). I fixed that up by allowing the `DiagnosticSink` to be used to be passed down explicitly (and allowing it to be null), while also leaving behind overloaded functions with the old signatures so that all the existing logic can continue to work unmodified.
Diffstat (limited to 'source/slang/slang-check-type.cpp')
-rw-r--r--source/slang/slang-check-type.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/source/slang/slang-check-type.cpp b/source/slang/slang-check-type.cpp
index b92f9a8f7..68e14c462 100644
--- a/source/slang/slang-check-type.cpp
+++ b/source/slang/slang-check-type.cpp
@@ -105,9 +105,22 @@ namespace Slang
return ExpectAType(exp);
}
+ RefPtr<IntVal> SemanticsVisitor::ExtractGenericArgInteger(RefPtr<Expr> exp, DiagnosticSink* sink)
+ {
+ RefPtr<IntVal> val = CheckIntegerConstantExpression(exp.Ptr(), sink);
+ if(val) return val;
+
+ // If the argument expression could not be coerced to an integer
+ // constant expression in context, then we will instead construct
+ // a dummy "error" value to represent the result.
+ //
+ val = new ErrorIntVal();
+ return val;
+ }
+
RefPtr<IntVal> SemanticsVisitor::ExtractGenericArgInteger(RefPtr<Expr> exp)
{
- return CheckIntegerConstantExpression(exp.Ptr());
+ return ExtractGenericArgInteger(exp, getSink());
}
RefPtr<Val> SemanticsVisitor::ExtractGenericArgVal(RefPtr<Expr> exp)