mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
vkd3d: Add a macro to mark unreachable code.
This should silence warnings about some branches non returning any value without requiring additional "return 0" statement or similar. Also, in theory this might enable to compiler to optimize the program a little bit more, though that's unlikely to have any measurable effect.
This commit is contained in:
parent
56b2f56b86
commit
d5fd309ef8
Notes:
Alexandre Julliard
2022-10-18 00:13:00 +02:00
Approved-by: Zebediah Figura (@zfigura) Approved-by: Henri Verbeet (@hverbeet) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/11
@ -56,12 +56,26 @@ static inline size_t align(size_t addr, size_t alignment)
|
||||
# define VKD3D_NORETURN __attribute__((noreturn))
|
||||
# define VKD3D_PRINTF_FUNC(fmt, args) __attribute__((format(printf, fmt, args)))
|
||||
# define VKD3D_UNUSED __attribute__((unused))
|
||||
# define VKD3D_UNREACHABLE __builtin_unreachable()
|
||||
#else
|
||||
# define VKD3D_NORETURN
|
||||
# define VKD3D_PRINTF_FUNC(fmt, args)
|
||||
# define VKD3D_UNUSED
|
||||
# define VKD3D_UNREACHABLE (void)0
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
VKD3D_NORETURN static inline void vkd3d_unreachable_(const char *filename, unsigned int line)
|
||||
{
|
||||
fprintf(stderr, "%s:%u: Aborting, reached unreachable code.\n", filename, line);
|
||||
abort();
|
||||
}
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define vkd3d_unreachable() VKD3D_UNREACHABLE
|
||||
#else
|
||||
#define vkd3d_unreachable() vkd3d_unreachable_(__FILE__, __LINE__)
|
||||
#endif
|
||||
|
||||
static inline unsigned int vkd3d_popcount(unsigned int v)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
|
@ -333,13 +333,11 @@ static unsigned int traverse_path_from_component_index(struct hlsl_ctx *ctx,
|
||||
}
|
||||
index -= field_comp_count;
|
||||
}
|
||||
assert(0);
|
||||
return 0;
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
return 0;
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
@ -466,8 +464,7 @@ struct hlsl_type *hlsl_get_element_type_from_path_index(struct hlsl_ctx *ctx, co
|
||||
}
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
return NULL;
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
@ -586,8 +583,7 @@ unsigned int hlsl_type_component_count(const struct hlsl_type *type)
|
||||
return 1;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
return 0;
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1590,7 +1586,7 @@ static void dump_ir_constant(struct vkd3d_string_buffer *buffer, const struct hl
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
}
|
||||
if (type->dimx != 1)
|
||||
|
@ -701,8 +701,7 @@ static inline unsigned int hlsl_sampler_dim_count(enum hlsl_sampler_dim dim)
|
||||
case HLSL_SAMPLER_DIM_CUBEARRAY:
|
||||
return 4;
|
||||
default:
|
||||
assert(0);
|
||||
return 0;
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1086,8 +1086,7 @@ static unsigned int evaluate_array_dimension(struct hlsl_ir_node *node)
|
||||
case HLSL_TYPE_BOOL:
|
||||
return !!value->u;
|
||||
default:
|
||||
assert(0);
|
||||
return 0;
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1104,10 +1103,10 @@ static unsigned int evaluate_array_dimension(struct hlsl_ir_node *node)
|
||||
case HLSL_IR_STORE:
|
||||
WARN("Invalid node type %s.\n", hlsl_node_type_to_string(node->type));
|
||||
return 0;
|
||||
}
|
||||
|
||||
assert(0);
|
||||
return 0;
|
||||
default:
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
static bool expr_compatible_data_types(struct hlsl_type *t1, struct hlsl_type *t2)
|
||||
@ -2510,8 +2509,7 @@ static unsigned int hlsl_offset_dim_count(enum hlsl_sampler_dim dim)
|
||||
/* Offset parameters not supported for these types. */
|
||||
return 0;
|
||||
default:
|
||||
assert(0);
|
||||
return 0;
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,8 +80,7 @@ static struct hlsl_ir_node *new_offset_from_path_index(struct hlsl_ctx *ctx, str
|
||||
}
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
return NULL;
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
|
||||
if (offset)
|
||||
@ -1763,8 +1762,7 @@ static void allocate_const_registers_recurse(struct hlsl_ctx *ctx, struct hlsl_b
|
||||
return;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
return;
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
defs->values[constant->reg.id + y].f[x] = f;
|
||||
}
|
||||
@ -2149,8 +2147,7 @@ bool hlsl_component_index_range_from_deref(struct hlsl_ctx *ctx, const struct hl
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
|
||||
type = hlsl_get_element_type_from_path_index(ctx, type, path_node);
|
||||
|
@ -79,8 +79,7 @@ static bool fold_cast(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst, struct
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
return false;
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
|
||||
switch (dst->node.data_type->base_type)
|
||||
@ -104,12 +103,8 @@ static bool fold_cast(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst, struct
|
||||
|
||||
case HLSL_TYPE_BOOL:
|
||||
/* Casts to bool should have already been lowered. */
|
||||
assert(0);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
return false;
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@ -248,8 +243,7 @@ static bool fold_nequal(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst,
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
return false;
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
|
||||
dst->value[k].u *= ~0u;
|
||||
|
@ -159,8 +159,7 @@ static D3DXPARAMETER_CLASS sm1_class(const struct hlsl_type *type)
|
||||
return D3DXPC_VECTOR;
|
||||
default:
|
||||
ERR("Invalid class %#x.\n", type->type);
|
||||
assert(0);
|
||||
return 0;
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
@ -193,6 +192,7 @@ static D3DXPARAMETER_TYPE sm1_base_type(const struct hlsl_type *type)
|
||||
return D3DXPT_SAMPLER;
|
||||
default:
|
||||
ERR("Invalid dimension %#x.\n", type->sampler_dim);
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
break;
|
||||
case HLSL_TYPE_STRING:
|
||||
@ -212,6 +212,7 @@ static D3DXPARAMETER_TYPE sm1_base_type(const struct hlsl_type *type)
|
||||
return D3DXPT_TEXTURE;
|
||||
default:
|
||||
ERR("Invalid dimension %#x.\n", type->sampler_dim);
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
break;
|
||||
case HLSL_TYPE_VERTEXSHADER:
|
||||
@ -219,10 +220,8 @@ static D3DXPARAMETER_TYPE sm1_base_type(const struct hlsl_type *type)
|
||||
case HLSL_TYPE_VOID:
|
||||
return D3DXPT_VOID;
|
||||
default:
|
||||
assert(0);
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct hlsl_type *get_array_type(const struct hlsl_type *type)
|
||||
|
@ -279,8 +279,7 @@ static D3D_SHADER_VARIABLE_CLASS sm4_class(const struct hlsl_type *type)
|
||||
return D3D_SVC_VECTOR;
|
||||
default:
|
||||
ERR("Invalid class %#x.\n", type->type);
|
||||
assert(0);
|
||||
return 0;
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
@ -313,7 +312,7 @@ static D3D_SHADER_VARIABLE_TYPE sm4_base_type(const struct hlsl_type *type)
|
||||
case HLSL_SAMPLER_DIM_GENERIC:
|
||||
return D3D_SVT_SAMPLER;
|
||||
default:
|
||||
assert(0);
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
break;
|
||||
case HLSL_TYPE_STRING:
|
||||
@ -332,7 +331,7 @@ static D3D_SHADER_VARIABLE_TYPE sm4_base_type(const struct hlsl_type *type)
|
||||
case HLSL_SAMPLER_DIM_GENERIC:
|
||||
return D3D_SVT_TEXTURE;
|
||||
default:
|
||||
assert(0);
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
break;
|
||||
case HLSL_TYPE_UINT:
|
||||
@ -342,10 +341,8 @@ static D3D_SHADER_VARIABLE_TYPE sm4_base_type(const struct hlsl_type *type)
|
||||
case HLSL_TYPE_VOID:
|
||||
return D3D_SVT_VOID;
|
||||
default:
|
||||
assert(0);
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void write_sm4_type(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer, struct hlsl_type *type)
|
||||
@ -414,8 +411,7 @@ static D3D_SHADER_INPUT_TYPE sm4_resource_type(const struct hlsl_type *type)
|
||||
case HLSL_TYPE_TEXTURE:
|
||||
return D3D_SIT_TEXTURE;
|
||||
default:
|
||||
assert(0);
|
||||
return 0;
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
@ -439,8 +435,7 @@ static D3D_RESOURCE_RETURN_TYPE sm4_resource_format(const struct hlsl_type *type
|
||||
return D3D_RETURN_TYPE_UINT;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
return 0;
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
@ -467,8 +462,7 @@ static D3D_SRV_DIMENSION sm4_rdef_resource_dimension(const struct hlsl_type *typ
|
||||
case HLSL_SAMPLER_DIM_CUBEARRAY:
|
||||
return D3D_SRV_DIMENSION_TEXTURECUBEARRAY;
|
||||
default:
|
||||
assert(0);
|
||||
return D3D_SRV_DIMENSION_UNKNOWN;
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
@ -764,8 +758,7 @@ static enum vkd3d_sm4_resource_type sm4_resource_dimension(const struct hlsl_typ
|
||||
case HLSL_SAMPLER_DIM_CUBEARRAY:
|
||||
return VKD3D_SM4_RESOURCE_TEXTURE_CUBEARRAY;
|
||||
default:
|
||||
assert(0);
|
||||
return 0;
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
@ -800,8 +793,7 @@ static uint32_t sm4_encode_instruction_modifier(const struct sm4_instruction_mod
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
|
||||
return word;
|
||||
@ -1528,7 +1520,7 @@ static void write_sm4_cast(struct hlsl_ctx *ctx,
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
break;
|
||||
|
||||
@ -1554,7 +1546,7 @@ static void write_sm4_cast(struct hlsl_ctx *ctx,
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
break;
|
||||
|
||||
@ -1580,7 +1572,7 @@ static void write_sm4_cast(struct hlsl_ctx *ctx,
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
break;
|
||||
|
||||
@ -1594,11 +1586,8 @@ static void write_sm4_cast(struct hlsl_ctx *ctx,
|
||||
|
||||
case HLSL_TYPE_BOOL:
|
||||
/* Casts to bool should have already been lowered. */
|
||||
assert(0);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1754,11 +1743,8 @@ static void write_sm4_expr(struct hlsl_ctx *ctx,
|
||||
break;
|
||||
|
||||
case 1:
|
||||
assert(0);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -1314,7 +1314,7 @@ int vkd3d_shader_compile(const struct vkd3d_shader_compile_info *compile_info,
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
|
||||
vkd3d_shader_message_context_trace_messages(&message_context);
|
||||
|
@ -183,8 +183,7 @@ static D3DTEXTUREADDRESS sampler_address_to_d3d9(D3D12_TEXTURE_ADDRESS_MODE addr
|
||||
return D3DTADDRESS_MIRRORONCE;
|
||||
}
|
||||
|
||||
assert(0);
|
||||
return 0;
|
||||
vkd3d_unreachable();
|
||||
}
|
||||
|
||||
static bool d3d9_runner_check_requirements(struct shader_runner *r)
|
||||
@ -369,8 +368,7 @@ static bool d3d9_runner_draw(struct shader_runner *r,
|
||||
break;
|
||||
|
||||
case RESOURCE_TYPE_UAV:
|
||||
assert(0);
|
||||
break;
|
||||
vkd3d_unreachable();
|
||||
|
||||
case RESOURCE_TYPE_VERTEX_BUFFER:
|
||||
for (j = 0; j < runner->r.input_element_count; ++j)
|
||||
|
Loading…
Reference in New Issue
Block a user