This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix pr15443
- From: ja2morri at csclub dot uwaterloo dot ca (James A. Morrison)
- To: gcc-patches at gcc dot gnu dot org
- Date: 25 Mar 2005 00:28:22 -0500
- Subject: [PATCH] Fix pr15443
Hi,
As indicated in pr15443 gcc used to ice when a program tried to call
a void function marked with __attribute__((malloc)). This patch warns
the user if __attribute__((malloc)) is used on any function that doesn't
return a pointer, it also gets rid of the ice because DECL_IS_MALLOC is not
set on the function that returns void.
Currently bootstrapping and regtesting on ia64-linux, ok for mainline
if testing succeeds?
--
Thanks,
Jim
http://www.student.cs.uwaterloo.ca/~ja2morri/
http://phython.blogspot.com
http://open.nit.ca/wiki/?page=jim
2005-03-25 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.
Index: c-common.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.617
diff -u -p -r1.617 c-common.c
--- c-common.c 23 Mar 2005 01:35:00 -0000 1.617
+++ c-common.c 25 Mar 2005 05:13:42 -0000
@@ -4784,9 +4784,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);
/* { dg-do compile } */
void f () __attribute__ ((__malloc__)); /* { dg-warning "ignored" } */
int main ()
{
/* This used to cause an ICE. */
f ();
}
/* { 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));