On 6/6/19 11:27 PM, Martin Liška wrote:
On 6/6/19 5:17 PM, Martin Sebor wrote:
On 6/6/19 2:01 AM, Martin Liška wrote:
Hi.

The patch is about addition of warn_unused_attribute for malloc-like function.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

I like this change (as you know :)  Just one question: should
all allocation functions be also annotated, including the two
variants of __builtin_alloca_with_align and
__builtin_posix_memalign?

Hi, we define the first one (and __builtin_alloca_with_align_and_max) in 
builtins.def
as: /* Implementing variable sized local variables.  */
and define just a stub: DEF_BUILTIN_STUB

Do you know why is that a variable sized function?

__builtin_alloca_with_align implements VLAs.  I think the stubs
are used for intrnisics that were originally meant to be called
exclusively by GCC alone and not directly by programs.

The later one is a bit different as it does not return memory, but return code.
Glibc does not mark it with warn_unused_result attr.

My mistake.  I confused posix_memalign with aligned_alloc.

Martin




As a separate comment, to get the benefit of the attribute in
GCC we might want to also annotate the wrappers in libiberty.h
and perhaps also some (many?) of the functions in tree.h.
(This is just a suggestion to think about independent of your
change.)

Good idea, I can prepare a patch for it as well.

Martin


Martin


Ready to be installed?
Thanks,
Martin

gcc/ChangeLog:

2019-06-06  Martin Liska  <mli...@suse.cz>

     PR tree-optimization/78902
     * builtin-attrs.def (ATTR_WARN_UNUSED_RESULT): New.
     (ATTR_MALLOC_NOTHROW_LEAF_LIST): Remove.
     (ATTR_WARN_UNUSED_RESULT_NOTHROW_LEAF_LIST): New.
     (ATTR_MALLOC_WARN_UNUSED_RESULT_NOTHROW_LEAF_LIST): New.
     (ATTR_ALLOC_SIZE_2_NOTHROW_LIST): Remove.
     (ATTR_MALLOC_SIZE_1_NOTHROW_LEAF_LIST): Remove.
     (ATTR_MALLOC_WARN_UNUSED_RESULT_NOTHROW_LIST): New.
     (ATTR_ALLOC_WARN_UNUSED_RESULT_SIZE_2_NOTHROW_LIST): New.
     (ATTR_MALLOC_WARN_UNUSED_RESULT_SIZE_1_NOTHROW_LEAF_LIST): New.
     (ATTR_ALLOCA_SIZE_1_NOTHROW_LEAF_LIST): Remove.
     (ATTR_ALLOCA_WARN_UNUSED_RESULT_SIZE_1_NOTHROW_LEAF_LIST): New.
     (ATTR_MALLOC_SIZE_1_2_NOTHROW_LEAF_LIST):  Remove.
     (ATTR_MALLOC_WARN_UNUSED_RESULT_SIZE_1_2_NOTHROW_LEAF_LIST):
     New.
     (ATTR_ALLOC_SIZE_2_NOTHROW_LEAF_LIST): Remove.
     (ATTR_ALLOC_WARN_UNUSED_RESULT_SIZE_2_NOTHROW_LEAF_LIST): New.
     (ATTR_MALLOC_NOTHROW_NONNULL): Remove.
     (ATTR_WARN_UNUSED_RESULT_NOTHROW_NONNULL): New.
     (ATTR_MALLOC_WARN_UNUSED_RESULT_NOTHROW_NONNULL): New.
     (ATTR_MALLOC_NOTHROW_NONNULL_LEAF): Remove.
     (ATTR_WARN_UNUSED_RESULT_NOTHROW_NONNULL_LEAF): New.
     (ATTR_MALLOC_WARN_UNUSED_RESULT_NOTHROW_NONNULL_LEAF): New.
     * builtins.def (BUILT_IN_ALIGNED_ALLOC): Change to use
     warn_unused_result attribute.
     (BUILT_IN_STRDUP): Likewise.
     (BUILT_IN_STRNDUP): Likewise.
     (BUILT_IN_ALLOCA): Likewise.
     (BUILT_IN_CALLOC): Likewise.
     (BUILT_IN_MALLOC): Likewise.
     (BUILT_IN_REALLOC): Likewise.

gcc/testsuite/ChangeLog:

2019-06-06  Martin Liska  <mli...@suse.cz>

     PR tree-optimization/78902
     * c-c++-common/asan/alloca_loop_unpoisoning.c: Use result
     of __builtin_alloca.
     * c-c++-common/asan/pr88619.c: Likewise.
     * g++.dg/overload/using2.C: Likewise for malloc.
     * gcc.dg/attr-alloc_size-5.c: Add new dg-warning.
     * gcc.dg/nonnull-3.c: Use result of __builtin_strdup.
     * gcc.dg/pr43643.c: Likewise.
     * gcc.dg/pr59717.c: Likewise for calloc.
     * gcc.dg/torture/pr71816.c: Likewise.
     * gcc.dg/tree-ssa/pr78886.c: Likewise.
     * gcc.dg/tree-ssa/pr79697.c: Likewise.
     * gcc.dg/pr78902.c: New test.
---
   gcc/builtin-attrs.def                         | 37 ++++++++++++-------
   gcc/builtins.def                              | 14 +++----
   .../asan/alloca_loop_unpoisoning.c            |  2 +-
   gcc/testsuite/c-c++-common/asan/pr88619.c     |  2 +-
   gcc/testsuite/g++.dg/overload/using2.C        |  2 +-
   gcc/testsuite/gcc.dg/attr-alloc_size-5.c      |  2 +-
   gcc/testsuite/gcc.dg/nonnull-3.c              |  4 +-
   gcc/testsuite/gcc.dg/pr43643.c                |  6 +--
   gcc/testsuite/gcc.dg/pr59717.c                |  8 ++--
   gcc/testsuite/gcc.dg/pr78902.c                | 14 +++++++
   gcc/testsuite/gcc.dg/torture/pr71816.c        |  2 +-
   gcc/testsuite/gcc.dg/tree-ssa/pr78886.c       |  2 +-
   gcc/testsuite/gcc.dg/tree-ssa/pr79697.c       |  6 +--
   13 files changed, 62 insertions(+), 39 deletions(-)
   create mode 100644 gcc/testsuite/gcc.dg/pr78902.c





Reply via email to