From 7be5f5dc43c9511ae9a8109ae4a92de29f541fc5 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 29 Oct 2022 10:37:26 +0100 Subject: [PATCH] Do not rely on behaviour of __builtin_ctz with zero argument --- src/rt/model.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rt/model.c b/src/rt/model.c index ee79d611..c3ef6e26 100644 --- a/src/rt/model.c +++ b/src/rt/model.c @@ -1091,8 +1091,10 @@ static void build_index(rt_signal_t *signal) rt_nexus_t *n = &(signal->nexus); for (int i = 0, offset = 0; i < signal->n_nexus; i++, offset += n->width, n = n->chain) { - const int tzc = __builtin_ctz(offset); - shift = MIN(shift, tzc); + if (offset > 0) { + const int tzc = __builtin_ctz(offset); + shift = MIN(shift, tzc); + } // Compute greatest common divisor for (int b = offset; b > 0;) { -- 2.39.2