Mesa (7.10): glsl: Don' t assert when the value returned by a function has no rvalue

Ian Romanick idr at kemper.freedesktop.org
Sat Feb 5 00:14:06 UTC 2011


Module: Mesa
Branch: 7.10
Commit: b51b8db4506dad9930497f96c4ef754fba8bfe67
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b51b8db4506dad9930497f96c4ef754fba8bfe67

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Sat Jan 22 17:47:05 2011 -0800

glsl: Don't assert when the value returned by a function has no rvalue

The rvalue of the returned value can be NULL if the shader says
'return foo();' and foo() is a function that returns void.

Existing GLSL specs do *NOT* say that this is an error.  The type of
the return value is void.  If the return type of the function is also
void, then this should compile without error.  I expect that future
versions of the GLSL spec will fix this (wink, wink, nudge, nudge).

Fixes piglit test glsl-1.10/compiler/expressions/return-01.vert and
bugzilla #33308.

NOTE: This is a candidate for the 7.9 and 7.10 branches.
(cherry picked from commit 2db46fe5f0145a6afff5b8edc2f00b8c734bb640)

---

 src/glsl/ast_to_hir.cpp |   25 ++++++++++++-------------
 1 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 8e74879..c444e62 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -2892,27 +2892,26 @@ ast_jump_statement::hir(exec_list *instructions,
       assert(state->current_function);
 
       if (opt_return_value) {
-	 if (state->current_function->return_type->base_type ==
-	     GLSL_TYPE_VOID) {
-	    YYLTYPE loc = this->get_location();
-
-	    _mesa_glsl_error(& loc, state,
-			     "`return` with a value, in function `%s' "
-			     "returning void",
-			     state->current_function->function_name());
-	 }
-
 	 ir_rvalue *const ret = opt_return_value->hir(instructions, state);
-	 assert(ret != NULL);
+
+	 /* The value of the return type can be NULL if the shader says
+	  * 'return foo();' and foo() is a function that returns void.
+	  *
+	  * NOTE: The GLSL spec doesn't say that this is an error.  The type
+	  * of the return value is void.  If the return type of the function is
+	  * also void, then this should compile without error.  Seriously.
+	  */
+	 const glsl_type *const ret_type =
+	    (ret == NULL) ? glsl_type::void_type : ret->type;
 
 	 /* Implicit conversions are not allowed for return values. */
-	 if (state->current_function->return_type != ret->type) {
+	 if (state->current_function->return_type != ret_type) {
 	    YYLTYPE loc = this->get_location();
 
 	    _mesa_glsl_error(& loc, state,
 			     "`return' with wrong type %s, in function `%s' "
 			     "returning %s",
-			     ret->type->name,
+			     ret_type->name,
 			     state->current_function->function_name(),
 			     state->current_function->return_type->name);
 	 }




More information about the mesa-commit mailing list