aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2020-12-02 13:01:47 +0100
committerMartin Liska <mliska@suse.cz>2020-12-02 15:03:26 +0100
commitf5850e7da93a6b1e4bec3e8740d08e985433eef3 (patch)
tree6c704bfc4da1dd95e4417d6735fcae892cefd321
parent694d4a6d0c466d0fbc97920a9c6641a7b349ca35 (diff)
downloadgcc-f5850e7da93a6b1e4bec3e8740d08e985433eef3.zip
gcc-f5850e7da93a6b1e4bec3e8740d08e985433eef3.tar.gz
gcc-f5850e7da93a6b1e4bec3e8740d08e985433eef3.tar.bz2
ipa: do not DECL_IS_MALLOC for void fns
gcc/ChangeLog: PR ipa/98075 * cgraph.c (cgraph_node::dump): Dump decl_is_malloc flag. * ipa-pure-const.c (propagate_malloc): Do not set malloc attribute for void functions. gcc/testsuite/ChangeLog: PR ipa/98075 * g++.dg/ipa/pr98075.C: New test.
-rw-r--r--gcc/cgraph.c2
-rw-r--r--gcc/ipa-pure-const.c3
-rw-r--r--gcc/testsuite/g++.dg/ipa/pr98075.C30
3 files changed, 34 insertions, 1 deletions
diff --git a/gcc/cgraph.c b/gcc/cgraph.c
index dbde8aa..cb59a5a 100644
--- a/gcc/cgraph.c
+++ b/gcc/cgraph.c
@@ -2190,6 +2190,8 @@ cgraph_node::dump (FILE *f)
fprintf (f, " optimize_size");
if (parallelized_function)
fprintf (f, " parallelized_function");
+ if (DECL_IS_MALLOC (decl))
+ fprintf (f, " decl_is_malloc");
if (DECL_IS_OPERATOR_NEW_P (decl))
fprintf (f, " %soperator_new",
DECL_IS_REPLACEABLE_OPERATOR (decl) ? "replaceable_" : "");
diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c
index 054f359..4c47eec 100644
--- a/gcc/ipa-pure-const.c
+++ b/gcc/ipa-pure-const.c
@@ -1973,7 +1973,8 @@ propagate_malloc (void)
funct_state l = funct_state_summaries->get (node);
if (!node->alias
&& l->malloc_state == STATE_MALLOC
- && !node->inlined_to)
+ && !node->inlined_to
+ && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (node->decl))))
{
if (dump_file && (dump_flags & TDF_DETAILS))
fprintf (dump_file, "Function %s found to be malloc\n",
diff --git a/gcc/testsuite/g++.dg/ipa/pr98075.C b/gcc/testsuite/g++.dg/ipa/pr98075.C
new file mode 100644
index 0000000..0c4219d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ipa/pr98075.C
@@ -0,0 +1,30 @@
+/* PR ipa/98075 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-inline" } */
+
+template <typename BS>
+class xg {
+public:
+ BS *
+ fw ()
+ {
+ return static_cast<BS *> (operator new (sizeof (BS)));
+ }
+};
+
+class zp : xg<int> {
+public:
+ __attribute__ ((always_inline)) zp ()
+ {
+ hy = xg<int>::fw ();
+ }
+
+private:
+ int *hy;
+};
+
+void
+e5 ()
+{
+ zp ix;
+}