From: Richard Biener Date: Thu, 2 Nov 2017 08:28:18 +0000 (+0000) Subject: re PR c/82765 (ICE at -Os on valid code on x86_64-linux-gnu: in tree_to_shwi, at... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a4d758d005722358ce73ac1b31fea68358667e83;p=gcc.git re PR c/82765 (ICE at -Os on valid code on x86_64-linux-gnu: in tree_to_shwi, at tree.c:6611) 2017-11-02 Richard Biener 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. From-SVN: r254337 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 40267c3f398..fc871f8be9f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-11-02 Richard Biener + + PR middle-end/82765 + * varasm.c (decode_addr_const): Make offset HOST_WIDE_INT. + Truncate ARRAY_REF index and element size. + 2017-11-01 Palmer Dabbelt * doc/invoke.texi (RISC-V Options): Use "@minus{}2 GB", not "-2 GB". diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8046bb17f9f..3556b869226 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-11-02 Richard Biener + + PR middle-end/82765 + * gcc.dg/pr82765.c: New testcase. + 2017-11-02 Tom de Vries * gfortran.dg/implied_do_io_1.f90: Fix scan-tree-dump-times pattern. diff --git a/gcc/testsuite/gcc.dg/pr82765.c b/gcc/testsuite/gcc.dg/pr82765.c new file mode 100644 index 00000000000..dde0aeba7ef --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr82765.c @@ -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}; } diff --git a/gcc/varasm.c b/gcc/varasm.c index 655324e23e2..1b35a99d688 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -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_const *value) 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