From f3f75f693d12f58acbb37d393280081621eb3f58 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Wed, 23 Apr 2008 13:47:38 +0000 Subject: [PATCH] re PR c/36021 (__attribute__((alloc_size(n))) with function of no arguments causes gcc to segfault) 2008-04-23 Richard Guenther PR middle-end/36021 * c-common.c (handle_alloc_size_attribute): Use type_num_arguments. * gcc.dg/attr-alloc_size-2.c: New testcase. From-SVN: r134595 --- gcc/ChangeLog | 5 +++++ gcc/c-common.c | 7 +------ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/attr-alloc_size-2.c | 4 ++++ 4 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/attr-alloc_size-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 50b7fc2f185..f0fb8403400 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2008-04-23 Richard Guenther + + PR middle-end/36021 + * c-common.c (handle_alloc_size_attribute): Use type_num_arguments. + 2008-04-22 Tomas Bily * tree-cfg.c (verify_expr): Check for NON_LVALUE_EXPR as unreachable diff --git a/gcc/c-common.c b/gcc/c-common.c index 351c62831d3..a18752e7a7b 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -5941,12 +5941,7 @@ static tree handle_alloc_size_attribute (tree *node, tree ARG_UNUSED (name), tree args, int ARG_UNUSED (flags), bool *no_add_attrs) { - tree params = TYPE_ARG_TYPES (*node); - unsigned arg_count = 0; - - for (; TREE_CHAIN (params); params = TREE_CHAIN (params)) - arg_count ++; - + unsigned arg_count = type_num_arguments (*node); for (; args; args = TREE_CHAIN (args)) { tree position = TREE_VALUE (args); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9493fef2e55..d5828e87085 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-04-23 Richard Guenther + + PR middle-end/36021 + * gcc.dg/attr-alloc_size-2.c: New testcase. + 2008-04-23 Kai Tietz * gcc.dg/20020919-1.c (loc_size_t): New type. diff --git a/gcc/testsuite/gcc.dg/attr-alloc_size-2.c b/gcc/testsuite/gcc.dg/attr-alloc_size-2.c new file mode 100644 index 00000000000..3cac807370f --- /dev/null +++ b/gcc/testsuite/gcc.dg/attr-alloc_size-2.c @@ -0,0 +1,4 @@ +/* { dg-do compile } */ + +char *foo() __attribute__((alloc_size(1))); /* { dg-warning "outside range" } */ + -- 2.30.2