summaryrefslogtreecommitdiff
path: root/src/mesa/shader
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2009-06-26 12:34:03 -0600
committerBrian Paul <brianp@vmware.com>2009-06-26 13:16:34 -0600
commite80ecdf6596eb1f570ab6ae3dbcbd30660cd5b3a (patch)
tree53a8817e251eec81299307cef1f5fb39e8167fa7 /src/mesa/shader
parent8e6dd8bf7991d8fc4938af692e5ce880ef139b4d (diff)
glsl: move/simplify error checking for 'return' statements
Diffstat (limited to 'src/mesa/shader')
-rw-r--r--src/mesa/shader/slang/slang_codegen.c36
1 files changed, 14 insertions, 22 deletions
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index 28d04d396d..24e9952386 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -950,6 +950,11 @@ gen_return_with_expression(slang_assemble_ctx *A, slang_operation *oper)
assert(oper->type == SLANG_OPER_RETURN);
+ if (A->CurFunction->header.type.specifier.type == SLANG_SPEC_VOID) {
+ slang_info_log_error(A->log, "illegal return expression");
+ return NULL;
+ }
+
blockOper = slang_operation_new(1);
blockOper->type = SLANG_OPER_BLOCK_NO_NEW_SCOPE;
blockOper->locals->outer_scope = oper->locals->outer_scope;
@@ -1039,6 +1044,11 @@ gen_return_without_expression(slang_assemble_ctx *A, slang_operation *oper)
assert(oper->type == SLANG_OPER_RETURN);
+ if (A->CurFunction->header.type.specifier.type != SLANG_SPEC_VOID) {
+ slang_info_log_error(A->log, "return statement requires an expression");
+ return NULL;
+ }
+
if (A->UseReturnFlag) {
/* Emit:
* __notRetFlag = 0;
@@ -1150,6 +1160,9 @@ slang_substitute(slang_assemble_ctx *A, slang_operation *oper,
else
newReturn = gen_return_with_expression(A, oper);
+ if (!newReturn)
+ return;
+
/* do substitutions on the new 'return' code */
slang_substitute(A, newReturn,
substCount, substOld, substNew, GL_FALSE);
@@ -4060,28 +4073,7 @@ _slang_gen_logical_or(slang_assemble_ctx *A, slang_operation *oper)
static slang_ir_node *
_slang_gen_return(slang_assemble_ctx * A, slang_operation *oper)
{
- const GLboolean haveReturnValue
- = (oper->num_children == 1 && oper->children[0].type != SLANG_OPER_VOID);
-
- assert(oper->type == SLANG_OPER_RETURN ||
- oper->type == SLANG_OPER_RETURN_INLINED);
-
- /* error checking */
- if (oper->type == SLANG_OPER_RETURN) {
- assert(A->CurFunction);
-
- if (haveReturnValue &&
- A->CurFunction->header.type.specifier.type == SLANG_SPEC_VOID) {
- slang_info_log_error(A->log, "illegal return expression");
- return NULL;
- }
- else if (!haveReturnValue &&
- A->CurFunction->header.type.specifier.type != SLANG_SPEC_VOID) {
- slang_info_log_error(A->log, "return statement requires an expression");
- return NULL;
- }
- }
-
+ assert(oper->type == SLANG_OPER_RETURN);
return new_return(A->curFuncEndLabel);
}