• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Revision29298bf66f62f2f6c1efb0685623fbc29dfade90 (tree)
Time2019-12-17 21:28:19
AuthorAlan Modra <amodra@gmai...>
CommiterAlan Modra

Log Message

ubsan: aarch64: left shift cannot be represented in type 'int64_t'

* aarch64-opc.c (value_fit_signed_field_p): Avoid signed overflow.
(value_fit_unsigned_field_p): Likewise.
(aarch64_wide_constant_p): Likewise.
(operand_general_constraint_met_p): Likewise.
* aarch64-opc.h (aarch64_wide_constant_p): Update prototype.

Change Summary

Incremental Difference

--- a/opcodes/ChangeLog
+++ b/opcodes/ChangeLog
@@ -1,5 +1,13 @@
11 2019-12-17 Alan Modra <amodra@gmail.com>
22
3+ * aarch64-opc.c (value_fit_signed_field_p): Avoid signed overflow.
4+ (value_fit_unsigned_field_p): Likewise.
5+ (aarch64_wide_constant_p): Likewise.
6+ (operand_general_constraint_met_p): Likewise.
7+ * aarch64-opc.h (aarch64_wide_constant_p): Update prototype.
8+
9+2019-12-17 Alan Modra <amodra@gmail.com>
10+
311 * nds32-dis.c (nds32_mask_opcode): Avoid signed overflow.
412 (print_insn_nds32): Use uint64_t for "given" and "given1".
513
--- a/opcodes/aarch64-opc.c
+++ b/opcodes/aarch64-opc.c
@@ -546,7 +546,7 @@ value_fit_signed_field_p (int64_t value, unsigned width)
546546 assert (width < 32);
547547 if (width < sizeof (value) * 8)
548548 {
549- int64_t lim = (int64_t)1 << (width - 1);
549+ int64_t lim = (uint64_t) 1 << (width - 1);
550550 if (value >= -lim && value < lim)
551551 return 1;
552552 }
@@ -560,7 +560,7 @@ value_fit_unsigned_field_p (int64_t value, unsigned width)
560560 assert (width < 32);
561561 if (width < sizeof (value) * 8)
562562 {
563- int64_t lim = (int64_t)1 << width;
563+ int64_t lim = (uint64_t) 1 << width;
564564 if (value >= 0 && value < lim)
565565 return 1;
566566 }
@@ -1063,7 +1063,7 @@ match_operands_qualifier (aarch64_inst *inst, bfd_boolean update_p)
10631063 amount will be returned in *SHIFT_AMOUNT. */
10641064
10651065 bfd_boolean
1066-aarch64_wide_constant_p (int64_t value, int is32, unsigned int *shift_amount)
1066+aarch64_wide_constant_p (uint64_t value, int is32, unsigned int *shift_amount)
10671067 {
10681068 int amount;
10691069
@@ -1074,22 +1074,21 @@ aarch64_wide_constant_p (int64_t value, int is32, unsigned int *shift_amount)
10741074 /* Allow all zeros or all ones in top 32-bits, so that
10751075 32-bit constant expressions like ~0x80000000 are
10761076 permitted. */
1077- uint64_t ext = value;
1078- if (ext >> 32 != 0 && ext >> 32 != (uint64_t) 0xffffffff)
1077+ if (value >> 32 != 0 && value >> 32 != 0xffffffff)
10791078 /* Immediate out of range. */
10801079 return FALSE;
1081- value &= (int64_t) 0xffffffff;
1080+ value &= 0xffffffff;
10821081 }
10831082
10841083 /* first, try movz then movn */
10851084 amount = -1;
1086- if ((value & ((int64_t) 0xffff << 0)) == value)
1085+ if ((value & ((uint64_t) 0xffff << 0)) == value)
10871086 amount = 0;
1088- else if ((value & ((int64_t) 0xffff << 16)) == value)
1087+ else if ((value & ((uint64_t) 0xffff << 16)) == value)
10891088 amount = 16;
1090- else if (!is32 && (value & ((int64_t) 0xffff << 32)) == value)
1089+ else if (!is32 && (value & ((uint64_t) 0xffff << 32)) == value)
10911090 amount = 32;
1092- else if (!is32 && (value & ((int64_t) 0xffff << 48)) == value)
1091+ else if (!is32 && (value & ((uint64_t) 0xffff << 48)) == value)
10931092 amount = 48;
10941093
10951094 if (amount == -1)
@@ -1535,7 +1534,7 @@ operand_general_constraint_met_p (const aarch64_opnd_info *opnds, int idx,
15351534 : _("z0-z7 expected"));
15361535 return 0;
15371536 }
1538- mask = (1 << (size - shift)) - 1;
1537+ mask = (1u << (size - shift)) - 1;
15391538 if (!value_in_range_p (opnd->reglane.index, 0, mask))
15401539 {
15411540 set_elem_idx_out_of_range_error (mismatch_detail, idx, 0, mask);
@@ -2161,7 +2160,7 @@ operand_general_constraint_met_p (const aarch64_opnd_info *opnds, int idx,
21612160 if (!value_fit_unsigned_field_p (opnd->imm.value, size))
21622161 {
21632162 set_imm_out_of_range_error (mismatch_detail, idx, 0,
2164- (1 << size) - 1);
2163+ (1u << size) - 1);
21652164 return 0;
21662165 }
21672166 break;
--- a/opcodes/aarch64-opc.h
+++ b/opcodes/aarch64-opc.h
@@ -485,7 +485,7 @@ enum aarch64_modifier_kind
485485 aarch64_get_operand_modifier_from_value (aarch64_insn, bfd_boolean);
486486
487487
488-bfd_boolean aarch64_wide_constant_p (int64_t, int, unsigned int *);
488+bfd_boolean aarch64_wide_constant_p (uint64_t, int, unsigned int *);
489489 bfd_boolean aarch64_logical_immediate_p (uint64_t, int, aarch64_insn *);
490490 int aarch64_shrink_expanded_imm8 (uint64_t);
491491