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?

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.)

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