re PR ipa/85734 (--suggest-attribute=malloc misdiagnoses static functions)
authorPrathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
Tue, 15 May 2018 04:44:33 +0000 (04:44 +0000)
committerPrathamesh Kulkarni <prathamesh3492@gcc.gnu.org>
Tue, 15 May 2018 04:44:33 +0000 (04:44 +0000)
2018-05-15  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.

From-SVN: r260249

gcc/ChangeLog
gcc/ipa-pure-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/ipa/pr85734.c [new file with mode: 0644]

index 9e54758..294a937 100644 (file)
@@ -1,3 +1,9 @@
+2018-05-15  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.
+
 2018-05-14  Segher Boessenkool  <segher@kernel.crashing.org>
 
        * doc/invoke.texi (RS/6000 and PowerPC Options): Delete @itemx for
index a80b684..7665358 100644 (file)
@@ -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.  */
index 4a0b371..452e6a2 100644 (file)
@@ -1,3 +1,8 @@
+2018-05-14  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
+
+       PR ipa/85734
+       * gcc.dg/ipa/pr85734.c: New test.
+
 2018-05-14  Eric Botcazou  <ebotcazou@adacore.com>
 
        PR target/85756
diff --git a/gcc/testsuite/gcc.dg/ipa/pr85734.c b/gcc/testsuite/gcc.dg/ipa/pr85734.c
new file mode 100644 (file)
index 0000000..e5fa21f
--- /dev/null
@@ -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);
+}