From c5bfa57e8ffe7435375b122d1cd7d7da72f6916f Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Thu, 24 Jul 2025 13:58:52 +0200 Subject: [PATCH] microsoft/compiler: fix returning _Bool instead of pointer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When building for C23 the compiler warns about returning a boolean when a different type is expected instead. Change the code to return NULL instead of false, fixing the following errors: ----------------------------------------------------------------------- ../src/microsoft/compiler/dxil_module.c: In function ‘create_call_instr’: ../src/microsoft/compiler/dxil_module.c:3311:17: error: incompatible types when returning type ‘_Bool’ but ‘struct dxil_instr *’ was expected 3311 | return false; | ^~~~~ ../src/microsoft/compiler/dxil_module.c: In function ‘dxil_emit_load’: ../src/microsoft/compiler/dxil_module.c:3469:14: error: incompatible types when returning type ‘_Bool’ but ‘const struct dxil_value *’ was expected 3469 | return false; | ^~~~~ ../src/microsoft/compiler/dxil_module.c: In function ‘dxil_emit_cmpxchg’: ../src/microsoft/compiler/dxil_module.c:3511:14: error: incompatible types when returning type ‘_Bool’ but ‘const struct dxil_value *’ was expected 3511 | return false; | ^~~~~ ../src/microsoft/compiler/dxil_module.c: In function ‘dxil_emit_atomicrmw’: ../src/microsoft/compiler/dxil_module.c:3535:14: error: incompatible types when returning type ‘_Bool’ but ‘const struct dxil_value *’ was expected 3535 | return false; | ^~~~~ ../src/microsoft/compiler/dxil_function.c: In function ‘dxil_alloc_func_with_rettype’: ../src/microsoft/compiler/dxil_function.c:251:17: error: incompatible types when returning type ‘_Bool’ but ‘const struct dxil_func *’ was expected 251 | return false; | ^~~~~ ../src/microsoft/compiler/dxil_function.c:261:14: error: incompatible types when returning type ‘_Bool’ but ‘const struct dxil_func *’ was expected 261 | return false; | ^~~~~ ../src/microsoft/compiler/nir_to_dxil.c: In function ‘emit_atomic_binop’: ../src/microsoft/compiler/nir_to_dxil.c:959:14: error: incompatible types when returning type ‘_Bool’ but ‘const struct dxil_value *’ was expected 959 | return false; | ^~~~~ ../src/microsoft/compiler/nir_to_dxil.c: In function ‘emit_atomic_cmpxchg’: ../src/microsoft/compiler/nir_to_dxil.c:984:14: error: incompatible types when returning type ‘_Bool’ but ‘const struct dxil_value *’ was expected 984 | return false; | ^~~~~ ../src/microsoft/compiler/nir_to_dxil.c: In function ‘emit_threads’: ../src/microsoft/compiler/nir_to_dxil.c:1793:14: error: incompatible types when returning type ‘_Bool’ but ‘const struct dxil_mdnode *’ was expected 1793 | return false; | ^~~~~ ../src/microsoft/compiler/nir_to_dxil.c: In function ‘call_unary_external_function’: ../src/microsoft/compiler/nir_to_dxil.c:3223:14: error: incompatible types when returning type ‘_Bool’ but ‘const struct dxil_value *’ was expected 3223 | return false; | ^~~~~ ../src/microsoft/compiler/nir_to_dxil.c:3228:14: error: incompatible types when returning type ‘_Bool’ but ‘const struct dxil_value *’ was expected 3228 | return false; | ^~~~~ ../src/microsoft/compiler/nir_to_dxil.c: In function ‘emit_texture_size’: ../src/microsoft/compiler/nir_to_dxil.c:4305:14: error: incompatible types when returning type ‘_Bool’ but ‘const struct dxil_value *’ was expected 4305 | return false; | ^~~~~ ../src/microsoft/compiler/nir_to_dxil.c: In function ‘emit_sample_grad’: ../src/microsoft/compiler/nir_to_dxil.c:5350:14: error: incompatible types when returning type ‘_Bool’ but ‘const struct dxil_value *’ was expected 5350 | return false; | ^~~~~ ../src/microsoft/compiler/nir_to_dxil.c: In function ‘emit_sample_cmp_grad’: ../src/microsoft/compiler/nir_to_dxil.c:5370:14: error: incompatible types when returning type ‘_Bool’ but ‘const struct dxil_value *’ was expected 5370 | return false; | ^~~~~ ../src/microsoft/compiler/nir_to_dxil.c: In function ‘emit_texel_fetch’: ../src/microsoft/compiler/nir_to_dxil.c:5393:14: error: incompatible types when returning type ‘_Bool’ but ‘const struct dxil_value *’ was expected 5393 | return false; | ^~~~~ ../src/microsoft/compiler/nir_to_dxil.c: In function ‘emit_texture_lod’: ../src/microsoft/compiler/nir_to_dxil.c:5413:14: error: incompatible types when returning type ‘_Bool’ but ‘const struct dxil_value *’ was expected 5413 | return false; | ^~~~~ ../src/microsoft/compiler/nir_to_dxil.c: In function ‘emit_texture_gather’: ../src/microsoft/compiler/nir_to_dxil.c:5434:14: error: incompatible types when returning type ‘_Bool’ but ‘const struct dxil_value *’ was expected 5434 | return false; | ^~~~~ ----------------------------------------------------------------------- Reviewed-by: Faith Ekstrand Reviewed-by: Jesse Natalie Part-of: --- src/microsoft/compiler/dxil_function.c | 4 ++-- src/microsoft/compiler/dxil_module.c | 8 ++++---- src/microsoft/compiler/nir_to_dxil.c | 22 +++++++++++----------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/microsoft/compiler/dxil_function.c b/src/microsoft/compiler/dxil_function.c index 483e85be61f..8fcf30585a2 100644 --- a/src/microsoft/compiler/dxil_function.c +++ b/src/microsoft/compiler/dxil_function.c @@ -248,7 +248,7 @@ dxil_alloc_func_with_rettype(struct dxil_module *mod, const char *name, while (param_descr[num_params]) { const struct dxil_type *t = get_type_from_string(mod, param_descr, overload, &index); if (!t) - return false; + return NULL; assert(num_params < MAX_FUNC_PARAMS); arg_types[num_params++] = t; } @@ -258,7 +258,7 @@ dxil_alloc_func_with_rettype(struct dxil_module *mod, const char *name, arg_types, num_params); if (!func_type) { fprintf(stderr, "%s: Func type allocation failed\n", __func__); - return false; + return NULL; } char full_name[100]; diff --git a/src/microsoft/compiler/dxil_module.c b/src/microsoft/compiler/dxil_module.c index 7be3cdf3918..94433121bff 100644 --- a/src/microsoft/compiler/dxil_module.c +++ b/src/microsoft/compiler/dxil_module.c @@ -3308,7 +3308,7 @@ create_call_instr(struct dxil_module *m, instr->call.func = func; instr->call.args = ralloc_array(instr, struct dxil_value *, num_args); if (!args) - return false; + return NULL; memcpy(instr->call.args, args, sizeof(struct dxil_value *) * num_args); instr->call.num_args = num_args; } @@ -3466,7 +3466,7 @@ dxil_emit_load(struct dxil_module *m, const struct dxil_value *ptr, struct dxil_instr *instr = create_instr(m, INSTR_LOAD, type); if (!instr) - return false; + return NULL; instr->load.ptr = ptr; instr->load.type = type; @@ -3508,7 +3508,7 @@ dxil_emit_cmpxchg(struct dxil_module *m, const struct dxil_value *cmpval, struct dxil_instr *instr = create_instr(m, INSTR_CMPXCHG, ptr->type->ptr_target_type); if (!instr) - return false; + return NULL; instr->cmpxchg.cmpval = cmpval; instr->cmpxchg.newval = newval; @@ -3532,7 +3532,7 @@ dxil_emit_atomicrmw(struct dxil_module *m, const struct dxil_value *value, struct dxil_instr *instr = create_instr(m, INSTR_ATOMICRMW, ptr->type->ptr_target_type); if (!instr) - return false; + return NULL; instr->atomicrmw.value = value; instr->atomicrmw.ptr = ptr; diff --git a/src/microsoft/compiler/nir_to_dxil.c b/src/microsoft/compiler/nir_to_dxil.c index 5a10a335256..b62f8506fee 100644 --- a/src/microsoft/compiler/nir_to_dxil.c +++ b/src/microsoft/compiler/nir_to_dxil.c @@ -956,7 +956,7 @@ emit_atomic_binop(struct ntd_context *ctx, const struct dxil_func *func = dxil_get_function(&ctx->mod, "dx.op.atomicBinOp", DXIL_I32); if (!func) - return false; + return NULL; const struct dxil_value *opcode = dxil_module_get_int32_const(&ctx->mod, DXIL_INTR_ATOMIC_BINOP); @@ -981,7 +981,7 @@ emit_atomic_cmpxchg(struct ntd_context *ctx, dxil_get_function(&ctx->mod, "dx.op.atomicCompareExchange", DXIL_I32); if (!func) - return false; + return NULL; const struct dxil_value *opcode = dxil_module_get_int32_const(&ctx->mod, DXIL_INTR_ATOMIC_CMPXCHG); @@ -1790,7 +1790,7 @@ emit_threads(struct ntd_context *ctx) const struct dxil_mdnode *threads_y = dxil_get_metadata_int32(&ctx->mod, MAX2(s->info.workgroup_size[1], 1)); const struct dxil_mdnode *threads_z = dxil_get_metadata_int32(&ctx->mod, MAX2(s->info.workgroup_size[2], 1)); if (!threads_x || !threads_y || !threads_z) - return false; + return NULL; const struct dxil_mdnode *threads_nodes[] = { threads_x, threads_y, threads_z }; return dxil_get_metadata_node(&ctx->mod, threads_nodes, ARRAY_SIZE(threads_nodes)); @@ -3220,12 +3220,12 @@ call_unary_external_function(struct ntd_context *ctx, const struct dxil_func *func = dxil_get_function(&ctx->mod, name, overload); if (!func) - return false; + return NULL; const struct dxil_value *opcode = dxil_module_get_int32_const(&ctx->mod, dxil_intr); if (!opcode) - return false; + return NULL; const struct dxil_value *args[] = {opcode}; @@ -4302,7 +4302,7 @@ emit_texture_size(struct ntd_context *ctx, struct texop_parameters *params) { const struct dxil_func *func = dxil_get_function(&ctx->mod, "dx.op.getDimensions", DXIL_NONE); if (!func) - return false; + return NULL; const struct dxil_value *args[] = { dxil_module_get_int32_const(&ctx->mod, DXIL_INTR_TEXTURE_SIZE), @@ -5347,7 +5347,7 @@ emit_sample_grad(struct ntd_context *ctx, struct texop_parameters *params) { const struct dxil_func *func = dxil_get_function(&ctx->mod, "dx.op.sampleGrad", params->overload); if (!func) - return false; + return NULL; const struct dxil_value *args[17] = { dxil_module_get_int32_const(&ctx->mod, DXIL_INTR_SAMPLE_GRAD), @@ -5367,7 +5367,7 @@ emit_sample_cmp_grad(struct ntd_context *ctx, struct texop_parameters *params) { const struct dxil_func *func = dxil_get_function(&ctx->mod, "dx.op.sampleCmpGrad", params->overload); if (!func) - return false; + return NULL; ctx->mod.feats.sample_cmp_bias_gradient = 1; @@ -5390,7 +5390,7 @@ emit_texel_fetch(struct ntd_context *ctx, struct texop_parameters *params) { const struct dxil_func *func = dxil_get_function(&ctx->mod, "dx.op.textureLoad", params->overload); if (!func) - return false; + return NULL; if (!params->lod_or_sample) params->lod_or_sample = dxil_module_get_undef(&ctx->mod, dxil_module_get_int_type(&ctx->mod, 32)); @@ -5410,7 +5410,7 @@ emit_texture_lod(struct ntd_context *ctx, struct texop_parameters *params, bool { const struct dxil_func *func = dxil_get_function(&ctx->mod, "dx.op.calculateLOD", DXIL_F32); if (!func) - return false; + return NULL; const struct dxil_value *args[] = { dxil_module_get_int32_const(&ctx->mod, DXIL_INTR_TEXTURE_LOD), @@ -5431,7 +5431,7 @@ emit_texture_gather(struct ntd_context *ctx, struct texop_parameters *params, un const struct dxil_func *func = dxil_get_function(&ctx->mod, params->cmp ? "dx.op.textureGatherCmp" : "dx.op.textureGather", params->overload); if (!func) - return false; + return NULL; const struct dxil_value *args[] = { dxil_module_get_int32_const(&ctx->mod, params->cmp ?