Cast operands to uint32_t before left-shifting in build_mreg() to avoid undefined behavior when the shift result overflows int32_t. Found with UBSan.
Signed-off-by: Brian Cain <[email protected]> --- tests/tcg/hexagon/circ.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/tcg/hexagon/circ.c b/tests/tcg/hexagon/circ.c index ab949ebef1c..2a15c324242 100644 --- a/tests/tcg/hexagon/circ.c +++ b/tests/tcg/hexagon/circ.c @@ -97,9 +97,9 @@ INIT(dbuf, NDOBLS) */ static int32_t build_mreg(int32_t inc, int32_t K, int32_t len) { - return ((inc & 0x780) << 21) | - ((K & 0xf) << 24) | - ((inc & 0x7f) << 17) | + return ((uint32_t)(inc & 0x780) << 21) | + ((uint32_t)(K & 0xf) << 24) | + ((uint32_t)(inc & 0x7f) << 17) | (len & 0x1ffff); } -- 2.34.1
