diff options
author | Brian Paul <brianp@vmware.com> | 2009-06-26 12:34:03 -0600 |
---|---|---|
committer | Brian Paul <brianp@vmware.com> | 2009-06-26 12:34:03 -0600 |
commit | aa835b0fbe229f8421b36f26bcff359c098dc7af (patch) | |
tree | 49d204379de30d239511381c4ccd7c854a11ab6c | |
parent | b0602823dc4e79c5071285acecb0cc10d65db151 (diff) |
glsl: move/simplify error checking for 'return' statementsglsl-continue-return
-rw-r--r-- | src/mesa/shader/slang/slang_codegen.c | 36 |
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); } |