Add warn_unused_result for malloc-like functions (PR tree-optimization/78902).
authorMartin Liska <mliska@suse.cz>
Fri, 7 Jun 2019 05:33:11 +0000 (07:33 +0200)
committerMartin Liska <marxin@gcc.gnu.org>
Fri, 7 Jun 2019 05:33:11 +0000 (05:33 +0000)
commitb8e2acff118bfa0dcd3aaf299e1f78dfc5266cbd
treee290bc247d689b3309c4c50784ecfd7132849bfa
parentc437d2d437be4be232e44b58e2e0c8d7ab40e175
Add warn_unused_result for malloc-like functions (PR tree-optimization/78902).

2019-06-07  Martin Liska  <mliska@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.
2019-06-07  Martin Liska  <mliska@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.

From-SVN: r272028
15 files changed:
gcc/ChangeLog
gcc/builtin-attrs.def
gcc/builtins.def
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/asan/alloca_loop_unpoisoning.c
gcc/testsuite/c-c++-common/asan/pr88619.c
gcc/testsuite/g++.dg/overload/using2.C
gcc/testsuite/gcc.dg/attr-alloc_size-5.c
gcc/testsuite/gcc.dg/nonnull-3.c
gcc/testsuite/gcc.dg/pr43643.c
gcc/testsuite/gcc.dg/pr59717.c
gcc/testsuite/gcc.dg/pr78902.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr71816.c
gcc/testsuite/gcc.dg/tree-ssa/pr78886.c
gcc/testsuite/gcc.dg/tree-ssa/pr79697.c