[Mesa-dev] [PATCH 7/7] glsl: Disallow return with a void argument from void functions.

Matt Turner mattst88 at gmail.com
Fri May 24 18:28:19 PDT 2013


NOTE: This is a candidate for the stable branches.
---
 src/glsl/ast_to_hir.cpp | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 6b56e87..6ee50f5 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -3401,7 +3401,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 {
-- 
1.8.1.5



More information about the mesa-dev mailing list