From 6308a1224672944220a1fee34ae22f70212703a0 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Tue, 25 Feb 2020 08:12:16 -0800 Subject: 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 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. --- source/slang/slang-check-expr.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'source/slang/slang-check-expr.cpp') diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index 524bab4e4..adfc36641 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -828,7 +828,7 @@ namespace Slang return TryConstantFoldExpr(exp); } - RefPtr SemanticsVisitor::CheckIntegerConstantExpression(Expr* inExpr) + RefPtr SemanticsVisitor::CheckIntegerConstantExpression(Expr* inExpr, DiagnosticSink* sink) { // No need to issue further errors if the expression didn't even type-check. if(IsErrorExpr(inExpr)) return nullptr; @@ -840,13 +840,18 @@ namespace Slang if(IsErrorExpr(expr)) return nullptr; auto result = TryCheckIntegerConstantExpression(expr.Ptr()); - if (!result) + if (!result && sink) { - getSink()->diagnose(expr, Diagnostics::expectedIntegerConstantNotConstant); + sink->diagnose(expr, Diagnostics::expectedIntegerConstantNotConstant); } return result; } + RefPtr SemanticsVisitor::CheckIntegerConstantExpression(Expr* inExpr) + { + return CheckIntegerConstantExpression(inExpr, getSink()); + } + RefPtr SemanticsVisitor::CheckEnumConstantExpression(Expr* expr) { // No need to issue further errors if the expression didn't even type-check. -- cgit v1.2.3