re PR tree-optimization/83648 (missing -Wsuggest-attribute=malloc on a trivial malloc...
authorPrathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
Tue, 15 May 2018 06:07:48 +0000 (06:07 +0000)
committerPrathamesh Kulkarni <prathamesh3492@gcc.gnu.org>
Tue, 15 May 2018 06:07:48 +0000 (06:07 +0000)
2018-05-15  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>

PR tree-optimization/83648
* ipa-pure-const.c (malloc_candidate_p): Allow function with NULL
return value as malloc candidate.

testsuite/
* gcc.dg/tree-ssa/pr83648.c: New test.
* gcc.dg/tree-ssa/pr83648-2.c: Likewise.

From-SVN: r260250

gcc/ChangeLog
gcc/ipa-pure-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/pr83648-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr83648.c [new file with mode: 0644]

index 294a937327ae35811e3cd88600e4ac8ca3c4b500..17f2cfd3ec18012da7e795c5ed81a80aa869643b 100644 (file)
@@ -1,3 +1,9 @@
+2018-05-15  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
+
+       PR tree-optimization/83648
+       * ipa-pure-const.c (malloc_candidate_p): Allow function with NULL
+       return value as malloc candidate.
+
 2018-05-15  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
 
        PR ipa/85734
index 7665358a9a51e4b6801b1bcf86dcb7541f063414..567b615fb60e457c831336ffd7f0be905292922f 100644 (file)
@@ -919,11 +919,13 @@ malloc_candidate_p (function *fun, bool ipa)
 #define DUMP_AND_RETURN(reason)  \
 {  \
   if (dump_file && (dump_flags & TDF_DETAILS))  \
-    fprintf (dump_file, "%s", (reason));  \
+    fprintf (dump_file, "\n%s is not a malloc candidate, reason: %s\n", \
+            (node->name()), (reason));  \
   return false;  \
 }
 
-  if (EDGE_COUNT (exit_block->preds) == 0)
+  if (EDGE_COUNT (exit_block->preds) == 0
+      || !flag_delete_null_pointer_checks)
     return false;
 
   FOR_EACH_EDGE (e, ei, exit_block->preds)
@@ -938,6 +940,9 @@ malloc_candidate_p (function *fun, bool ipa)
       if (!retval)
        DUMP_AND_RETURN("No return value.")
 
+      if (integer_zerop (retval))
+       continue;
+
       if (TREE_CODE (retval) != SSA_NAME
          || TREE_CODE (TREE_TYPE (retval)) != POINTER_TYPE)
        DUMP_AND_RETURN("Return value is not SSA_NAME or not a pointer type.")
@@ -970,11 +975,14 @@ malloc_candidate_p (function *fun, bool ipa)
        for (unsigned i = 0; i < gimple_phi_num_args (phi); ++i)
          {
            tree arg = gimple_phi_arg_def (phi, i);
+           if (integer_zerop (arg))
+             continue;
+
            if (TREE_CODE (arg) != SSA_NAME)
-             DUMP_AND_RETURN("phi arg is not SSA_NAME.")
-           if (!(arg == null_pointer_node || check_retval_uses (arg, phi)))
-             DUMP_AND_RETURN("phi arg has uses outside phi"
-                             " and comparisons against 0.")
+             DUMP_AND_RETURN ("phi arg is not SSA_NAME.");
+           if (!check_retval_uses (arg, phi))
+             DUMP_AND_RETURN ("phi arg has uses outside phi"
+                              " and comparisons against 0.")
 
            gimple *arg_def = SSA_NAME_DEF_STMT (arg);
            gcall *call_stmt = dyn_cast<gcall *> (arg_def);
index 452e6a276a51299d919a57a5fe464ffc94067fe1..90839ae94284cf9cd16b82f1f7f6378fb0b589f1 100644 (file)
@@ -1,3 +1,9 @@
+2018-05-15  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
+
+       PR tree-optimization/83648
+       * gcc.dg/tree-ssa/pr83648.c: New test.
+       * gcc.dg/tree-ssa/pr83648-2.c: Likewise.
+
 2018-05-14  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
 
        PR ipa/85734
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr83648-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr83648-2.c
new file mode 100644 (file)
index 0000000..ffa7e46
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-delete-null-pointer-checks -fdump-tree-local-pure-const-details" } */
+
+void *g(unsigned n)
+{
+  return n ? __builtin_malloc (n) : 0;
+}
+
+void *h()
+{
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-not "Function found to be malloc: g" "local-pure-const1" } } */
+/* { dg-final { scan-tree-dump-not "Function found to be malloc: h" "local-pure-const1" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr83648.c b/gcc/testsuite/gcc.dg/tree-ssa/pr83648.c
new file mode 100644 (file)
index 0000000..febfd7d
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-local-pure-const-details" } */
+
+void *g(unsigned n)
+{
+  return n ? __builtin_malloc (n) : 0;
+}
+
+void *h()
+{
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump "Function found to be malloc: g" "local-pure-const1" } } */
+/* { dg-final { scan-tree-dump "Function found to be malloc: h" "local-pure-const1" } } */