]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-ssa-alias.c (ref_maybe_used_by_call_p_1): Handle BUILT_IN_REALLOC like BUILT_IN_...
authorRichard Biener <rguenther@suse.de>
Thu, 22 May 2014 09:59:49 +0000 (09:59 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 22 May 2014 09:59:49 +0000 (09:59 +0000)
2014-05-22  Richard Biener  <rguenther@suse.de>

* tree-ssa-alias.c (ref_maybe_used_by_call_p_1): Handle
BUILT_IN_REALLOC like BUILT_IN_STRDUP.
(call_may_clobber_ref_p_1): Handle BUILT_IN_REALLOC as allocation
and deallocation site.
* tree-ssa-structalias.c (find_func_aliases_for_builtin_call):
Handle BUILT_IN_REALLOC similar to BUILT_IN_STRDUP with also
passing through the incoming points-to set.
(handle_lhs_call): Use flags argument instead of recomputing it.
(find_func_aliases_for_call): Call handle_lhs_call with proper
call return flags.

* gcc.dg/tree-ssa/alias-33.c: New testcase.

From-SVN: r210802

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/alias-33.c [new file with mode: 0644]
gcc/tree-ssa-alias.c
gcc/tree-ssa-structalias.c

index 1d766a3635e8388ad7d14b84f43786a48ea97a65..ad78d7819eea62584e49928ed7d75b6dd8dfa448 100644 (file)
@@ -1,3 +1,16 @@
+2014-05-22  Richard Biener  <rguenther@suse.de>
+
+       * tree-ssa-alias.c (ref_maybe_used_by_call_p_1): Handle
+       BUILT_IN_REALLOC like BUILT_IN_STRDUP.
+       (call_may_clobber_ref_p_1): Handle BUILT_IN_REALLOC as allocation
+       and deallocation site.
+       * tree-ssa-structalias.c (find_func_aliases_for_builtin_call):
+       Handle BUILT_IN_REALLOC similar to BUILT_IN_STRDUP with also
+       passing through the incoming points-to set.
+       (handle_lhs_call): Use flags argument instead of recomputing it.
+       (find_func_aliases_for_call): Call handle_lhs_call with proper
+       call return flags.
+
 2014-05-22  Jakub Jelinek  <jakub@redhat.com>
 
        * tree-streamer-in.c (unpack_ts_real_cst_value_fields): Make sure
index edbb9c6dd7a0563e9e3e1cfe80574c09e2648247..0641f59884e3e9f0d77c43a0b3ab714de8ecb9b9 100644 (file)
@@ -1,3 +1,7 @@
+2014-05-22  Richard Biener  <rguenther@suse.de>
+
+       * gcc.dg/tree-ssa/alias-33.c: New testcase.
+
 2014-05-22  Kostya Serebryany  <kcc@google.com>
 
        * c-c++-common/tsan/mutexset1.c: Update the test to match
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/alias-33.c b/gcc/testsuite/gcc.dg/tree-ssa/alias-33.c
new file mode 100644 (file)
index 0000000..cbc0812
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-do run } */
+/* { dg-options "-O -fdump-tree-fre1-details" } */
+
+int j;
+int main ()
+{
+  int i = 1;
+  int **p;
+  j = 0;
+  p = __builtin_malloc (sizeof (int *));
+  *p = &i;
+  p = __builtin_realloc (p, 2 * sizeof (int *));
+  **p = 0;
+  if (i != 0)
+    __builtin_abort ();
+  return j;
+}
+
+/* { dg-final { scan-tree-dump "Replaced j with 0" "fre1" } } */
+/* { dg-final { cleanup-tree-dump "fre1" } } */
index 479fa9ce0f012108971836fae6e331b817a95dcd..0371070a67ece8c1fbd70037b391f2ee1a3dd00a 100644 (file)
@@ -1594,6 +1594,7 @@ ref_maybe_used_by_call_p_1 (gimple call, ao_ref *ref)
        /* These read memory pointed to by the first argument.  */
        case BUILT_IN_STRDUP:
        case BUILT_IN_STRNDUP:
+       case BUILT_IN_REALLOC:
          {
            ao_ref dref;
            tree size = NULL_TREE;
@@ -1991,6 +1992,15 @@ call_may_clobber_ref_p_1 (gimple call, ao_ref *ref)
            tree ptr = gimple_call_arg (call, 0);
            return ptr_deref_may_alias_ref_p_1 (ptr, ref);
          }
+       /* Realloc serves both as allocation point and deallocation point.  */
+       case BUILT_IN_REALLOC:
+         {
+           tree ptr = gimple_call_arg (call, 0);
+           /* Unix98 specifies that errno is set on allocation failure.  */
+           return ((flag_errno_math
+                    && targetm.ref_may_alias_errno (ref))
+                   || ptr_deref_may_alias_ref_p_1 (ptr, ref));
+         }
        case BUILT_IN_GAMMA_R:
        case BUILT_IN_GAMMAF_R:
        case BUILT_IN_GAMMAL_R:
index 5d3a323e54a64d1e48ee6f3b88a085aa4747cd1b..99e97d67a850e15110ed341d908f6516afc1f567 100644 (file)
@@ -3974,7 +3974,6 @@ handle_lhs_call (gimple stmt, tree lhs, int flags, vec<ce_s> rhsc,
 
   /* If the call returns an argument unmodified override the rhs
      constraints.  */
-  flags = gimple_call_return_flags (stmt);
   if (flags & ERF_RETURNS_ARG
       && (flags & ERF_RETURN_ARG_MASK) < gimple_call_num_args (stmt))
     {
@@ -4299,9 +4298,11 @@ find_func_aliases_for_builtin_call (struct function *fn, gimple t)
        return true;
       case BUILT_IN_STRDUP:
       case BUILT_IN_STRNDUP:
+      case BUILT_IN_REALLOC:
        if (gimple_call_lhs (t))
          {
-           handle_lhs_call (t, gimple_call_lhs (t), gimple_call_flags (t),
+           handle_lhs_call (t, gimple_call_lhs (t),
+                            gimple_call_return_flags (t) | ERF_NOALIAS,
                             vNULL, fndecl);
            get_constraint_for_ptr_offset (gimple_call_lhs (t),
                                           NULL_TREE, &lhsc);
@@ -4312,6 +4313,17 @@ find_func_aliases_for_builtin_call (struct function *fn, gimple t)
            process_all_all_constraints (lhsc, rhsc);
            lhsc.release ();
            rhsc.release ();
+           /* For realloc the resulting pointer can be equal to the
+              argument as well.  But only doing this wouldn't be
+              correct because with ptr == 0 realloc behaves like malloc.  */
+           if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_REALLOC)
+             {
+               get_constraint_for (gimple_call_lhs (t), &lhsc);
+               get_constraint_for (gimple_call_arg (t, 0), &rhsc);
+               process_all_all_constraints (lhsc, rhsc);
+               lhsc.release ();
+               rhsc.release ();
+             }
            return true;
          }
        break;
@@ -4535,7 +4547,8 @@ find_func_aliases_for_call (struct function *fn, gimple t)
       else
        handle_rhs_call (t, &rhsc);
       if (gimple_call_lhs (t))
-       handle_lhs_call (t, gimple_call_lhs (t), flags, rhsc, fndecl);
+       handle_lhs_call (t, gimple_call_lhs (t),
+                        gimple_call_return_flags (t), rhsc, fndecl);
       rhsc.release ();
     }
   else