From ab372dab2a013e5d0c8ee57bb799a76c9a78abf2 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Sun, 28 Mar 2010 01:24:55 -0700 Subject: [PATCH] Reject main() declarations with a non-void return value. Fixes main3.vert. --- ast_to_hir.cpp | 9 ++++++++- glsl_types.cpp | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ast_to_hir.cpp b/ast_to_hir.cpp index 277e67ba389..e16f79f6f21 100644 --- a/ast_to_hir.cpp +++ b/ast_to_hir.cpp @@ -1146,7 +1146,6 @@ ast_function_definition::hir(exec_list *instructions, assert(return_type != NULL); - /* Verify that this function's signature either doesn't match a previously * seen signature for a function with the same name, or, if a match is found, * that the previously seen signature does not have an associated definition. @@ -1190,6 +1189,14 @@ ast_function_definition::hir(exec_list *instructions, state->symbols->add_function(f->name, f); } + /* Verify the return type of main() */ + if (strcmp(name, "main") == 0) { + if (return_type != glsl_type::get_instance(GLSL_TYPE_VOID, 0, 0)) { + YYLTYPE loc = this->get_location(); + + _mesa_glsl_error(& loc, state, "main() must return void"); + } + } /* Finish storing the information about this new function in its signature. */ diff --git a/glsl_types.cpp b/glsl_types.cpp index 55d960320db..df9667f8dce 100644 --- a/glsl_types.cpp +++ b/glsl_types.cpp @@ -489,10 +489,12 @@ _mesa_glsl_initialize_constructors(exec_list *instructions, const glsl_type * glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns) { + if (base_type == GLSL_TYPE_VOID) + return &void_type; + if ((rows < 1) || (rows > 4) || (columns < 1) || (columns > 4)) return error_type; - /* Treat GLSL vectors as Nx1 matrices. */ if (columns == 1) { -- 2.30.2