diff options
author | Martin Liska <mliska@suse.cz> | 2020-02-18 14:39:41 +0100 |
---|---|---|
committer | Martin Liska <mliska@suse.cz> | 2020-02-18 14:39:41 +0100 |
commit | 33351ff9faa21c4c1af377d661a52ac0ce366db3 (patch) | |
tree | 7d760e87a084594b68ebff4ced557ee2ffb57460 | |
parent | ea0b12523d0d9a9059b5173ce9653b92ddfb284f (diff) | |
download | gcc-33351ff9faa21c4c1af377d661a52ac0ce366db3.zip gcc-33351ff9faa21c4c1af377d661a52ac0ce366db3.tar.gz gcc-33351ff9faa21c4c1af377d661a52ac0ce366db3.tar.bz2 |
Drop MALLOC attribute for void functions.
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.
-rw-r--r-- | gcc/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/cgraph.c | 7 | ||||
-rw-r--r-- | gcc/ipa-param-manipulation.c | 4 | ||||
-rw-r--r-- | gcc/ipa-pure-const.c | 5 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/ipa/pr93583.c | 15 |
6 files changed, 45 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index db6740a..b4b4942 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,15 @@ 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 * common.opt: Add -fprofile-reproducibility. * doc/invoke.texi: Document it. diff --git a/gcc/cgraph.c b/gcc/cgraph.c index c420863..9f0774f 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; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 55e2e6e..9f7a4f7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 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; +} |