glsl2: Check for non-void functions that don't have a return statement.
This doesn't do any control flow analysis to ensure that the return statements are actually reached. Fixes piglit tests function5.frag and function-07.vert.
This commit is contained in:

committed by
Ian Romanick

parent
ac04c257e3
commit
6de8256505
@@ -2097,6 +2097,7 @@ ast_function_definition::hir(exec_list *instructions,
|
|||||||
|
|
||||||
assert(state->current_function == NULL);
|
assert(state->current_function == NULL);
|
||||||
state->current_function = signature;
|
state->current_function = signature;
|
||||||
|
state->found_return = false;
|
||||||
|
|
||||||
/* Duplicate parameters declared in the prototype as concrete variables.
|
/* Duplicate parameters declared in the prototype as concrete variables.
|
||||||
* Add these to the symbol table.
|
* Add these to the symbol table.
|
||||||
@@ -2128,6 +2129,14 @@ ast_function_definition::hir(exec_list *instructions,
|
|||||||
assert(state->current_function == signature);
|
assert(state->current_function == signature);
|
||||||
state->current_function = NULL;
|
state->current_function = NULL;
|
||||||
|
|
||||||
|
if (!signature->return_type->is_void() && !state->found_return) {
|
||||||
|
YYLTYPE loc = this->get_location();
|
||||||
|
_mesa_glsl_error(& loc, state, "function `%s' has non-void return type "
|
||||||
|
"%s, but no return statement",
|
||||||
|
signature->function_name(),
|
||||||
|
signature->return_type->name);
|
||||||
|
}
|
||||||
|
|
||||||
/* Function definitions do not have r-values.
|
/* Function definitions do not have r-values.
|
||||||
*/
|
*/
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -2186,6 +2195,7 @@ ast_jump_statement::hir(exec_list *instructions,
|
|||||||
inst = new(ctx) ir_return;
|
inst = new(ctx) ir_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
state->found_return = true;
|
||||||
instructions->push_tail(inst);
|
instructions->push_tail(inst);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -51,6 +51,9 @@ struct _mesa_glsl_parse_state {
|
|||||||
*/
|
*/
|
||||||
class ir_function_signature *current_function;
|
class ir_function_signature *current_function;
|
||||||
|
|
||||||
|
/** Have we found a return statement in this function? */
|
||||||
|
bool found_return;
|
||||||
|
|
||||||
/** Was there an error during compilation? */
|
/** Was there an error during compilation? */
|
||||||
bool error;
|
bool error;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user