public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/marxin/heads/PR93583-malloc-attribute-v2)] Drop MALLOC attribute for void functions.
@ 2020-02-17 14:53 Martin Liska
0 siblings, 0 replies; 3+ messages in thread
From: Martin Liska @ 2020-02-17 14:53 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:c215a4d5d5d5aa72729c16408805eb9ddf5f0d38
commit c215a4d5d5d5aa72729c16408805eb9ddf5f0d38
Author: Martin Liska <mliska@suse.cz>
Date: Mon Feb 17 12:33:28 2020 +0100
Drop MALLOC attribute for void functions.
gcc/ChangeLog:
2020-02-17 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.
gcc/testsuite/ChangeLog:
2020-02-17 Martin Liska <mliska@suse.cz>
PR ipa/93583
* gcc.dg/ipa/pr93583.c: New test.
Diff:
---
gcc/cgraph.c | 6 ++++++
gcc/ipa-param-manipulation.c | 4 ++++
gcc/ipa-pure-const.c | 5 ++++-
gcc/testsuite/gcc.dg/ipa/pr93583.c | 15 +++++++++++++++
4 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/gcc/cgraph.c b/gcc/cgraph.c
index 294b2d3..6e99fbb 100644
--- a/gcc/cgraph.c
+++ b/gcc/cgraph.c
@@ -3374,6 +3374,12 @@ cgraph_node::verify_node (void)
error ("calls_comdat_local is set outside of a comdat group");
error_found = true;
}
+ if (DECL_IS_MALLOC (decl)
+ && VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
+ {
+ error ("MALLOC attribute set on a void function");
+ error_found = true;
+ }
for (e = indirect_calls; e; e = e->next_callee)
{
if (e->aux)
diff --git a/gcc/ipa-param-manipulation.c b/gcc/ipa-param-manipulation.c
index 19ec873..839bd2e 100644
--- a/gcc/ipa-param-manipulation.c
+++ b/gcc/ipa-param-manipulation.c
@@ -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;
}
diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c
index ccd0918..564c662 100644
--- a/gcc/ipa-pure-const.c
+++ b/gcc/ipa-pure-const.c
@@ -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
diff --git a/gcc/testsuite/gcc.dg/ipa/pr93583.c b/gcc/testsuite/gcc.dg/ipa/pr93583.c
new file mode 100644
index 0000000..30ef506
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/pr93583.c
@@ -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;
+}
^ permalink raw reply [flat|nested] 3+ messages in thread
* [gcc(refs/users/marxin/heads/PR93583-malloc-attribute-v2)] Drop MALLOC attribute for void functions.
@ 2020-02-18 12:31 Martin Liska
0 siblings, 0 replies; 3+ messages in thread
From: Martin Liska @ 2020-02-18 12:31 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:4c41e3381f2b1469888325ddf00856a82fe3c8de
commit 4c41e3381f2b1469888325ddf00856a82fe3c8de
Author: Martin Liska <mliska@suse.cz>
Date: Mon Feb 17 12:33:28 2020 +0100
Drop MALLOC attribute for void functions.
gcc/ChangeLog:
2020-02-17 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.
gcc/testsuite/ChangeLog:
2020-02-17 Martin Liska <mliska@suse.cz>
PR ipa/93583
* gcc.dg/ipa/pr93583.c: New test.
Diff:
---
gcc/cgraph.c | 6 ++++++
gcc/ipa-param-manipulation.c | 4 ++++
gcc/ipa-pure-const.c | 5 ++++-
gcc/testsuite/gcc.dg/ipa/pr93583.c | 15 +++++++++++++++
4 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/gcc/cgraph.c b/gcc/cgraph.c
index 294b2d3..ef0ca87 100644
--- a/gcc/cgraph.c
+++ b/gcc/cgraph.c
@@ -3374,6 +3374,12 @@ 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 set on a void function");
+ error_found = true;
+ }
for (e = indirect_calls; e; e = e->next_callee)
{
if (e->aux)
diff --git a/gcc/ipa-param-manipulation.c b/gcc/ipa-param-manipulation.c
index 19ec873..839bd2e 100644
--- a/gcc/ipa-param-manipulation.c
+++ b/gcc/ipa-param-manipulation.c
@@ -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;
}
diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c
index ccd0918..564c662 100644
--- a/gcc/ipa-pure-const.c
+++ b/gcc/ipa-pure-const.c
@@ -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
diff --git a/gcc/testsuite/gcc.dg/ipa/pr93583.c b/gcc/testsuite/gcc.dg/ipa/pr93583.c
new file mode 100644
index 0000000..30ef506
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/pr93583.c
@@ -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;
+}
^ permalink raw reply [flat|nested] 3+ messages in thread
* [gcc(refs/users/marxin/heads/PR93583-malloc-attribute-v2)] Drop MALLOC attribute for void functions.
@ 2020-02-18 13:08 Martin Liska
0 siblings, 0 replies; 3+ messages in thread
From: Martin Liska @ 2020-02-18 13:08 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:6c29b60fa67b5cbafec4a1089a4edee03ac97ea1
commit 6c29b60fa67b5cbafec4a1089a4edee03ac97ea1
Author: Martin Liska <mliska@suse.cz>
Date: Mon Feb 17 12:33:28 2020 +0100
Drop MALLOC attribute for void functions.
gcc/ChangeLog:
2020-02-17 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.
gcc/testsuite/ChangeLog:
2020-02-17 Martin Liska <mliska@suse.cz>
PR ipa/93583
* gcc.dg/ipa/pr93583.c: New test.
Diff:
---
gcc/cgraph.c | 7 +++++++
gcc/ipa-param-manipulation.c | 4 ++++
gcc/ipa-pure-const.c | 5 ++++-
gcc/testsuite/gcc.dg/ipa/pr93583.c | 15 +++++++++++++++
4 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/gcc/cgraph.c b/gcc/cgraph.c
index 294b2d3..c342379 100644
--- a/gcc/cgraph.c
+++ b/gcc/cgraph.c
@@ -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)
diff --git a/gcc/ipa-param-manipulation.c b/gcc/ipa-param-manipulation.c
index 19ec873..839bd2e 100644
--- a/gcc/ipa-param-manipulation.c
+++ b/gcc/ipa-param-manipulation.c
@@ -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;
}
diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c
index ccd0918..564c662 100644
--- a/gcc/ipa-pure-const.c
+++ b/gcc/ipa-pure-const.c
@@ -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
diff --git a/gcc/testsuite/gcc.dg/ipa/pr93583.c b/gcc/testsuite/gcc.dg/ipa/pr93583.c
new file mode 100644
index 0000000..30ef506
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/pr93583.c
@@ -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;
+}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-02-18 13:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-17 14:53 [gcc(refs/users/marxin/heads/PR93583-malloc-attribute-v2)] Drop MALLOC attribute for void functions Martin Liska
2020-02-18 12:31 Martin Liska
2020-02-18 13:08 Martin Liska
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).