Cleanup: use assume attribute to quiet array bounds warning for GCC 15
Ref !146150
This commit is contained in:
@@ -259,18 +259,42 @@ static bool values_different(const T value1,
|
||||
if constexpr (std::is_same_v<T, float>) {
|
||||
return compare_threshold_relative(value1, value2, threshold);
|
||||
}
|
||||
if constexpr (is_same_any_v<T, float2, float3, ColorGeometry4f>) {
|
||||
|
||||
/* GCC 15.x triggers an array-bounds warning unless `component_i` is assumed to be in range. */
|
||||
#if (defined(__GNUC__) && (__GNUC__ >= 15) && !defined(__clang__))
|
||||
# define ASSERT_AND_ASSUME(expr) \
|
||||
BLI_assert(expr); \
|
||||
[[assume(expr)]];
|
||||
#else
|
||||
# define ASSERT_AND_ASSUME(expr) BLI_assert(expr);
|
||||
#endif
|
||||
|
||||
if constexpr (is_same_any_v<T, float2>) {
|
||||
ASSERT_AND_ASSUME(component_i >= 0 && component_i < 2);
|
||||
return compare_threshold_relative(value1[component_i], value2[component_i], threshold);
|
||||
}
|
||||
if constexpr (is_same_any_v<T, float3>) {
|
||||
ASSERT_AND_ASSUME(component_i >= 0 && component_i < 3);
|
||||
return compare_threshold_relative(value1[component_i], value2[component_i], threshold);
|
||||
}
|
||||
if constexpr (is_same_any_v<T, ColorGeometry4f>) {
|
||||
ASSERT_AND_ASSUME(component_i >= 0 && component_i < 4);
|
||||
return compare_threshold_relative(value1[component_i], value2[component_i], threshold);
|
||||
}
|
||||
if constexpr (std::is_same_v<T, math::Quaternion>) {
|
||||
ASSERT_AND_ASSUME(component_i >= 0 && component_i < 4);
|
||||
const float4 value1_f = float4(value1);
|
||||
const float4 value2_f = float4(value2);
|
||||
return compare_threshold_relative(value1_f[component_i], value2_f[component_i], threshold);
|
||||
}
|
||||
if constexpr (std::is_same_v<T, float4x4>) {
|
||||
ASSERT_AND_ASSUME(component_i >= 0 && component_i < 4);
|
||||
return compare_threshold_relative(
|
||||
value1.base_ptr()[component_i], value2.base_ptr()[component_i], threshold);
|
||||
}
|
||||
|
||||
#undef ASSERT_AND_ASSUME
|
||||
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
|
||||
|
||||
@@ -162,6 +162,11 @@ BLI_INLINE void bicubic_interpolation(const T *src_buffer,
|
||||
BLI_assert(src_buffer && output);
|
||||
BLI_assert(components > 0 && components <= 4);
|
||||
|
||||
/* GCC 15.x can't reliably detect that `components` is never over 4. */
|
||||
#if (defined(__GNUC__) && (__GNUC__ >= 15) && !defined(__clang__))
|
||||
[[assume(components <= 4)]];
|
||||
#endif
|
||||
|
||||
#if BLI_HAVE_SSE4
|
||||
if constexpr (std::is_same_v<T, uchar>) {
|
||||
if (components == 4 && wrap_u == InterpWrapMode::Extend && wrap_v == InterpWrapMode::Extend) {
|
||||
|
||||
@@ -139,6 +139,11 @@ blender::gpu::Batch *LookdevModule::sphere_get(const SphereLOD level_of_detail)
|
||||
{
|
||||
BLI_assert(level_of_detail >= SphereLOD::LOW && level_of_detail < SphereLOD::MAX);
|
||||
|
||||
/* GCC 15.x triggers an array-bounds warning without this. */
|
||||
#if (defined(__GNUC__) && (__GNUC__ >= 15) && !defined(__clang__))
|
||||
[[assume((level_of_detail >= 0) && (level_of_detail < SphereLOD::MAX))]];
|
||||
#endif
|
||||
|
||||
if (sphere_lod_[level_of_detail] != nullptr) {
|
||||
return sphere_lod_[level_of_detail];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user