Drop MALLOC attribute for void functions.
authorMartin Liska <mliska@suse.cz>
Tue, 18 Feb 2020 13:39:41 +0000 (14:39 +0100)
committerMartin Liska <mliska@suse.cz>
Tue, 18 Feb 2020 13:39:41 +0000 (14:39 +0100)
PR ipa/93583
* cgraph.c (cgraph_node::verify_node): Verify MALLOC attribute
and return type of functions.
* ipa-param-manipulation.c (ipa_param_adjustments::adjust_decl):
Drop MALLOC attribute for void functions.
* ipa-pure-const.c (funct_state_summary_t::duplicate): Drop
malloc_state for a new VOID clone.
PR ipa/93583
* gcc.dg/ipa/pr93583.c: New test.

gcc/ChangeLog
gcc/cgraph.c
gcc/ipa-param-manipulation.c
gcc/ipa-pure-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/ipa/pr93583.c [new file with mode: 0644]

index db6740a500662488666bd942c3bb1338590fa22b..b4b49424eaed5cbe63df5f4fec8bf16b9776cf20 100644 (file)
@@ -1,3 +1,13 @@
+2020-02-18  Martin Liska  <mliska@suse.cz>
+
+       PR ipa/93583
+       * cgraph.c (cgraph_node::verify_node): Verify MALLOC attribute
+       and return type of functions.
+       * ipa-param-manipulation.c (ipa_param_adjustments::adjust_decl):
+       Drop MALLOC attribute for void functions.
+       * ipa-pure-const.c (funct_state_summary_t::duplicate): Drop
+       malloc_state for a new VOID clone.
+
 2020-02-18  Martin Liska  <mliska@suse.cz>
 
        PR ipa/92924
index c420863a0fd19a9e552e75babacc8bc003d85a4e..9f0774f227f83c2dd6558ea6ef694ab0fa1a2585 100644 (file)
@@ -3374,6 +3374,13 @@ cgraph_node::verify_node (void)
       error ("calls_comdat_local is set outside of a comdat group");
       error_found = true;
     }
+  if (DECL_IS_MALLOC (decl)
+      && !POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
+    {
+      error ("malloc attribute should be used for a function that "
+            "returns a pointer");
+      error_found = true;
+    }
   for (e = indirect_calls; e; e = e->next_callee)
     {
       if (e->aux)
index 19ec87358fa97464f9f186d9435567b9400fa987..839bd2ef870e1fba7e03f005c7d4589e8f35fc4a 100644 (file)
@@ -410,6 +410,10 @@ ipa_param_adjustments::adjust_decl (tree orig_decl)
   DECL_VIRTUAL_P (new_decl) = 0;
   DECL_LANG_SPECIFIC (new_decl) = NULL;
 
+  /* Drop MALLOC attribute for a void function.  */
+  if (m_skip_return)
+    DECL_IS_MALLOC (new_decl) = 0;
+
   return new_decl;
 }
 
index ccd0918c120c7bd424bca72fb055ac68b099e400..564c6629c92edc6dd4682fe31412f9ff70cba025 100644 (file)
@@ -1157,11 +1157,14 @@ funct_state_summary_t::insert (cgraph_node *node, funct_state_d *state)
 /* Called when new clone is inserted to callgraph late.  */
 
 void
-funct_state_summary_t::duplicate (cgraph_node *, cgraph_node *,
+funct_state_summary_t::duplicate (cgraph_node *, cgraph_node *dst,
                                  funct_state_d *src_data,
                                  funct_state_d *dst_data)
 {
   new (dst_data) funct_state_d (*src_data);
+  if (dst_data->malloc_state == STATE_MALLOC
+      && VOID_TYPE_P (TREE_TYPE (TREE_TYPE (dst->decl))))
+    dst_data->malloc_state = STATE_MALLOC_BOTTOM;
 }
 
 \f
index 55e2e6eaa4327046cc7abb5f1d615b51c7ceab80..9f7a4f7a61d2a10be97b308bf03ecc8c1a7cfe75 100644 (file)
@@ -1,3 +1,8 @@
+2020-02-18  Martin Liska  <mliska@suse.cz>
+
+       PR ipa/93583
+       * gcc.dg/ipa/pr93583.c: New test.
+
 2020-02-18  David Malcolm  <dmalcolm@redhat.com>
 
        PR analyzer/93777
diff --git a/gcc/testsuite/gcc.dg/ipa/pr93583.c b/gcc/testsuite/gcc.dg/ipa/pr93583.c
new file mode 100644 (file)
index 0000000..30ef506
--- /dev/null
@@ -0,0 +1,15 @@
+/* PR ipa/93583 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+void *bar(const char*);
+static void *__attribute__((malloc,noinline)) foo(const char *p)
+{
+  return bar (p);
+}
+
+int main(int argc, char **argv)
+{
+  foo (argv[0]);
+  return 0;
+}