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:45:50 -0600 |
commit | beec5f0399fbd392552670b9ea930a9e63075031 (patch) | |
tree | 1289ff70e5235006d41586f2556ae50c71826457 | |
parent | 819a2f200fe06177229e7cbc5a97c1f07d684f07 (diff) |
glsl: move/simplify error checking for 'return' statements
-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); } |