2018-05-14 Prathamesh Kulkarni PR ipa/85734 * ipa-pure-const.c (propagate_malloc): Gate call towarn_function_malloc on !funcion_always_visible_to_compiler_p. (pass_local_pure_const::execute): Likewise. testsuite/ * gcc.dg/ipa/pr85734.c: New test. diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c index a80b6845633..ce8028c1639 100644 --- a/gcc/ipa-pure-const.c +++ b/gcc/ipa-pure-const.c @@ -1987,7 +1987,8 @@ propagate_malloc (void) bool malloc_decl_p = DECL_IS_MALLOC (node->decl); node->set_malloc_flag (true); - if (!malloc_decl_p && warn_suggest_attribute_malloc) + if (!malloc_decl_p && !function_always_visible_to_compiler_p (node->decl) + && warn_suggest_attribute_malloc) warn_function_malloc (node->decl); } } @@ -2221,7 +2222,8 @@ pass_local_pure_const::execute (function *fun) && !DECL_IS_MALLOC (current_function_decl)) { node->set_malloc_flag (true); - if (warn_suggest_attribute_malloc) + if (warn_suggest_attribute_malloc + && !function_always_visible_to_compiler_p (current_function_decl)) warn_function_malloc (node->decl); changed = true; if (dump_file) diff --git a/gcc/testsuite/gcc.dg/ipa/pr85734.c b/gcc/testsuite/gcc.dg/ipa/pr85734.c new file mode 100644 index 00000000000..e5fa21f0548 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/pr85734.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wsuggest-attribute=malloc" } */ + +__attribute__((noinline)) +static void *f1(__SIZE_TYPE__ sz) /* { dg-bogus "function might be candidate for attribute 'malloc'" } */ +{ + return __builtin_malloc (sz); +} + +__attribute__((noinline)) +static void *f2(__SIZE_TYPE__ sz) /* { dg-bogus "function might be candidate for attribute 'malloc'" } */ +{ + return f1 (sz); +} + +void *f3(__SIZE_TYPE__ sz) /* { dg-warning "function might be candidate for attribute 'malloc'" } */ +{ + return f2(sz); +}