Skip to content

Commit 33c29d0

Browse files
wallabraj-schultz
authored andcommitted
FIX: Replace manual traps (nullptr access) with built-in macros
Add portable unreachable macros Move unreachable macros to arch.h, add default compiler case Remove unnecessary brackets in macro Thanks @j-schultz :) Moved macros inside the include guard of arch.h Removed unnecessary unreachable.h include Original merge request: xiph/rnnoise#205 Co-authored-by: j-schultz <[email protected]> Signed-off-by: Gustavo Ramos Rehermann <[email protected]>
1 parent b823769 commit 33c29d0

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/arch.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,23 @@ static RENAMENOISE_INLINE int renamenoise_isnan(float x)
203203
#define renamenoise_stackalloc(type, id, len) type id[len]
204204
#endif
205205

206+
/*
207+
* Portable macros for denoting unreachable code.
208+
* In such a scenario, perform an early exit ('panic').
209+
*/
210+
211+
#if _MSC_VER // MSVC
212+
#define renamenoise_unreachable() __assume(0)
213+
#elif __GNUC__ || __clang__ || __MINGW32__
214+
#define renamenoise_unreachable() __builtin_unreachable()
215+
/*
216+
* Borland case is unknown.
217+
* More investigation needed.
218+
*/
219+
//--#elif __BORLANDC__
220+
//--#define renamenoise_unreachable() __builtin_unreachable()
221+
#else
222+
#define renamenoise_unreachable()
223+
#endif
224+
206225
#endif /* ARCH_H */

src/rnn.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void renamenoise_compute_dense(const ReNameNoiseDenseLayer *layer, float *output
100100
for (i=0;i<N;i++)
101101
output[i] = renamenoise_relu(output[i]);
102102
} else {
103-
*(int*)0=0;
103+
renamenoise_unreachable();
104104
}
105105
}
106106

@@ -146,7 +146,7 @@ void renamenoise_compute_gru(const ReNameNoiseGRULayer *gru, float *state, const
146146
if (gru->activation == RENAMENOISE_ACTIVATION_SIGMOID) sum = renamenoise_sigmoid_approx(RENAMENOISE_WEIGHTS_SCALE*sum);
147147
else if (gru->activation == RENAMENOISE_ACTIVATION_TANH) sum = renamenoise_tansig_approx(RENAMENOISE_WEIGHTS_SCALE*sum);
148148
else if (gru->activation == RENAMENOISE_ACTIVATION_RELU) sum = renamenoise_relu(RENAMENOISE_WEIGHTS_SCALE*sum);
149-
else *(int*)0=0;
149+
else renamenoise_unreachable();
150150
h[i] = z[i]*state[i] + (1-z[i])*sum;
151151
}
152152
for (i=0;i<N;i++)

0 commit comments

Comments
 (0)