mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 18:18:06 +02:00
check that if/while/do-while condition is boolean or scalar
This commit is contained in:
parent
20d85c609a
commit
59f7f6dbe9
1 changed files with 34 additions and 0 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue