diff mbox series

PR85734

Message ID CAAgBjM=VeybyghFgEThw55mQRSHy3w_+4Dg__NAtkJOQEF_FMQ@mail.gmail.com
State New
Headers show
Series PR85734 | expand

Commit Message

Prathamesh Kulkarni May 14, 2018, 9:07 a.m. UTC
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 ?

Thanks,
Prathamesh
2018-05-14  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>

	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.

Comments

Richard Biener May 14, 2018, 9:16 a.m. UTC | #1
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).

So I suggest to simply pass true as that arg.

Richard

> Thanks,
> Prathamesh
>
Prathamesh Kulkarni May 14, 2018, 9:33 a.m. UTC | #2
On 14 May 2018 at 14:46, Richard Biener <rguenther@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 <rguenther@suse.de>
> SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)
2018-05-14  Prathamesh Kulkarni  <prathamesh.kulkarni@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);
+}
Richard Biener May 14, 2018, 9:36 a.m. UTC | #3
On Mon, 14 May 2018, Prathamesh Kulkarni wrote:

> On 14 May 2018 at 14:46, Richard Biener <rguenther@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 ?

Yes.
Richard.

> Thanks,
> Prathamesh
> >
> > Richard
> >
> >> Thanks,
> >> Prathamesh
> >>
> >
> > --
> > Richard Biener <rguenther@suse.de>
> > SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)
>
Prathamesh Kulkarni May 14, 2018, 12:30 p.m. UTC | #4
On 14 May 2018 at 15:06, Richard Biener <rguenther@suse.de> wrote:
> On Mon, 14 May 2018, Prathamesh Kulkarni wrote:
>
>> On 14 May 2018 at 14:46, Richard Biener <rguenther@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 ?
>
> Yes.
Also on a related bug PR85562, should we change the wording of
suggest_attribute for malloc
to omit the text "if it is known to return normally" ?

Thanks,
Prathamesh
> Richard.
>
>> Thanks,
>> Prathamesh
>> >
>> > Richard
>> >
>> >> Thanks,
>> >> Prathamesh
>> >>
>> >
>> > --
>> > Richard Biener <rguenther@suse.de>
>> > SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)
>>
>
> --
> Richard Biener <rguenther@suse.de>
> SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)
Richard Biener May 14, 2018, 2:19 p.m. UTC | #5
On May 14, 2018 2:30:27 PM GMT+02:00, Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org> wrote:
>On 14 May 2018 at 15:06, Richard Biener <rguenther@suse.de> wrote:
>> On Mon, 14 May 2018, Prathamesh Kulkarni wrote:
>>
>>> On 14 May 2018 at 14:46, Richard Biener <rguenther@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 ?
>>
>> Yes.
>Also on a related bug PR85562, should we change the wording of
>suggest_attribute for malloc
>to omit the text "if it is known to return normally" ?

Yes. 

Richard. 

>Thanks,
>Prathamesh
>> Richard.
>>
>>> Thanks,
>>> Prathamesh
>>> >
>>> > Richard
>>> >
>>> >> Thanks,
>>> >> Prathamesh
>>> >>
>>> >
>>> > --
>>> > Richard Biener <rguenther@suse.de>
>>> > SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham
>Norton, HRB 21284 (AG Nuernberg)
>>>
>>
>> --
>> Richard Biener <rguenther@suse.de>
>> SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham
>Norton, HRB 21284 (AG Nuernberg)
diff mbox series

Patch

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);
+}