Commit 11c0bcd29b for qemu.org
commit 11c0bcd29b4b8165a87efa7bc9e40f1975f39aaf
Author: Brian Cain <brian.cain@oss.qualcomm.com>
Date: Tue Sep 15 09:30:32 2026 -0700
tests/tcg/hexagon: fix undefined signed left shift in brev.c
Cast to uint32_t before left-shifting in sext8() to avoid undefined
behavior when shifting a negative value. The subsequent arithmetic
right shift on the int32_t cast correctly sign-extends the result.
Found with UBSan.
Reviewed-by: Sid Manning <sid.manning@oss.qualcomm.com>
Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
diff --git a/tests/tcg/hexagon/brev.c b/tests/tcg/hexagon/brev.c
index 6c7b134084..1473e309ee 100644
--- a/tests/tcg/hexagon/brev.c
+++ b/tests/tcg/hexagon/brev.c
@@ -106,7 +106,7 @@ uint32_t bitreverse(uint32_t x)
int32_t sext8(int32_t x)
{
- return (x << 24) >> 24;
+ return (int32_t)((uint32_t)x << 24) >> 24;
}
#define TEST_BREV_LOAD(SZ, TYPE, BUF, SHIFT, EXP) \