glsl: Disallow return with a void argument from void functions.
authorMatt Turner <mattst88@gmail.com>
Wed, 22 May 2013 21:57:04 +0000 (14:57 -0700)
committerMatt Turner <mattst88@gmail.com>
Fri, 14 Jun 2013 18:25:49 +0000 (11:25 -0700)
NOTE: This is a candidate for the stable branches.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/glsl/ast_to_hir.cpp

index 22d0cad5079a54cc26247a36e3f3455ab0a5a107..4b5f04980a341abf85583f7cb243e9f8e83fcd35 100644 (file)
@@ -3393,7 +3393,23 @@ ast_jump_statement::hir(exec_list *instructions,
                                 state->current_function->function_name(),
                                 state->current_function->return_type->name);
             }
-        }
+         } else if (state->current_function->return_type->base_type ==
+                    GLSL_TYPE_VOID) {
+            YYLTYPE loc = this->get_location();
+
+            /* The ARB_shading_language_420pack, GLSL ES 3.0, and GLSL 4.20
+             * specs add a clarification:
+             *
+             *    "A void function can only use return without a return argument, even if
+             *     the return argument has void type. Return statements only accept values:
+             *
+             *         void func1() { }
+             *         void func2() { return func1(); } // illegal return statement"
+             */
+            _mesa_glsl_error(& loc, state,
+                             "void functions can only use `return' without a "
+                             "return argument");
+         }
 
         inst = new(ctx) ir_return(ret);
       } else {