Patchwork [07/10] Make build_check_stmt accept an SSA_NAME for its base

login
register
mail settings
Submitter Dodji Seketeli
Date Nov. 2, 2012, 11:02 p.m.
Message ID <87sj8r7gms.fsf_-_@redhat.com>
Download mbox | patch
Permalink /patch/196769/
State New
Headers show

Comments

Dodji Seketeli - Nov. 2, 2012, 11:02 p.m.
This patch makes build_check_stmt accept its memory access parameter
to be an SSA name.  This is useful for a subsequent patch that will
re-use.

Tested by running cc1 -fasan on the program below with and without the
patch and inspecting the gimple output to see that there is no change.

void
foo ()
{
  char foo[1] = {0};

  foo[0] = 1;
}

gcc/
	* asan.c (build_check_stmt): Accept the memory access to be
	represented by an SSA_NAME.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/asan@192843 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog.asan |  5 +++++
 gcc/asan.c         | 36 +++++++++++++++++++++++-------------
 2 files changed, 28 insertions(+), 13 deletions(-)
Diego Novillo - Nov. 6, 2012, 5:28 p.m.
On 2012-11-02 16:02 , Dodji Seketeli wrote:

> 	* asan.c (build_check_stmt): Accept the memory access to be
> 	represented by an SSA_NAME.

OK.


Diego.

Patch

diff --git a/gcc/ChangeLog.asan b/gcc/ChangeLog.asan
index a2e18ce..395ba4f 100644
--- a/gcc/ChangeLog.asan
+++ b/gcc/ChangeLog.asan
@@ -1,3 +1,8 @@ 
+2012-10-26  Dodji Seketeli  <dodji@redhat.com>
+
+	* asan.c (build_check_stmt): Accept the memory access to be
+	represented by an SSA_NAME.
+
 2012-10-17  Jakub Jelinek  <jakub@redhat.com>
 	    Wei Mi <wmi@google.com>
 
diff --git a/gcc/asan.c b/gcc/asan.c
index 6880270..7c99173 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -383,16 +383,18 @@  asan_init_func (void)
 #define PROB_VERY_UNLIKELY	(REG_BR_PROB_BASE / 2000 - 1)
 #define PROB_ALWAYS		(REG_BR_PROB_BASE)
 
-/* Instrument the memory access instruction BASE.
-   Insert new statements before ITER.
-   LOCATION is source code location.
-   IS_STORE is either 1 (for a store) or 0 (for a load).
+/* Instrument the memory access instruction BASE.  Insert new
+   statements before ITER.
+
+   Note that the memory access represented by BASE can be either an
+   SSA_NAME, or a non-SSA expression.  LOCATION is the source code
+   location.  IS_STORE is TRUE for a store, FALSE for a load.
    SIZE_IN_BYTES is one of 1, 2, 4, 8, 16.  */
 
 static void
-build_check_stmt (tree base,
-                  gimple_stmt_iterator *iter,
-                  location_t location, bool is_store, int size_in_bytes)
+build_check_stmt (tree base, gimple_stmt_iterator *iter,
+                  location_t location, bool is_store,
+		  int size_in_bytes)
 {
   gimple_stmt_iterator gsi;
   basic_block cond_bb, then_bb, else_bb;
@@ -403,6 +405,7 @@  build_check_stmt (tree base,
   tree shadow_type = TREE_TYPE (shadow_ptr_type);
   tree uintptr_type
     = build_nonstandard_integer_type (TYPE_PRECISION (TREE_TYPE (base)), 1);
+  tree base_ssa = base;
 
   /* We first need to split the current basic block, and start altering
      the CFG.  This allows us to insert the statements we're about to
@@ -448,15 +451,22 @@  build_check_stmt (tree base,
   base = unshare_expr (base);
 
   gsi = gsi_last_bb (cond_bb);
-  g = gimple_build_assign_with_ops (TREE_CODE (base),
-				    make_ssa_name (TREE_TYPE (base), NULL),
-				    base, NULL_TREE);
-  gimple_set_location (g, location);
-  gsi_insert_after (&gsi, g, GSI_NEW_STMT);
+
+  /* BASE can already be an SSA_NAME; in that case, do not create a
+     new SSA_NAME for it.  */
+  if (TREE_CODE (base) != SSA_NAME)
+    {
+      g = gimple_build_assign_with_ops (TREE_CODE (base),
+					make_ssa_name (TREE_TYPE (base), NULL),
+					base, NULL_TREE);
+      gimple_set_location (g, location);
+      gsi_insert_after (&gsi, g, GSI_NEW_STMT);
+      base_ssa = gimple_assign_lhs (g);
+    }
 
   g = gimple_build_assign_with_ops (NOP_EXPR,
 				    make_ssa_name (uintptr_type, NULL),
-				    gimple_assign_lhs (g), NULL_TREE);
+				    base_ssa, NULL_TREE);
   gimple_set_location (g, location);
   gsi_insert_after (&gsi, g, GSI_NEW_STMT);
   base_addr = gimple_assign_lhs (g);