public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Richard Biener <rguenther@suse.de>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] Improve build_simple_mem_ref_loc (PR middle-end/83185)
Date: Wed, 29 Nov 2017 08:24:00 -0000	[thread overview]
Message-ID: <20171129081351.GU2353@tucnak> (raw)

Hi!

This PR is about forwprop propagating:
  _17 = __builtin_alloca_with_align (_16, 256);
  _18 = _17 + 32;
  __builtin___asan_alloca_poison (_18, _8);
  _7 = &*_18[4];
  __builtin_va_start (_7, 0);
to:
  _17 = __builtin_alloca_with_align (_16, 256);
  _18 = _17 + 32;
  __builtin___asan_alloca_poison (_18, _8);
  _7 = &MEM[(struct [0:D.2257][1] *)_17 + 32B][4];
  __builtin_va_start (_7, 0);
which is something the verifiers allow and then backend VA_START
handling calling build_simple_mem_ref_loc on the ADDR_EXPR it got.
get_addr_base_and_unit_offset only looks through a MEM_REF if it
has ADDR_EXPR as the first operand, which is not the case here, so nothing
sums up the 96 offset from the [4] ARRAY_REF with the extra 32 from the
MEM_REF.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

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.

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

--- gcc/tree.c.jj	2017-11-28 12:11:38.000000000 +0100
+++ gcc/tree.c	2017-11-28 17:22:01.800939050 +0100
@@ -4692,7 +4692,13 @@ build_simple_mem_ref_loc (location_t loc
     {
       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),
--- gcc/testsuite/gcc.dg/asan/pr83185.c.jj	2017-11-28 17:24:15.540329283 +0100
+++ gcc/testsuite/gcc.dg/asan/pr83185.c	2017-11-28 17:24:19.851277394 +0100
@@ -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]);
+}

	Jakub

             reply	other threads:[~2017-11-29  8:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-29  8:24 Jakub Jelinek [this message]
2017-11-29  9:47 ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171129081351.GU2353@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=rguenther@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).