On 14 May 2018 at 14:46, Richard Biener <rguent...@suse.de> wrote: > On Mon, 14 May 2018, Prathamesh Kulkarni wrote: > >> Hi, >> The attached patch tries to fix PR85734, by gating on >> !function_always_visible_to_compiler_p. >> Bootstrap+test in progress on x86_64. >> OK to commit if passes ? > > This looks redundant - suggest_attribute does that very same check > but warn_function_malloc passes it 'false' as known_finite > (warn_function_noreturn passes it true for example). Indeed, thanks for pointing it out. > > So I suggest to simply pass true as that arg. Is the attached version OK to commit after bootstrap+test ?
Thanks, Prathamesh > > Richard > >> Thanks, >> Prathamesh >> > > -- > Richard Biener <rguent...@suse.de> > SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB > 21284 (AG Nuernberg)
2018-05-14 Prathamesh Kulkarni <prathamesh.kulka...@linaro.org> PR ipa/85734 * ipa-pure-const.c (warn_function_malloc): Pass value of known_finite param as true in call to suggest_attribute. testsuite/ * gcc.dg/ipa/pr85734.c: New test. diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c index a80b6845633..7665358a9a5 100644 --- a/gcc/ipa-pure-const.c +++ b/gcc/ipa-pure-const.c @@ -249,7 +249,7 @@ warn_function_malloc (tree decl) static hash_set<tree> *warned_about; warned_about = suggest_attribute (OPT_Wsuggest_attribute_malloc, decl, - false, warned_about, "malloc"); + true, warned_about, "malloc"); } /* Emit suggestion about __attribute__((noreturn)) for DECL. */ 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); +}