From 351136a636d755a308ea58f0075e6a79c2e6d8b9 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 15 Jan 2025 18:21:00 +0900 Subject: [PATCH] [qfcc] Fix a few segfaults compiling glsl --- tools/qfcc/source/expr_call.c | 1 + tools/qfcc/source/function.c | 8 +++++--- tools/qfcc/source/target_spirv.c | 4 ++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/qfcc/source/expr_call.c b/tools/qfcc/source/expr_call.c index 48c118e2f..109540b4b 100644 --- a/tools/qfcc/source/expr_call.c +++ b/tools/qfcc/source/expr_call.c @@ -430,6 +430,7 @@ build_function_call (const expr_t *fexpr, const type_t *ftype, "inlined not implemented"); } else { auto call = new_block_expr (nullptr); + call->block.scope = current_symtab; call->block.is_call = 1; int num_args = 0; const expr_t *arg_exprs[arg_count + 1][2]; diff --git a/tools/qfcc/source/function.c b/tools/qfcc/source/function.c index 6572dd0e0..d758f05b0 100644 --- a/tools/qfcc/source/function.c +++ b/tools/qfcc/source/function.c @@ -756,8 +756,8 @@ create_generic_sym (genfunc_t *g, const expr_t *fexpr, calltype_t *calltype, rua_ctx_t *ctx) { int num_params = calltype->num_params; - const type_t *param_types[num_params]; - param_qual_t param_quals[num_params]; + const type_t *param_types[num_params] = {}; + param_qual_t param_quals[num_params] = {}; const type_t *return_type; for (int i = 0; i < num_params; i++) { auto p = &g->params[i]; @@ -1065,6 +1065,7 @@ find_function (const expr_t *fexpr, const expr_t *params, rua_ctx_t *ctx) // time sym->metafunc->func = new_function (sym->name, gen->name); sym->metafunc->func->type = sym->type; + sym->metafunc->func->sym = sym; build_generic_scope (sym, current_symtab, gen, ref_types); } return new_symbol_expr (sym); @@ -1323,6 +1324,8 @@ build_code_function (specifier_t spec, const expr_t *state_expr, genfunc->can_inline = can_inline (statements, fsym); return; } + function_t *func = fsym->metafunc->func; + current_func = func; if (ctx) { statements = (expr_t *) expr_process (statements, ctx); } @@ -1333,7 +1336,6 @@ build_code_function (specifier_t spec, const expr_t *state_expr, if (state_expr) { prepend_expr (statements, state_expr); } - function_t *func = fsym->metafunc->func; current_target.build_code (func, statements); } diff --git a/tools/qfcc/source/target_spirv.c b/tools/qfcc/source/target_spirv.c index 3b9dab5aa..f46c1beea 100644 --- a/tools/qfcc/source/target_spirv.c +++ b/tools/qfcc/source/target_spirv.c @@ -1210,6 +1210,10 @@ spirv_symbol (const expr_t *e, spirvctx_t *ctx) } } else if (sym->sy_type == sy_func) { auto func = sym->metafunc->func; + if (!func) { + error (e, "%s called but not defined", sym->name); + return 0; + } sym->id = spirv_function_ref (func, ctx); } else if (sym->sy_type == sy_var) { sym->id = spirv_variable (sym, ctx);