build: stop calling unreachable() without arguments

The unreachable(str) macro defined in src/util/macros.h is defined to
accept a literal string as an argument.

However the way it checks that the argument is a string literal, by
prepending an empty string where the argument is used, i.e.:

  #define unreachabel(str) assert(!"" str)

still allows users to call the macro with no arguments.

This is confusing, so pass an empty string to all invocations of
unreachable() for consistency.

This is done with the following command:

  git grep -l '[^_]unreachable();' -- "src/**" | sort | uniq | \
  while read file; \
  do \
    sed -e 's/\([^_]\)unreachable();/\1unreachable("");/g' -i "$file";
  done

This should not change the behaviour of the callers of unreachable() in
a meaningful way, but there will be some cosmetic consequence.

The changed invocations will now print:

  Assertion `!"" ""' failed.

instead of

  Assertion `!""' failed.

But this is also what happens for the invocations that do pass an
argument, for instance `unreachable("Invalid type")` currently prints:

  Assertion `!"" "Invalid type"' failed.

So all invocations now also have the same output style.

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36437>
This commit is contained in:
Antonio Ospite 2025-07-29 13:55:45 +02:00 committed by Marge Bot
parent 128aa6bcae
commit b4c7d3a08e
22 changed files with 75 additions and 75 deletions

View file

@ -214,7 +214,7 @@ try_opt_quad_vote(nir_builder *b, nir_alu_instr *alu, bool block_has_discard)
lane = (nir_intrinsic_swizzle_mask(quad_broadcasts[i]) >> (j * 2)) & 0x3;
break;
default:
unreachable();
unreachable("");
}
lanes_read |= (1 << lane) << (j * 4);
}

View file

@ -303,7 +303,7 @@ emit_textures(struct fd_context *ctx, struct fd_ringbuffer *ring,
break;
default:
unreachable();
unreachable("");
}
texconst0 =

View file

@ -212,7 +212,7 @@ ei_math1_select(struct r300_vertex_program_code *vp,
case RC_MATH_DX: hw_opcode = hw_opcode_dx; break;
case RC_MATH_FF: hw_opcode = hw_opcode_ff; break;
default:
unreachable();
unreachable("");
}
ei_math1(vp, hw_opcode, vpi, inst);
}

View file

@ -156,10 +156,10 @@ radeonTransformALU(struct radeon_compiler *c, struct rc_instruction *inst, void
case RC_OPCODE_DP2: transform_DP2(c, inst); return 1;
case RC_OPCODE_KILP: transform_KILP(c, inst); return 1;
case RC_OPCODE_RSQ: transform_RSQ(c, inst); return 1;
case RC_OPCODE_SEQ: unreachable();
case RC_OPCODE_SGE: unreachable();
case RC_OPCODE_SLT: unreachable();
case RC_OPCODE_SNE: unreachable();
case RC_OPCODE_SEQ: unreachable("");
case RC_OPCODE_SGE: unreachable("");
case RC_OPCODE_SLT: unreachable("");
case RC_OPCODE_SNE: unreachable("");
default: return 0;
}
}
@ -172,7 +172,7 @@ transform_r300_vertex_CMP(struct radeon_compiler *c, struct rc_instruction *inst
if (c->is_r500 && !rc_inst_has_three_diff_temp_srcs(inst))
return;
unreachable();
unreachable("");
}
static void

View file

@ -166,7 +166,7 @@ static void transform_texture(struct rc_instruction * dst, struct tgsi_instructi
dst->U.I.TexSrcTarget = RC_TEXTURE_2D_ARRAY;
break;
default:
unreachable();
unreachable("");
break;
}
dst->U.I.TexSwizzle = RC_SWIZZLE_XYZW;

View file

@ -70,7 +70,7 @@ static void r300_shader_read_vs_outputs(
assert(index == 0);
/* Draw does clip vertex for us. */
if (r300->screen->caps.has_tcl) {
unreachable();
unreachable("");
}
break;

View file

@ -210,7 +210,7 @@ static inline pco_func *pco_cursor_func(pco_cursor cursor)
break;
}
unreachable();
unreachable("");
}
/**
@ -238,7 +238,7 @@ static inline pco_cf_node *pco_cursor_cf_node(pco_cursor cursor)
break;
}
unreachable();
unreachable("");
}
/**
@ -274,7 +274,7 @@ static inline pco_block *pco_cursor_block(pco_cursor cursor)
break;
}
unreachable();
unreachable("");
}
/**
@ -312,7 +312,7 @@ static inline pco_instr *pco_cursor_instr(pco_cursor cursor)
break;
}
unreachable();
unreachable("");
}
/**
@ -355,7 +355,7 @@ static inline pco_igrp *pco_cursor_igrp(pco_cursor cursor)
break;
}
unreachable();
unreachable("");
}
/* Builder functions. */

View file

@ -49,7 +49,7 @@ const char *${enum.name}_str(uint64_t val) {
break;
}
unreachable();
unreachable("");
}
% endfor

View file

@ -48,7 +48,7 @@ static inline unsigned calc_da(pco_igrp *igrp)
break;
default:
unreachable();
unreachable("");
}
return da;
@ -102,7 +102,7 @@ static inline void calc_lengths(pco_igrp *igrp, unsigned *offset_bytes)
break;
default:
unreachable();
unreachable("");
}
total_length += igrp->enc.len.instrs[phase];

View file

@ -667,7 +667,7 @@ static inline unsigned pco_igrp_variant(const pco_igrp *igrp,
break;
}
unreachable();
unreachable("");
}
/* Motions. */
@ -808,7 +808,7 @@ static inline pco_block *pco_cf_node_first_block(pco_cf_node *cf_node)
break;
}
unreachable();
unreachable("");
}
/**
@ -836,7 +836,7 @@ static inline pco_block *pco_cf_node_last_block(pco_cf_node *cf_node)
break;
}
unreachable();
unreachable("");
}
static inline struct list_head *pco_parent_cf_node_body(pco_cf_node *cf_node)
@ -859,7 +859,7 @@ static inline struct list_head *pco_parent_cf_node_body(pco_cf_node *cf_node)
break;
}
unreachable();
unreachable("");
}
/**
@ -903,7 +903,7 @@ static inline pco_block *pco_next_block(pco_block *block)
break;
}
unreachable();
unreachable("");
}
/**
@ -948,7 +948,7 @@ static inline pco_block *pco_prev_block(pco_block *block)
break;
}
unreachable();
unreachable("");
}
/**
@ -1087,7 +1087,7 @@ static inline pco_instr *pco_igrp_first_instr(pco_igrp *igrp)
if (igrp->instrs[p])
return igrp->instrs[p];
unreachable();
unreachable("");
}
/**
@ -1102,7 +1102,7 @@ static inline pco_instr *pco_igrp_last_instr(pco_igrp *igrp)
if (igrp->instrs[p])
return igrp->instrs[p];
unreachable();
unreachable("");
}
/**
@ -1259,7 +1259,7 @@ static inline enum pco_bits pco_bits(unsigned bits)
break;
}
unreachable();
unreachable("");
}
/* PCO ref checkers. */
@ -1430,7 +1430,7 @@ static inline unsigned pco_ref_get_bits(pco_ref ref)
break;
}
unreachable();
unreachable("");
}
/**
@ -1461,7 +1461,7 @@ static inline uint64_t pco_ref_get_imm(pco_ref ref)
break;
}
unreachable();
unreachable("");
}
/**
@ -1578,7 +1578,7 @@ static inline enum pco_movw01 pco_ref_get_movw01(pco_ref ref)
break;
}
unreachable();
unreachable("");
}
/**

View file

@ -42,7 +42,7 @@ static unsigned ${bit_set.name}_bytes(enum ${bit_set.name}_variant variant)
default: break;
}
unreachable();
unreachable("");
}
static unsigned ${bit_set.name}_encode_field(uint8_t *bin, enum ${bit_set.name}_field field, uint64_t val)
@ -71,7 +71,7 @@ static unsigned ${bit_set.name}_encode_field(uint8_t *bin, enum ${bit_set.name}_
break;
}
unreachable();
unreachable("");
}
% for bit_struct in bit_set.bit_structs.values():

View file

@ -50,7 +50,7 @@ ${enum_map.type_to} ${enum_map.name}(${enum_map.type_from} val)
% endfor
default:
unreachable();
unreachable("");
}
}
% else:
@ -62,7 +62,7 @@ ${enum_map.type_to} ${enum_map.name}(${enum_map.type_from} val)
% endfor
default:
unreachable();
unreachable("");
}
% endif
@ -124,7 +124,7 @@ static inline unsigned pco_map_reg_index(pco_ref ref)
return pco_map_idx_bank(ref) | (ref.idx_reg.offset << 3);
}
unreachable();
unreachable("");
}
static inline unsigned pco_map_reg_index_bits(pco_ref ref)
@ -134,7 +134,7 @@ static inline unsigned pco_map_reg_index_bits(pco_ref ref)
else if (pco_ref_is_idx_reg(ref))
return 11;
unreachable();
unreachable("");
}
static inline
@ -195,7 +195,7 @@ enum pco_src_variant pco_igrp_src_variant(const pco_igrp *igrp,
}
% endfor
unreachable();
unreachable("");
}
static inline
@ -248,7 +248,7 @@ enum pco_dst_variant pco_igrp_dest_variant(pco_igrp *igrp)
}
% endfor
unreachable();
unreachable("");
}
% for encode_map in encode_maps.values():
@ -303,7 +303,7 @@ void pco_map_igrp(pco_igrp *igrp, pco_instr *instr)
info->type == PCO_OP_TYPE_PSEUDO ? "pseudo" : "hardware",
info->str);
unreachable();
unreachable("");
}
static inline unsigned pco_igrp_hdr_map_encode(uint8_t *bin, pco_igrp *igrp)
@ -360,7 +360,7 @@ static inline unsigned pco_igrp_hdr_map_encode(uint8_t *bin, pco_igrp *igrp)
break;
}
unreachable();
unreachable("");
}
% for encode_map in encode_maps.values():
@ -378,7 +378,7 @@ unsigned ${encode_map.name}_map_encode(uint8_t *bin, pco_instr *instr, unsigned
break;
}
unreachable();
unreachable("");
}
% else:
unsigned ${encode_map.name}_map_encode(uint8_t *bin, pco_instr *instr)
@ -406,7 +406,7 @@ unsigned pco_instr_map_encode(uint8_t *bin, pco_igrp *igrp, enum pco_op_phase ph
break;
}
unreachable();
unreachable("");
}
static inline
@ -462,7 +462,7 @@ unsigned pco_srcs_map_encode(uint8_t *bin, pco_igrp *igrp, bool is_upper)
break;
}
unreachable();
unreachable("");
}
static inline
@ -536,7 +536,7 @@ unsigned pco_dests_map_encode(uint8_t *bin, pco_igrp *igrp)
break;
}
unreachable();
unreachable("");
}
#endif /* PCO_MAP_H */"""

View file

@ -390,7 +390,7 @@ static void gather_data(nir_shader *nir, pco_data *data)
break;
default:
unreachable();
unreachable("");
}
}

View file

@ -162,7 +162,7 @@ static bool lower_pfo(nir_builder *b, nir_instr *instr, void *cb_data)
.io_xfb2 = nir_intrinsic_io_xfb2(intr));
util_dynarray_append(&state->stores, nir_intrinsic_instr *, store);
} else {
unreachable();
unreachable("");
}
/* Remove the old store. */

View file

@ -83,7 +83,7 @@ static nir_def *lower_vk(nir_builder *b, nir_instr *instr, void *cb_data)
break;
}
unreachable();
unreachable("");
}
/**

View file

@ -105,7 +105,7 @@ static inline bool pco_opt_prep_mods(pco_shader *shader,
break;
default:
unreachable();
unreachable("");
}
/* Source can already have the mod set. */
@ -140,7 +140,7 @@ static inline bool pco_opt_prep_mods(pco_shader *shader,
break;
default:
unreachable();
unreachable("");
}
pco_builder b = pco_builder_create(func, pco_cursor_before_instr(mod));

View file

@ -236,7 +236,7 @@ static void pco_print_ref_color(pco_print_state *state, pco_ref ref)
break;
}
unreachable();
unreachable("");
}
/**
@ -288,7 +288,7 @@ static void _pco_print_ref(pco_print_state *state, pco_ref ref)
break;
default:
unreachable();
unreachable("");
}
pco_printf(state, "%s", pco_dtype_str(ref.dtype));
break;
@ -309,7 +309,7 @@ static void _pco_print_ref(pco_print_state *state, pco_ref ref)
break;
default:
unreachable();
unreachable("");
}
unsigned chans = pco_ref_get_chans(ref);
@ -410,7 +410,7 @@ static void pco_print_instr_mods(pco_print_state *state,
break;
default:
unreachable();
unreachable("");
}
}
}
@ -474,7 +474,7 @@ static void _pco_print_instr(pco_print_state *state, pco_instr *instr)
}
default:
unreachable();
unreachable("");
}
printed = true;
} else if (!list_is_empty(&instr->phi_srcs)) {
@ -548,7 +548,7 @@ static void _pco_print_phase(pco_print_state *state,
default:
break;
}
unreachable();
unreachable("");
}
/**
@ -977,7 +977,7 @@ pco_print_func_sig(pco_print_state *state, pco_func *func, bool call)
break;
default:
unreachable();
unreachable("");
}
}
@ -1046,7 +1046,7 @@ static void _pco_print_cf_node(pco_print_state *state, pco_cf_node *cf_node)
break;
}
unreachable();
unreachable("");
}
/**
@ -1214,7 +1214,7 @@ void pco_print_cf_node_name(pco_shader *shader, pco_cf_node *cf_node)
break;
}
unreachable();
unreachable("");
}
/**

View file

@ -310,7 +310,7 @@ trans_load_input_fs(trans_ctx *tctx, nir_intrinsic_instr *intr, pco_ref dest)
break;
default:
unreachable();
unreachable("");
}
}
@ -380,7 +380,7 @@ trans_load_input_fs(trans_ctx *tctx, nir_intrinsic_instr *intr, pco_ref dest)
default:
/* Should have been previously lowered. */
unreachable();
unreachable("");
}
}
@ -556,7 +556,7 @@ static pco_instr *trans_intr(trans_ctx *tctx, nir_intrinsic_instr *intr)
printf("Unsupported intrinsic: \"");
nir_print_instr(&intr->instr, stdout);
printf("\"\n");
unreachable();
unreachable("");
break;
}
@ -741,7 +741,7 @@ trans_scmp(trans_ctx *tctx, nir_op op, pco_ref dest, pco_ref src0, pco_ref src1)
break;
default:
unreachable();
unreachable("");
}
return pco_scmp(&tctx->b, dest, src0, src1, .tst_op_main = tst_op_main);
@ -789,7 +789,7 @@ static pco_instr *trans_logical(trans_ctx *tctx,
break;
default:
unreachable();
unreachable("");
}
return pco_logical(&tctx->b, dest, src0, src1, .logiop = logiop);
@ -1000,7 +1000,7 @@ static pco_instr *trans_alu(trans_ctx *tctx, nir_alu_instr *alu)
printf("Unsupported alu instruction: \"");
nir_print_instr(&alu->instr, stdout);
printf("\"\n");
unreachable();
unreachable("");
}
if (!pco_ref_is_scalar(dest))
@ -1077,7 +1077,7 @@ static pco_instr *trans_instr(trans_ctx *tctx, nir_instr *ninstr)
break;
}
unreachable();
unreachable("");
}
/**
@ -1213,7 +1213,7 @@ static pco_block *trans_cf_nodes(trans_ctx *tctx,
}
default:
unreachable();
unreachable("");
}
cf_node->parent = parent_cf_node;

View file

@ -97,7 +97,7 @@ static void pco_assert(struct val_state *state,
break;
default:
unreachable();
unreachable("");
}
printf(" (");
@ -344,7 +344,7 @@ static inline bool ref_is_in_map(pco_ref ref, enum pco_ref_map ref_maps)
break;
default:
unreachable();
unreachable("");
}
}

View file

@ -81,7 +81,7 @@ static unsigned pvr_descriptor_size(VkDescriptorType type)
default:
mesa_loge("Unsupported descriptor type %s.\n",
vk_DescriptorType_to_str(type));
unreachable();
unreachable("");
}
}
@ -510,7 +510,7 @@ void pvr_UpdateDescriptorSets(VkDevice _device,
break;
default:
unreachable();
unreachable("");
}
}

View file

@ -1739,7 +1739,7 @@ static void pvr_alloc_vs_varyings(pco_data *data, nir_shader *nir)
break;
default:
unreachable();
unreachable("");
}
}
@ -2019,7 +2019,7 @@ pvr_preprocess_shader_data(pco_data *data,
}
default:
unreachable();
unreachable("");
}
pvr_init_descriptors(data, nir, layout);
@ -2061,7 +2061,7 @@ pvr_postprocess_shader_data(pco_data *data,
}
default:
unreachable();
unreachable("");
}
pvr_setup_descriptors(data, nir, layout);

View file

@ -430,7 +430,7 @@ vk_image_view_type_to_sampler_dim(VkImageViewType view_type)
return GLSL_SAMPLER_DIM_3D;
default:
unreachable();
unreachable("");
}
}
@ -450,7 +450,7 @@ vk_image_view_type_is_array(VkImageViewType view_type)
return false;
default:
unreachable();
unreachable("");
}
}