From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by sourceware.org (Postfix) with ESMTPS id DEDFC397201F for ; Wed, 2 Sep 2020 08:44:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DEDFC397201F Received: by mail-pg1-x52c.google.com with SMTP id p37so2200553pgl.3 for ; Wed, 02 Sep 2020 01:44:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=S2qYJUzP6zpnxMt0jRgcAdO/4cvJJfA7+Tf3Nw7iV+Y=; b=AePNkQgMLXnVk7OLbGgczOjWHwRe+XidCIz5HPgta7oqmX9cShZQ8EbZlq9JSshOa+ 7gChDoGEAD8pUvc89K8NNgm5jCIta3IT8NWlIgvx2DNUX9Tg2NcGQ56UPr/YJPmEZ48Y ENo9qsWUED8j/fAR78urRNYuKYufgePlCqLEKFg9IEMqbSbiMwyZOz3BwqZu2EgBs9H6 kzV5jM4o5WTSztVTk9izm2zog5rq3cZdQvj3k1prbbRrBgt5yS5+gCA6o4FtGFpR81kz gYRJUeyHNb0hCn2XbGGihKAOSakTR6g73LR0Q79heS9EcBbW4NmuttCPWTxWaAdlmdZ1 y5fg== X-Gm-Message-State: AOAM532IwU7AKvtOttevqPNhE8T5gwKTNmolnyhXxmmKelmUnJkmxur+ YM+e42s9mPaAPRUU/dJyDg9Sk/5keKY= X-Google-Smtp-Source: ABdhPJzTt3wAWMrbPLQO2DwKsaYjA/0R6VQNaexjXty9oimKU49/k069PhMDHb+lb21WooFmiPtwig== X-Received: by 2002:a63:4965:: with SMTP id y37mr1181379pgk.349.1599036259174; Wed, 02 Sep 2020 01:44:19 -0700 (PDT) Received: from bubble.grove.modra.org ([2406:3400:51d:8cc0:84c2:3a8b:c3d4:afab]) by smtp.gmail.com with ESMTPSA id r144sm5123369pfc.63.2020.09.02.01.44.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Sep 2020 01:44:18 -0700 (PDT) From: Alan Modra To: binutils@sourceware.org Subject: ubsan: v850-opc.c:412 left shift cannot be represented Date: Wed, 2 Sep 2020 18:13:02 +0930 Message-Id: <20200902084302.26786-19-amodra@gmail.com> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Sep 2020 08:44:23 -0000 include/ * opcode/v850.h (struct v850_operand ): Make param op an unsigned long. opcodes/ * v850-opc.c (insert_i5div1, insert_i5div2, insert_i5div3), (insert_d5_4, insert_d8_6, insert_d8_7, insert_v8, insert_d9), (insert_u16_loop, insert_d16_15, insert_d16_16, insert_d17_16), (insert_d22, insert_d23, insert_d23_align1, insert_i9, insert_u9), (insert_spe, insert_r4, insert_POS, insert_WIDTH, insert_SELID), (insert_VECTOR8, insert_VECTOR5, insert_CACHEOP, insert_PREFOP), (nsert_IMM10U, insert_SRSEL1, insert_SRSEL2): Use unsigned long for value parameter and update code to suit. (extract_d9, extract_d16_15, extract_d16_16, extract_d17_16), (extract_d22, extract_d23, extract_i9): Use unsigned long variables. diff --git a/include/opcode/v850.h b/include/opcode/v850.h index 214f9526ce..2ad8eaa37e 100644 --- a/include/opcode/v850.h +++ b/include/opcode/v850.h @@ -133,7 +133,7 @@ struct v850_operand operand value is legal, *ERRMSG will be unchanged (most operands can accept any value). */ unsigned long (* insert) - (unsigned long instruction, long op, const char ** errmsg); + (unsigned long instruction, unsigned long op, const char ** errmsg); /* Extraction function. This is used by the disassembler. To extract this operand type from an instruction, check this field. diff --git a/opcodes/v850-opc.c b/opcodes/v850-opc.c index 24b07fca4d..4c00ac6768 100644 --- a/opcodes/v850-opc.c +++ b/opcodes/v850-opc.c @@ -75,7 +75,7 @@ v850_msg_is_out_of_range (const char* msg) } static unsigned long -insert_i5div1 (unsigned long insn, long value, const char ** errmsg) +insert_i5div1 (unsigned long insn, unsigned long value, const char ** errmsg) { if (value > 30 || value < 2) { @@ -104,7 +104,7 @@ extract_i5div1 (unsigned long insn, int * invalid) } static unsigned long -insert_i5div2 (unsigned long insn, long value, const char ** errmsg) +insert_i5div2 (unsigned long insn, unsigned long value, const char ** errmsg) { if (value > 30 || value < 4) { @@ -133,7 +133,7 @@ extract_i5div2 (unsigned long insn, int * invalid) } static unsigned long -insert_i5div3 (unsigned long insn, long value, const char ** errmsg) +insert_i5div3 (unsigned long insn, unsigned long value, const char ** errmsg) { if (value > 32 || value < 2) { @@ -162,9 +162,9 @@ extract_i5div3 (unsigned long insn, int * invalid) } static unsigned long -insert_d5_4 (unsigned long insn, long value, const char ** errmsg) +insert_d5_4 (unsigned long insn, unsigned long value, const char ** errmsg) { - if (value > 0x1f || value < 0) + if (value > 0x1f) { if (value & 1) * errmsg = _(not_valid); @@ -192,9 +192,9 @@ extract_d5_4 (unsigned long insn, int * invalid) } static unsigned long -insert_d8_6 (unsigned long insn, long value, const char ** errmsg) +insert_d8_6 (unsigned long insn, unsigned long value, const char ** errmsg) { - if (value > 0xff || value < 0) + if (value > 0xff) { if ((value % 4) != 0) * errmsg = _(not_valid); @@ -222,9 +222,9 @@ extract_d8_6 (unsigned long insn, int * invalid) } static unsigned long -insert_d8_7 (unsigned long insn, long value, const char ** errmsg) +insert_d8_7 (unsigned long insn, unsigned long value, const char ** errmsg) { - if (value > 0xff || value < 0) + if (value > 0xff) { if ((value % 2) != 0) * errmsg = _(not_valid); @@ -252,9 +252,9 @@ extract_d8_7 (unsigned long insn, int * invalid) } static unsigned long -insert_v8 (unsigned long insn, long value, const char ** errmsg) +insert_v8 (unsigned long insn, unsigned long value, const char ** errmsg) { - if (value > 0xff || value < 0) + if (value > 0xff) * errmsg = _(immediate_out_of_range); return insn | (value & 0x1f) | ((value & 0xe0) << (27-5)); @@ -271,9 +271,9 @@ extract_v8 (unsigned long insn, int * invalid) } static unsigned long -insert_d9 (unsigned long insn, long value, const char ** errmsg) +insert_d9 (unsigned long insn, unsigned long value, const char ** errmsg) { - if (value > 0xff || value < -0x100) + if (value + 0x100 > 0x1ff) { if ((value % 2) != 0) * errmsg = branch_out_of_range_and_odd_offset; @@ -289,7 +289,7 @@ insert_d9 (unsigned long insn, long value, const char ** errmsg) static unsigned long extract_d9 (unsigned long insn, int * invalid) { - signed long ret = ((insn >> 7) & 0x1f0) | ((insn >> 3) & 0x0e); + unsigned long ret = ((insn >> 7) & 0x1f0) | ((insn >> 3) & 0x0e); ret = (ret ^ 0x100) - 0x100; @@ -299,11 +299,11 @@ extract_d9 (unsigned long insn, int * invalid) } static unsigned long -insert_u16_loop (unsigned long insn, long value, const char ** errmsg) +insert_u16_loop (unsigned long insn, unsigned long value, const char ** errmsg) { /* Loop displacement is encoded as a positive value, even though the instruction branches backwards. */ - if (value < 0 || value > 0xffff) + if (value > 0xffff) { if ((value % 2) != 0) * errmsg = branch_out_of_range_and_odd_offset; @@ -327,9 +327,9 @@ extract_u16_loop (unsigned long insn, int * invalid) } static unsigned long -insert_d16_15 (unsigned long insn, long value, const char ** errmsg) +insert_d16_15 (unsigned long insn, unsigned long value, const char ** errmsg) { - if (value > 0x7fff || value < -0x8000) + if (value + 0x8000 > 0xffff) { if ((value % 2) != 0) * errmsg = _(not_valid); @@ -345,7 +345,7 @@ insert_d16_15 (unsigned long insn, long value, const char ** errmsg) static unsigned long extract_d16_15 (unsigned long insn, int * invalid) { - signed long ret = (insn >> 16) & 0xfffe; + unsigned long ret = (insn >> 16) & 0xfffe; ret = (ret ^ 0x8000) - 0x8000; @@ -355,9 +355,9 @@ extract_d16_15 (unsigned long insn, int * invalid) } static unsigned long -insert_d16_16 (unsigned long insn, signed long value, const char ** errmsg) +insert_d16_16 (unsigned long insn, unsigned long value, const char ** errmsg) { - if (value > 0x7fff || value < -0x8000) + if (value + 0x8000 > 0xffff) * errmsg = _(out_of_range); return insn | ((value & 0xfffe) << 16) | ((value & 1) << 5); @@ -366,7 +366,7 @@ insert_d16_16 (unsigned long insn, signed long value, const char ** errmsg) static unsigned long extract_d16_16 (unsigned long insn, int * invalid) { - signed long ret = ((insn >> 16) & 0xfffe) | ((insn >> 5) & 1); + unsigned long ret = ((insn >> 16) & 0xfffe) | ((insn >> 5) & 1); ret = (ret ^ 0x8000) - 0x8000; @@ -376,9 +376,9 @@ extract_d16_16 (unsigned long insn, int * invalid) } static unsigned long -insert_d17_16 (unsigned long insn, long value, const char ** errmsg) +insert_d17_16 (unsigned long insn, unsigned long value, const char ** errmsg) { - if (value > 0xffff || value < -0x10000) + if (value + 0x10000 > 0x1ffff) * errmsg = _(out_of_range); return insn | ((value & 0xfffe) << 16) | ((value & 0x10000) >> (16 - 4)); @@ -387,19 +387,19 @@ insert_d17_16 (unsigned long insn, long value, const char ** errmsg) static unsigned long extract_d17_16 (unsigned long insn, int * invalid) { - signed long ret = ((insn >> 16) & 0xfffe) | ((insn << (16 - 4)) & 0x10000); + unsigned long ret = ((insn >> 16) & 0xfffe) | ((insn << (16 - 4)) & 0x10000); ret = (ret ^ 0x10000) - 0x10000; if (invalid != 0) *invalid = 0; - return (unsigned long)ret; + return ret; } static unsigned long -insert_d22 (unsigned long insn, long value, const char ** errmsg) +insert_d22 (unsigned long insn, unsigned long value, const char ** errmsg) { - if (value > 0x1fffff || value < -0x200000) + if (value + 0x200000 > 0x3fffff) { if ((value % 2) != 0) * errmsg = branch_out_of_range_and_odd_offset; @@ -415,28 +415,28 @@ insert_d22 (unsigned long insn, long value, const char ** errmsg) static unsigned long extract_d22 (unsigned long insn, int * invalid) { - signed long ret = ((insn >> 16) & 0xfffe) | ((insn << 16) & 0x3f0000); + unsigned long ret = ((insn >> 16) & 0xfffe) | ((insn << 16) & 0x3f0000); ret = (ret ^ 0x200000) - 0x200000; if (invalid != 0) *invalid = 0; - return (unsigned long) ret; + return ret; } static unsigned long -insert_d23 (unsigned long insn, long value, const char ** errmsg) +insert_d23 (unsigned long insn, unsigned long value, const char ** errmsg) { - if (value > 0x3fffff || value < -0x400000) + if (value + 0x400000 > 0x7fffff) * errmsg = out_of_range; return insn | ((value & 0x7f) << 4) | ((value & 0x7fff80) << (16-7)); } static unsigned long -insert_d23_align1 (unsigned long insn, long value, const char ** errmsg) +insert_d23_align1 (unsigned long insn, unsigned long value, const char ** errmsg) { - if (value > 0x3fffff || value < -0x400000) + if (value + 0x400000 > 0x7fffff) { if (value & 0x1) * errmsg = _(not_valid); @@ -452,19 +452,19 @@ insert_d23_align1 (unsigned long insn, long value, const char ** errmsg) static unsigned long extract_d23 (unsigned long insn, int * invalid) { - signed long ret = ((insn >> 4) & 0x7f) | ((insn >> (16-7)) & 0x7fff80); + unsigned long ret = ((insn >> 4) & 0x7f) | ((insn >> (16-7)) & 0x7fff80); ret = (ret ^ 0x400000) - 0x400000; if (invalid != 0) *invalid = 0; - return (unsigned long) ret; + return ret; } static unsigned long -insert_i9 (unsigned long insn, signed long value, const char ** errmsg) +insert_i9 (unsigned long insn, unsigned long value, const char ** errmsg) { - if (value > 0xff || value < -0x100) + if (value + 0x100 > 0x1ff) * errmsg = _(immediate_out_of_range); return insn | ((value & 0x1e0) << 13) | (value & 0x1f); @@ -473,7 +473,7 @@ insert_i9 (unsigned long insn, signed long value, const char ** errmsg) static unsigned long extract_i9 (unsigned long insn, int * invalid) { - signed long ret = ((insn >> 13) & 0x1e0) | (insn & 0x1f); + unsigned long ret = ((insn >> 13) & 0x1e0) | (insn & 0x1f); ret = (ret ^ 0x100) - 0x100; @@ -483,10 +483,8 @@ extract_i9 (unsigned long insn, int * invalid) } static unsigned long -insert_u9 (unsigned long insn, long v, const char ** errmsg) +insert_u9 (unsigned long insn, unsigned long value, const char ** errmsg) { - unsigned long value = (unsigned long) v; - if (value > 0x1ff) * errmsg = _(immediate_out_of_range); @@ -504,10 +502,8 @@ extract_u9 (unsigned long insn, int * invalid) } static unsigned long -insert_spe (unsigned long insn, long v, const char ** errmsg) +insert_spe (unsigned long insn, unsigned long value, const char ** errmsg) { - unsigned long value = (unsigned long) v; - if (value != 3) * errmsg = _("invalid register for stack adjustment"); @@ -524,10 +520,8 @@ extract_spe (unsigned long insn ATTRIBUTE_UNUSED, int * invalid) } static unsigned long -insert_r4 (unsigned long insn, long v, const char ** errmsg) +insert_r4 (unsigned long insn, unsigned long value, const char ** errmsg) { - unsigned long value = (unsigned long) v; - if (value >= 32) * errmsg = _("invalid register name"); @@ -552,12 +546,12 @@ extract_r4 (unsigned long insn, int * invalid) static unsigned long G_pos; static unsigned long -insert_POS (unsigned long insn, long pos, const char ** errmsg) +insert_POS (unsigned long insn, unsigned long pos, const char ** errmsg) { - if (pos > 0x1f || pos < 0) + if (pos > 0x1f) * errmsg = _(pos_out_of_range); - G_pos = (unsigned long) pos; + G_pos = pos; return insn; /* Not an oparaton until WIDTH. */ } @@ -598,17 +592,17 @@ extract_POS_L (unsigned long insn, int * invalid) } static unsigned long -insert_WIDTH (unsigned long insn, long width, const char ** errmsg) +insert_WIDTH (unsigned long insn, unsigned long width, const char ** errmsg) { unsigned long msb, lsb, opc, ret; unsigned long msb_expand, lsb_expand; - msb = (unsigned long)width + G_pos - 1; + msb = width + G_pos - 1; lsb = G_pos; opc = 0; G_pos = 0; - if (width > 0x20 || width < 0) + if (width > 0x20) * errmsg = _(width_out_of_range); if ((msb >= 16) && (lsb >= 16)) @@ -691,9 +685,9 @@ extract_WIDTH_L (unsigned long insn, int * invalid) } static unsigned long -insert_SELID (unsigned long insn, long selid, const char ** errmsg) +insert_SELID (unsigned long insn, unsigned long selid, const char ** errmsg) { - if ((unsigned long) selid > 0x1f) + if (selid > 0x1f) * errmsg = _(selid_out_of_range); return insn | ((selid & 0x1fUL) << 27); @@ -716,12 +710,12 @@ extract_SELID (unsigned long insn, int * invalid) } static unsigned long -insert_VECTOR8 (unsigned long insn, long vector8, const char ** errmsg) +insert_VECTOR8 (unsigned long insn, unsigned long vector8, const char ** errmsg) { unsigned long ret; - unsigned long VVV,vvvvv; + unsigned long VVV, vvvvv; - if (vector8 > 0xff || vector8 < 0) + if (vector8 > 0xff) * errmsg = _(vector8_out_of_range); VVV = (vector8 & 0xe0) >> 5; @@ -751,12 +745,12 @@ extract_VECTOR8 (unsigned long insn, int * invalid) } static unsigned long -insert_VECTOR5 (unsigned long insn, long vector5, const char ** errmsg) +insert_VECTOR5 (unsigned long insn, unsigned long vector5, const char ** errmsg) { unsigned long ret; unsigned long vvvvv; - if (vector5 > 0x1f || vector5 < 0) + if (vector5 > 0x1f) * errmsg = _(vector5_out_of_range); vvvvv = (vector5 & 0x1f); @@ -780,10 +774,10 @@ extract_VECTOR5 (unsigned long insn, int * invalid) } static unsigned long -insert_CACHEOP (unsigned long insn, long cacheop, const char ** errmsg ATTRIBUTE_UNUSED) +insert_CACHEOP (unsigned long insn, unsigned long cacheop, const char ** errmsg ATTRIBUTE_UNUSED) { unsigned long ret; - unsigned long pp,PPPPP; + unsigned long pp, PPPPP; pp = (cacheop & 0x60) >> 5; PPPPP = (cacheop & 0x1f); @@ -797,7 +791,7 @@ static unsigned long extract_CACHEOP (unsigned long insn, int * invalid) { unsigned long ret; - unsigned long pp,PPPPP; + unsigned long pp, PPPPP; unsigned long insn2; insn2 = insn >> 16; @@ -814,7 +808,7 @@ extract_CACHEOP (unsigned long insn, int * invalid) } static unsigned long -insert_PREFOP (unsigned long insn, long prefop, const char ** errmsg ATTRIBUTE_UNUSED) +insert_PREFOP (unsigned long insn, unsigned long prefop, const char ** errmsg ATTRIBUTE_UNUSED) { unsigned long ret; unsigned long PPPPP; @@ -846,15 +840,15 @@ extract_PREFOP (unsigned long insn, int * invalid) } static unsigned long -insert_IMM10U (unsigned long insn, long value, const char ** errmsg) +insert_IMM10U (unsigned long insn, unsigned long value, const char ** errmsg) { unsigned long imm10, ret; unsigned long iiiii,IIIII; - if (value > 0x3ff || value < 0) + if (value > 0x3ff) * errmsg = _(imm10_out_of_range); - imm10 = ((unsigned long) value) & 0x3ff; + imm10 = value & 0x3ff; IIIII = (imm10 >> 5) & 0x1f; iiiii = imm10 & 0x1f; @@ -883,15 +877,15 @@ extract_IMM10U (unsigned long insn, int * invalid) } static unsigned long -insert_SRSEL1 (unsigned long insn, long value, const char ** errmsg) +insert_SRSEL1 (unsigned long insn, unsigned long value, const char ** errmsg) { unsigned long imm10, ret; unsigned long sr,selid; - if (value > 0x3ff || value < 0) + if (value > 0x3ff) * errmsg = _(sr_selid_out_of_range); - imm10 = (unsigned long) value; + imm10 = value; selid = (imm10 & 0x3e0) >> 5; sr = imm10 & 0x1f; @@ -921,15 +915,15 @@ extract_SRSEL1 (unsigned long insn, int * invalid) } static unsigned long -insert_SRSEL2 (unsigned long insn, long value, const char ** errmsg) +insert_SRSEL2 (unsigned long insn, unsigned long value, const char ** errmsg) { unsigned long imm10, ret; unsigned long sr, selid; - if (value > 0x3ff || value < 0) + if (value > 0x3ff) * errmsg = _(sr_selid_out_of_range); - imm10 = (unsigned long) value; + imm10 = value; selid = (imm10 & 0x3e0) >> 5; sr = imm10 & 0x1f; -- Alan Modra Australia Development Lab, IBM