From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40022) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WPwFn-0006BD-Tp for qemu-devel@nongnu.org; Tue, 18 Mar 2014 11:48:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WPwFj-0004pH-2p for qemu-devel@nongnu.org; Tue, 18 Mar 2014 11:48:35 -0400 Received: from mail-pd0-x22a.google.com ([2607:f8b0:400e:c02::22a]:34215) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WPwFi-0004ou-Rr for qemu-devel@nongnu.org; Tue, 18 Mar 2014 11:48:31 -0400 Received: by mail-pd0-f170.google.com with SMTP id v10so7332418pde.1 for ; Tue, 18 Mar 2014 08:48:30 -0700 (PDT) Sender: Richard Henderson From: Richard Henderson Date: Tue, 18 Mar 2014 08:48:20 -0700 Message-Id: <1395157702-23108-2-git-send-email-rth@twiddle.net> In-Reply-To: <1395157702-23108-1-git-send-email-rth@twiddle.net> References: <1395157702-23108-1-git-send-email-rth@twiddle.net> Subject: [Qemu-devel] [PATCH 1/3] tcg: Mask shift quantities while folding List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org The TCG result would be undefined, but we can at least produce one plausible result and avoid triggering the wrath of analysis tools. Reported-by: Peter Maydell Signed-off-by: Richard Henderson --- tcg/optimize.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tcg/optimize.c b/tcg/optimize.c index 7777743..2fc6344 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -220,34 +220,34 @@ static TCGArg do_constant_folding_2(TCGOpcode op, TCGArg x, TCGArg y) return x ^ y; case INDEX_op_shl_i32: - return (uint32_t)x << (uint32_t)y; + return (uint32_t)x << (y & 31); case INDEX_op_shl_i64: - return (uint64_t)x << (uint64_t)y; + return (uint64_t)x << (y & 63); case INDEX_op_shr_i32: - return (uint32_t)x >> (uint32_t)y; + return (uint32_t)x >> (y & 31); case INDEX_op_shr_i64: - return (uint64_t)x >> (uint64_t)y; + return (uint64_t)x >> (y & 63); case INDEX_op_sar_i32: - return (int32_t)x >> (int32_t)y; + return (int32_t)x >> (y & 31); case INDEX_op_sar_i64: - return (int64_t)x >> (int64_t)y; + return (int64_t)x >> (y & 63); case INDEX_op_rotr_i32: - return ror32(x, y); + return ror32(x, y & 31); case INDEX_op_rotr_i64: - return ror64(x, y); + return ror64(x, y & 63); case INDEX_op_rotl_i32: - return rol32(x, y); + return rol32(x, y & 31); case INDEX_op_rotl_i64: - return rol64(x, y); + return rol64(x, y & 63); CASE_OP_32_64(not): return ~x; -- 1.8.5.3