c-common.c (handle_malloc_atttribute): Only set DECL_IS_MALLOC if the function return...
authorJames A. Morrison <phython@gcc.gnu.org>
Wed, 6 Apr 2005 21:22:02 +0000 (21:22 +0000)
committerJames A. Morrison <phython@gcc.gnu.org>
Wed, 6 Apr 2005 21:22:02 +0000 (21:22 +0000)
2005-04-06  James A. Morrison  <phython@gcc.gnu.org>

        * c-common.c (handle_malloc_atttribute): Only set DECL_IS_MALLOC if
        the function returns a pointer type.

From-SVN: r97751

gcc/ChangeLog
gcc/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr15443-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr15443-2.c [new file with mode: 0644]

index aa8bcc5d20de5974c15cbaf40e94df57dff26899..8751369fa8a3e1c504d6372eeb890d10aa141eef 100644 (file)
@@ -1,3 +1,8 @@
+2005-04-06  James A. Morrison  <phython@gcc.gnu.org>
+
+       * c-common.c (handle_malloc_atttribute): Only set DECL_IS_MALLOC if
+       the function returns a pointer type.
+
 2005-04-06  Daniel Berlin  <dberlin@dberlin.org>
 
        * params.def (PARAM_SALIAS_MAX_IMPLICIT_FIELDS): New
index 817d939be3b3c00236f770c16bb636291eab9f26..f68c8532ebe87b76354d95f45bde066a9fd2f2b1 100644 (file)
@@ -4808,9 +4808,9 @@ static tree
 handle_malloc_attribute (tree *node, tree name, tree ARG_UNUSED (args),
                         int ARG_UNUSED (flags), bool *no_add_attrs)
 {
-  if (TREE_CODE (*node) == FUNCTION_DECL)
+  if (TREE_CODE (*node) == FUNCTION_DECL
+      && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node))))
     DECL_IS_MALLOC (*node) = 1;
-  /* ??? TODO: Support types.  */
   else
     {
       warning ("%qE attribute ignored", name);
index dc98fcd7d632bbcc2d05b3ff28f064be4629eba4..2b354af1a75de44873fd873a6fa4ceac728a1221 100644 (file)
@@ -1,3 +1,8 @@
+2005-04-06  James A. Morrison  <phython@gcc.gnu.org>
+
+       * gcc.dg/15443-1.c: New test.
+       * gcc.dg/15443-2.c: Likewise.
+
 2005-04-06  Tobias Schl"uter  <tobias.schlueter@physik.uni-muenchen.de>
 
        * gfortran.dg/pr15754.f90: Change annotations to dg-error.
diff --git a/gcc/testsuite/gcc.dg/pr15443-1.c b/gcc/testsuite/gcc.dg/pr15443-1.c
new file mode 100644 (file)
index 0000000..d6106b5
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+
+void f () __attribute__ ((__malloc__)); /* { dg-warning "ignored" } */
+
+int main ()
+{
+       /* This used to cause an ICE.  */
+       f ();
+}
+
diff --git a/gcc/testsuite/gcc.dg/pr15443-2.c b/gcc/testsuite/gcc.dg/pr15443-2.c
new file mode 100644 (file)
index 0000000..d97fa25
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+
+struct foo {
+       int bar;
+};
+
+typedef struct foo* bar;
+void f () __attribute__ ((__malloc__)); /* { dg-warning "ignored" } */
+int g () __attribute__ ((__malloc__)); /* { dg-warning "ignored" } */
+int* h () __attribute__ ((__malloc__));
+void* i () __attribute__ ((__malloc__));
+
+struct foo j () __attribute__ ((__malloc__)); /* { dg-warning "ignored" } */
+struct foo* k () __attribute__ ((__malloc__));
+bar l () __attribute__((malloc));