TsundereStation/src
LibretroAdmin b12fb4b291 common: remove ConvertToBoolUnchecked, replace with static_cast<bool>
ConvertToBoolUnchecked was a thin template that did a memcpy of the
low byte of its integer argument into a bool, deliberately bypassing
the standard 'nonzero -> true' conversion. The 'Unchecked' meant: if
your value's low byte happens to be 0 but a higher byte is set (e.g.
0x100), the result is false rather than true. The bool storage is
also left with whatever bit pattern the source's low byte had, which
pre-C++17 was technically a trap representation; only C++17+ made
non-{0,1} bool storage well-defined (any nonzero -> true).

In practice every one of the 46 callsites passed a value already
guaranteed to be in {0, 1}:

 - Bit-masked-to-LSB:  x & 1, value & 0x01, (reg >> i) & u32(1)
   11 sites in cdrom.cpp, gpu.cpp (3 sites), dma.h (2), spu.h (3),
   cpu_core.cpp, cpu_recompiler_code_generator.cpp.

 - Loop variable in {0, 1}: u8 textured/dithering/interlacing/
   wrapped/interlaced/depth_24bit from 'for (u8 v = 0; v < 2; v++)'.
   35 sites across gpu_hw_d3d11.cpp, gpu_hw_d3d12.cpp,
   gpu_hw_vulkan.cpp, gpu_hw_opengl.cpp.

For every caller, the result is the same as static_cast<bool>(x):
0 maps to false, nonzero maps to true. Equivalence verified with a
test harness covering {0, 1, 2, 3, 0x100, 0xFFFFFFFF} masked by 1
and u8 values {0, 1} - all 8 cases produce identical results, and
g++ -O2 inlines both forms to the same comparison-with-zero
sequence (the template was never doing a real memcpy at runtime).

Mechanical rewrite:

  ConvertToBoolUnchecked(EXPR)  ->  static_cast<bool>(EXPR)

then the helper is removed from common/types.h. The <cstring>
include in types.h stays - 40+ files in src/ rely on it being
transitively included; removing it is a separate sweep.

The 'Unchecked' semantics were never actually used. Any value
with low_byte=0 but other bytes set, or anything that would have
hit the pre-C++17 trap representation, would have been a latent
bug at the callsite. After this change such inputs would simply
read as true, matching what the surrounding code already assumes.

Build verification:
  Makefile.libretro platform=unix: clean (post-fold), zero warnings
  -Wconversion delta on the touched files: zero new warnings
  d3d11/d3d12 sites verified by code review (Linux toolchain cannot
  build them; the changes are all simple ConvertToBoolUnchecked(v)
  -> static_cast<bool>(v) substitutions on u8 loop variables, no
  expression rewriting)
2026-05-14 06:01:14 +02:00
..
common common: remove ConvertToBoolUnchecked, replace with static_cast<bool> 2026-05-14 06:01:14 +02:00
core common: remove ConvertToBoolUnchecked, replace with static_cast<bool> 2026-05-14 06:01:14 +02:00
libretro gpu_hw_d3d11: introduce three-mode shader precompile core option 2026-05-11 17:25:43 +02:00
CMakeLists.txt only #include <malloc.h> if it exists 2024-07-07 23:17:16 +00:00
config.h.cmake only #include <malloc.h> if it exists 2024-07-07 23:17:16 +00:00