From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 118717 invoked by alias); 11 Dec 2019 07:38:48 -0000 Mailing-List: contact gdb-testers-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-testers-owner@sourceware.org Received: (qmail 118708 invoked by uid 89); 11 Dec 2019 07:38:48 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.1 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: kwanyin.sergiodj.net Received: from kwanyin.sergiodj.net (HELO kwanyin.sergiodj.net) (158.69.185.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Dec 2019 07:38:46 +0000 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [binutils-gdb] ubsan: cr16: left shift cannot be represented in type 'int' From: gdb-buildbot@sergiodj.net To: gdb-testers@sourceware.org Message-Id: <0ef562a4b5da6bc1f16b2ea801b228acafd033d8@gdb-build> Date: Wed, 11 Dec 2019 07:38:00 -0000 X-SW-Source: 2019-q4/txt/msg04344.txt.bz2 *** TEST RESULTS FOR COMMIT 0ef562a4b5da6bc1f16b2ea801b228acafd033d8 *** commit 0ef562a4b5da6bc1f16b2ea801b228acafd033d8 Author: Alan Modra AuthorDate: Tue Dec 10 23:02:37 2019 +1030 Commit: Alan Modra CommitDate: Wed Dec 11 11:38:04 2019 +1030 ubsan: cr16: left shift cannot be represented in type 'int' This was: unsigned long mask = SBM (instruction->match_bits); with #define SBM(offs) ((((1 << (32 - offs)) -1) << (offs))) Well, there are a couple of problems. Firstly, the expression uses int values (1 rather than 1u or 1ul) resulting in the ubsan error, and secondly, a zero offs will result in a 32-bit shift which is undefined if ints are only 32 bits. * cr16-dis.c (EXTRACT, SBM): Rewrite. (cr16_match_opcode): Delete duplicate bcond test. diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog index faa160a37b..57212f843b 100644 --- a/opcodes/ChangeLog +++ b/opcodes/ChangeLog @@ -1,3 +1,8 @@ +2019-12-11 Alan Modra + + * cr16-dis.c (EXTRACT, SBM): Rewrite. + (cr16_match_opcode): Delete duplicate bcond test. + 2019-12-11 Alan Modra * bfin-dis.c (HOST_LONG_WORD_SIZE, XFIELD): Delete. diff --git a/opcodes/cr16-dis.c b/opcodes/cr16-dis.c index 65cf91cfed..68fbe42a65 100644 --- a/opcodes/cr16-dis.c +++ b/opcodes/cr16-dis.c @@ -30,11 +30,11 @@ /* Extract 'n_bits' from 'a' starting from offset 'offs'. */ #define EXTRACT(a, offs, n_bits) \ - (n_bits == 32 ? (((a) >> (offs)) & 0xffffffffL) \ - : (((a) >> (offs)) & ((1 << (n_bits)) -1))) + (((a) >> (offs)) & ((1ul << ((n_bits) - 1) << 1) - 1)) -/* Set Bit Mask - a mask to set all bits starting from offset 'offs'. */ -#define SBM(offs) ((((1 << (32 - offs)) -1) << (offs))) +/* Set Bit Mask - a mask to set all bits in a 32-bit word starting + from offset 'offs'. */ +#define SBM(offs) ((1ul << 31 << 1) - (1ul << (offs))) typedef struct { @@ -329,9 +329,6 @@ cr16_match_opcode (void) while (instruction >= cr16_instruction) { mask = build_mask (); - /* Adjust mask for bcond with 32-bit size instruction */ - if ((IS_INSN_MNEMONIC("b") && instruction->size == 2)) - mask = 0xff0f0000; if ((doubleWord & mask) == BIN (instruction->match, instruction->match_bits))