This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR82765
- From: Richard Biener <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 30 Oct 2017 15:53:18 +0100 (CET)
- Subject: [PATCH] Fix PR82765
- Authentication-results: sourceware.org; auth=none
The following fixes an ICE in constant pool hashtable functions
for overly large (__int128) array indices. The function doesn't
try to be correct in any way so simply truncate to HWI.
Bootstrapped and tested on x86_64-unknown-linux-gnu, ok?
Thanks,
Richard.
2017-10-30 Richard Biener <rguenther@suse.de>
PR middle-end/82765
* varasm.c (decode_addr_const): Make offset HOST_WIDE_INT.
Truncate ARRAY_REF index and element size.
* gcc.dg/pr82765.c: New testcase.
Index: gcc/varasm.c
===================================================================
--- gcc/varasm.c (revision 254211)
+++ gcc/varasm.c (working copy)
@@ -2879,7 +2879,7 @@ static void
decode_addr_const (tree exp, struct addr_const *value)
{
tree target = TREE_OPERAND (exp, 0);
- int offset = 0;
+ HOST_WIDE_INT offset = 0;
rtx x;
while (1)
@@ -2893,8 +2893,9 @@ decode_addr_const (tree exp, struct addr
else if (TREE_CODE (target) == ARRAY_REF
|| TREE_CODE (target) == ARRAY_RANGE_REF)
{
- offset += (tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (target)))
- * tree_to_shwi (TREE_OPERAND (target, 1)));
+ /* Truncate big offset. */
+ offset += (TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (target)))
+ * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)));
target = TREE_OPERAND (target, 0);
}
else if (TREE_CODE (target) == MEM_REF
Index: gcc/testsuite/gcc.dg/pr82765.c
===================================================================
--- gcc/testsuite/gcc.dg/pr82765.c (nonexistent)
+++ gcc/testsuite/gcc.dg/pr82765.c (working copy)
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-Os -w" } */
+
+int a[1][1];
+int main() { int *b[] = {a, a[1820408606019012862278468], a, a, a}; }