From: Erik Faye-Lund Date: Thu, 13 Jun 2019 10:03:27 +0000 (+0200) Subject: glsl: report no function instead of empty candidate list X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c5f14322965cc006038e293902412e76ad268767;p=mesa.git glsl: report no function instead of empty candidate list When generating the error message for a missing function error where all available overloads were missing due to a too low GLSL version, we used to report something like this: ---8<--- 0:224(14): error: no matching function for call to `textureCubeLod(samplerCube, vec3, float)'; candidates are: 0:224(14): error: type mismatch ---8<--- This is a pretty confusing error message, and can throw people off when debugging. So let's instead check if any overload is available before we decide what to print. This allow us to report something like this instead: ---8<--- 0:224(14): error: no function with name 'textureCubeLod' 0:224(14): error: type mismatch ---8<--- This is arguably easier to understand for programmers, and doesn't send you on a wild goose chase to figure out what argument is wrong just because you stopped reading the message prematurely. I'm of course referring to a friend, not me. For sure. I would never do that. Signed-off-by: Erik Faye-Lund Reviewed-by: Matt Turner --- diff --git a/src/compiler/glsl/ast_function.cpp b/src/compiler/glsl/ast_function.cpp index 80cbb582b0e..0ed47660e22 100644 --- a/src/compiler/glsl/ast_function.cpp +++ b/src/compiler/glsl/ast_function.cpp @@ -748,6 +748,21 @@ generate_array_index(void *mem_ctx, exec_list *instructions, } } +static bool +function_exists(_mesa_glsl_parse_state *state, + struct glsl_symbol_table *symbols, const char *name) +{ + ir_function *f = symbols->get_function(name); + if (f != NULL) { + foreach_in_list(ir_function_signature, sig, &f->signatures) { + if (sig->is_builtin() && !sig->is_builtin_available(state)) + continue; + return true; + } + } + return false; +} + static void print_function_prototypes(_mesa_glsl_parse_state *state, YYLTYPE *loc, ir_function *f) @@ -778,9 +793,9 @@ no_matching_function_error(const char *name, { gl_shader *sh = _mesa_glsl_get_builtin_function_shader(); - if (state->symbols->get_function(name) == NULL + if (!function_exists(state, state->symbols, name) && (!state->uses_builtin_functions - || sh->symbols->get_function(name) == NULL)) { + || !function_exists(state, sh->symbols, name))) { _mesa_glsl_error(loc, state, "no function with name '%s'", name); } else { char *str = prototype_string(NULL, name, actual_parameters);