summaryrefslogtreecommitdiff
path: root/src/mesa/shader
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/shader')
-rw-r--r--src/mesa/shader/slang/slang_codegen.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index cf3569c3b0..bd403b7c30 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -1363,6 +1363,22 @@ _slang_is_constant_cond(const slang_operation *oper, GLboolean *value)
}
+/**
+ * Test if an operation is a scalar or boolean.
+ */
+static GLboolean
+_slang_is_scalar_or_boolean(slang_assemble_ctx *A, slang_operation *oper)
+{
+ slang_typeinfo type;
+ GLint size;
+
+ slang_typeinfo_construct(&type);
+ _slang_typeof_operation(A, oper, &type);
+ size = _slang_sizeof_type_specifier(&type.spec);
+ slang_typeinfo_destruct(&type);
+ return size == 1;
+}
+
/**
* Generate loop code using high-level IR_LOOP instruction
@@ -1378,6 +1394,12 @@ _slang_gen_while(slang_assemble_ctx * A, const slang_operation *oper)
slang_ir_node *prevLoop, *loop, *cond, *breakIf, *body;
GLboolean isConst, constTrue;
+ /* type-check expression */
+ if (!_slang_is_scalar_or_boolean(A, &oper->children[0])) {
+ slang_info_log_error(A->log, "scalar/boolean expression expected for 'while'");
+ return NULL;
+ }
+
/* Check if loop condition is a constant */
isConst = _slang_is_constant_cond(&oper->children[0], &constTrue);
@@ -1434,6 +1456,12 @@ _slang_gen_do(slang_assemble_ctx * A, const slang_operation *oper)
slang_ir_node *prevLoop, *loop, *cond;
GLboolean isConst, constTrue;
+ /* type-check expression */
+ if (!_slang_is_scalar_or_boolean(A, &oper->children[1])) {
+ slang_info_log_error(A->log, "scalar/boolean expression expected for 'do/while'");
+ return NULL;
+ }
+
loop = new_loop(NULL);
/* save old, push new loop */
@@ -1556,6 +1584,12 @@ _slang_gen_if(slang_assemble_ctx * A, const slang_operation *oper)
slang_ir_node *ifNode, *cond, *ifBody, *elseBody;
GLboolean isConst, constTrue;
+ /* type-check expression */
+ if (!_slang_is_scalar_or_boolean(A, &oper->children[0])) {
+ slang_info_log_error(A->log, "scalar/boolean expression expected for 'if'");
+ return NULL;
+ }
+
isConst = _slang_is_constant_cond(&oper->children[0], &constTrue);
if (isConst) {
if (constTrue) {