public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Martin Liška" <mliska@suse.cz>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Cc: Jakub Jelinek <jakub@redhat.com>
Subject: [PATCH] Initialize live_switch_vars for SWITCH_BODY == STATEMENT_LIST (PR sanitizer/80879).
Date: Fri, 26 May 2017 11:14:00 -0000	[thread overview]
Message-ID: <08849f53-06b3-ab85-d524-7d291d9ab509@suse.cz> (raw)

[-- Attachment #1: Type: text/plain, Size: 325 bytes --]

Hello.

Unfortunately I guarded use-after-scope to track live switch variables just
to BIND_EXPR. However the bind expression can be included in a STATEMENT_LIST.
That enables proper tracking and fixes the test added.

Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

Ready to be installed?
Martin

[-- Attachment #2: 0001-Initialize-live_switch_vars-for-SWITCH_BODY-STATEMEN.patch --]
[-- Type: text/x-patch, Size: 2215 bytes --]

From a7f63e228118b3f256d9e774fdeeb8c85c0da437 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Thu, 25 May 2017 17:53:06 +0200
Subject: [PATCH] Initialize live_switch_vars for SWITCH_BODY == STATEMENT_LIST
 (PR sanitizer/80879).

gcc/ChangeLog:

2017-05-25  Martin Liska  <mliska@suse.cz>

	* gimplify.c (gimplify_switch_expr):
	Initialize live_switch_vars for SWITCH_BODY == STATEMENT_LIST.

gcc/testsuite/ChangeLog:

2017-05-25  Martin Liska  <mliska@suse.cz>

	* gcc.dg/asan/use-after-scope-switch-4.c: New test.
---
 gcc/gimplify.c                                     |  3 +-
 .../gcc.dg/asan/use-after-scope-switch-4.c         | 35 ++++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/asan/use-after-scope-switch-4.c

diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 455a6993e15..0983ebef298 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -2279,7 +2279,8 @@ gimplify_switch_expr (tree *expr_p, gimple_seq *pre_p)
 
       /* Do not create live_switch_vars if SWITCH_BODY is not a BIND_EXPR.  */
       saved_live_switch_vars = gimplify_ctxp->live_switch_vars;
-      if (TREE_CODE (SWITCH_BODY (switch_expr)) == BIND_EXPR)
+      tree_code body_type = TREE_CODE (SWITCH_BODY (switch_expr));
+      if (body_type == BIND_EXPR || body_type == STATEMENT_LIST)
 	gimplify_ctxp->live_switch_vars = new hash_set<tree> (4);
       else
 	gimplify_ctxp->live_switch_vars = NULL;
diff --git a/gcc/testsuite/gcc.dg/asan/use-after-scope-switch-4.c b/gcc/testsuite/gcc.dg/asan/use-after-scope-switch-4.c
new file mode 100644
index 00000000000..290a920633b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/asan/use-after-scope-switch-4.c
@@ -0,0 +1,35 @@
+// { dg-do run }
+// { dg-additional-options "-fdump-tree-gimple" }
+
+int *ptr;
+
+struct a
+{
+  int c;
+};
+
+int main(int argc, char **argv)
+{
+  struct a e;
+  e.c = 2;
+  int x = 0;
+
+  for (;;)
+    switch (e.c)    
+      case 3:
+	{
+	  int resxxx;
+	case 2:
+	  ptr = &resxxx;
+	  *ptr = 123;
+
+	  if (x)
+	    return 0;
+	  else
+	    x = 1;
+	}
+
+  return 1;
+}
+
+/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(UNPOISON, &resxxx, \[0-9\]\\);" 2 "gimple" } }  */
-- 
2.12.2


             reply	other threads:[~2017-05-26 11:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-26 11:14 Martin Liška [this message]
2017-06-06  6:58 ` Martin Liška
2017-06-19 10:23   ` Martin Liška
2017-06-19 13:23 ` Jakub Jelinek

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=08849f53-06b3-ab85-d524-7d291d9ab509@suse.cz \
    --to=mliska@suse.cz \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    /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).