re PR middle-end/83185 (ICE with -fsanitize=address in build_simple_mem_ref_loc,...
authorJakub Jelinek <jakub@redhat.com>
Wed, 29 Nov 2017 10:33:06 +0000 (11:33 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 29 Nov 2017 10:33:06 +0000 (11:33 +0100)
PR middle-end/83185
* tree.c (build_simple_mem_ref_loc): Handle
get_addr_base_and_unit_offset returning a MEM_REF.

* gcc.dg/asan/pr83185.c: New test.

From-SVN: r255229

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/asan/pr83185.c [new file with mode: 0644]
gcc/tree.c

index 483c02aa501c1b3ef477fff9136e6dfc5cc9f260..51d7009b6eac9c3d3e9b7b2da0228c56d9911b33 100644 (file)
@@ -1,5 +1,9 @@
 2017-11-29  Jakub Jelinek  <jakub@redhat.com>
 
+       PR middle-end/83185
+       * tree.c (build_simple_mem_ref_loc): Handle
+       get_addr_base_and_unit_offset returning a MEM_REF.
+
        PR middle-end/80929
        * rtlanal.c (seq_cost): For non-single_set insns try to use insn_cost.
 
index b8bd264dd337c4bd37ecbe4d60acb77942d8fa34..dbe90640f6b7d706ee0e0af72c962f3512f62869 100644 (file)
@@ -1,5 +1,8 @@
 2017-11-29  Jakub Jelinek  <jakub@redhat.com>
 
+       PR middle-end/83185
+       * gcc.dg/asan/pr83185.c: New test.
+
        PR target/80819
        * gcc.target/i386/pr80819-1.c: New test.
        * gcc.target/i386/pr80819-2.c: New test.
diff --git a/gcc/testsuite/gcc.dg/asan/pr83185.c b/gcc/testsuite/gcc.dg/asan/pr83185.c
new file mode 100644 (file)
index 0000000..175d2ce
--- /dev/null
@@ -0,0 +1,14 @@
+/* PR middle-end/83185 */
+/* { dg-do compile } */
+
+#include <stdarg.h>
+
+int bar (void);
+
+void
+foo (int i, ...)
+{
+  va_list aps[bar()];
+  va_start (aps[4], i);
+  va_end (aps[4]);
+}
index e97654cd0f1adc97d3287e83112ba9aa945a5d1c..b3902479c320173f4bc008645ae4681494a8a939 100644 (file)
@@ -4692,7 +4692,13 @@ build_simple_mem_ref_loc (location_t loc, tree ptr)
     {
       ptr = get_addr_base_and_unit_offset (TREE_OPERAND (ptr, 0), &offset);
       gcc_assert (ptr);
-      ptr = build_fold_addr_expr (ptr);
+      if (TREE_CODE (ptr) == MEM_REF)
+       {
+         offset += mem_ref_offset (ptr).to_short_addr ();
+         ptr = TREE_OPERAND (ptr, 0);
+       }
+      else
+       ptr = build_fold_addr_expr (ptr);
       gcc_assert (is_gimple_reg (ptr) || is_gimple_min_invariant (ptr));
     }
   tem = build2 (MEM_REF, TREE_TYPE (ptype),