Skip to content

Commit aafc732

Browse files
committed
Silence "may be used uninitialized" GCC warning
Helps gcc silence the warning about ``` warning: 'added' may be used uninitialized [-Wmaybe-uninitialized] const IndexType offsetA0 = TransformedFeatureDimensions * added[0]; ``` closes #5950 No functional change
1 parent 4a869f4 commit aafc732

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/nnue/nnue_accumulator.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,25 @@
2525
#include "../bitboard.h"
2626
#include "../position.h"
2727
#include "../types.h"
28-
#include "nnue_architecture.h"
2928
#include "network.h"
29+
#include "nnue_architecture.h"
3030
#include "nnue_common.h"
3131
#include "nnue_feature_transformer.h"
3232

3333
namespace Stockfish::Eval::NNUE {
3434

35+
#if defined(__GNUC__) && !defined(__clang__)
36+
#define sf_assume(cond) \
37+
do \
38+
{ \
39+
if (!(cond)) \
40+
__builtin_unreachable(); \
41+
} while (0)
42+
#else
43+
// do nothing for other compilers
44+
#define sf_assume(cond)
45+
#endif
46+
3547
namespace {
3648

3749
template<Color Perspective,
@@ -245,6 +257,12 @@ void update_accumulator_incremental(
245257
else
246258
assert(removed.size() <= added.size());
247259

260+
// Workaround compiler warning for uninitialized variables, replicated on
261+
// profile builds on windows with gcc 14.2.0.
262+
// TODO remove once unneeded
263+
sf_assume(added.size() == 1 || added.size() == 2);
264+
sf_assume(removed.size() == 1 || removed.size() == 2);
265+
248266
#ifdef VECTOR
249267
auto* accIn =
250268
reinterpret_cast<const vec_t*>(&(computed.*accPtr).accumulation[Perspective][0]);

0 commit comments

Comments
 (0)