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

index d9e27d11545d735e59f7e161a11e1cc783157339..7a21c939ac57d529170e3d278ecacd2ce9a5aad3 100644 (file)
@@ -1,3 +1,37 @@
+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-06  Jim Wilson  <jimw@sifive.com>
 
        PR target/89955
index 204141f6c53ef6a595832a98893894afe8ace793..39d1395f42abeca05b43ce2e079968227375913a 100644 (file)
@@ -118,6 +118,7 @@ DEF_ATTR_IDENT (ATTR_TM_REGPARM, "*tm regparm")
 DEF_ATTR_IDENT (ATTR_TM_TMPURE, "transaction_pure")
 DEF_ATTR_IDENT (ATTR_RETURNS_TWICE, "returns_twice")
 DEF_ATTR_IDENT (ATTR_RETURNS_NONNULL, "returns_nonnull")
+DEF_ATTR_IDENT (ATTR_WARN_UNUSED_RESULT, "warn_unused_result")
 
 DEF_ATTR_TREE_LIST (ATTR_NOVOPS_LIST, ATTR_NOVOPS, ATTR_NULL, ATTR_NULL)
 
@@ -157,8 +158,10 @@ DEF_ATTR_TREE_LIST (ATTR_CONST_NORETURN_NOTHROW_LEAF_COLD_LIST, ATTR_COLD,\
                        ATTR_NULL, ATTR_CONST_NORETURN_NOTHROW_LEAF_LIST)
 DEF_ATTR_TREE_LIST (ATTR_MALLOC_NOTHROW_LIST, ATTR_MALLOC,     \
                        ATTR_NULL, ATTR_NOTHROW_LIST)
-DEF_ATTR_TREE_LIST (ATTR_MALLOC_NOTHROW_LEAF_LIST, ATTR_MALLOC,        \
+DEF_ATTR_TREE_LIST (ATTR_WARN_UNUSED_RESULT_NOTHROW_LEAF_LIST, ATTR_WARN_UNUSED_RESULT,        \
                        ATTR_NULL, ATTR_NOTHROW_LEAF_LIST)
+DEF_ATTR_TREE_LIST (ATTR_MALLOC_WARN_UNUSED_RESULT_NOTHROW_LEAF_LIST, ATTR_MALLOC,     \
+                       ATTR_NULL, ATTR_WARN_UNUSED_RESULT_NOTHROW_LEAF_LIST)
 DEF_ATTR_TREE_LIST (ATTR_SENTINEL_NOTHROW_LIST, ATTR_SENTINEL, \
                        ATTR_NULL, ATTR_NOTHROW_LIST)
 DEF_ATTR_TREE_LIST (ATTR_SENTINEL_NOTHROW_LEAF_LIST, ATTR_SENTINEL,    \
@@ -170,24 +173,26 @@ DEF_ATTR_TREE_LIST (ATTR_COLD_CONST_NORETURN_NOTHROW_LEAF_LIST, ATTR_CONST,\
    with _SIZE_1, or second argument with _SIZE_2, specifies the size
    of the allocated object.  */
 DEF_ATTR_TREE_LIST (ATTR_MALLOC_SIZE_1_NOTHROW_LIST, ATTR_ALLOC_SIZE,  \
-                       ATTR_LIST_1, ATTR_MALLOC_NOTHROW_LIST)
-DEF_ATTR_TREE_LIST (ATTR_ALLOC_SIZE_2_NOTHROW_LIST, ATTR_ALLOC_SIZE,   \
-                       ATTR_LIST_2, ATTR_MALLOC_NOTHROW_LIST)
-DEF_ATTR_TREE_LIST (ATTR_MALLOC_SIZE_1_NOTHROW_LEAF_LIST, ATTR_ALLOC_SIZE, \
-                       ATTR_LIST_1, ATTR_MALLOC_NOTHROW_LEAF_LIST)
+                   ATTR_LIST_1, ATTR_MALLOC_NOTHROW_LIST)
+DEF_ATTR_TREE_LIST (ATTR_MALLOC_WARN_UNUSED_RESULT_NOTHROW_LIST, ATTR_WARN_UNUSED_RESULT,      \
+                   ATTR_NULL, ATTR_MALLOC_NOTHROW_LIST)
+DEF_ATTR_TREE_LIST (ATTR_ALLOC_WARN_UNUSED_RESULT_SIZE_2_NOTHROW_LIST, ATTR_ALLOC_SIZE,        \
+                   ATTR_LIST_2, ATTR_MALLOC_WARN_UNUSED_RESULT_NOTHROW_LIST)
+DEF_ATTR_TREE_LIST (ATTR_MALLOC_WARN_UNUSED_RESULT_SIZE_1_NOTHROW_LEAF_LIST, ATTR_ALLOC_SIZE, \
+                   ATTR_LIST_1, ATTR_MALLOC_WARN_UNUSED_RESULT_NOTHROW_LEAF_LIST)
 /* Alloca is just like malloc except that it never returns null.  */
-DEF_ATTR_TREE_LIST (ATTR_ALLOCA_SIZE_1_NOTHROW_LEAF_LIST, ATTR_RETURNS_NONNULL,
-                   ATTR_NULL, ATTR_MALLOC_SIZE_1_NOTHROW_LEAF_LIST)
+DEF_ATTR_TREE_LIST (ATTR_ALLOCA_WARN_UNUSED_RESULT_SIZE_1_NOTHROW_LEAF_LIST, ATTR_RETURNS_NONNULL,
+                   ATTR_NULL, ATTR_MALLOC_WARN_UNUSED_RESULT_SIZE_1_NOTHROW_LEAF_LIST)
 
 /* Allocation functions like calloc the product of whose first two arguments
    specifies the size of the allocated object.  */
-DEF_ATTR_TREE_LIST (ATTR_MALLOC_SIZE_1_2_NOTHROW_LEAF_LIST, ATTR_ALLOC_SIZE, \
-                       ATTR_LIST_1_2, ATTR_MALLOC_NOTHROW_LEAF_LIST)
+DEF_ATTR_TREE_LIST (ATTR_MALLOC_WARN_UNUSED_RESULT_SIZE_1_2_NOTHROW_LEAF_LIST, ATTR_ALLOC_SIZE, \
+                   ATTR_LIST_1_2, ATTR_MALLOC_WARN_UNUSED_RESULT_NOTHROW_LEAF_LIST)
 
 /* Allocation functions like realloc whose second argument specifies
    the size of the allocated object.  */
-DEF_ATTR_TREE_LIST (ATTR_ALLOC_SIZE_2_NOTHROW_LEAF_LIST, ATTR_ALLOC_SIZE, \
-                       ATTR_LIST_2, ATTR_NOTHROW_LEAF_LIST)
+DEF_ATTR_TREE_LIST (ATTR_ALLOC_WARN_UNUSED_RESULT_SIZE_2_NOTHROW_LEAF_LIST, ATTR_ALLOC_SIZE, \
+                   ATTR_LIST_2, ATTR_WARN_UNUSED_RESULT_NOTHROW_LEAF_LIST)
 
 /* Functions whose pointer parameter(s) are all nonnull.  */
 DEF_ATTR_TREE_LIST (ATTR_NONNULL_LIST, ATTR_NONNULL, ATTR_NULL, ATTR_NULL)
@@ -290,11 +295,15 @@ DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_NONNULL, ATTR_PURE, ATTR_NULL, \
 DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_NONNULL_LEAF, ATTR_PURE, ATTR_NULL, \
                        ATTR_NOTHROW_NONNULL_LEAF)
 /* Nothrow malloc functions whose pointer parameter(s) are all nonnull.  */
-DEF_ATTR_TREE_LIST (ATTR_MALLOC_NOTHROW_NONNULL, ATTR_MALLOC, ATTR_NULL, \
+DEF_ATTR_TREE_LIST (ATTR_WARN_UNUSED_RESULT_NOTHROW_NONNULL, ATTR_WARN_UNUSED_RESULT, ATTR_NULL, \
                        ATTR_NOTHROW_NONNULL)
+DEF_ATTR_TREE_LIST (ATTR_MALLOC_WARN_UNUSED_RESULT_NOTHROW_NONNULL, ATTR_MALLOC, ATTR_NULL, \
+                       ATTR_WARN_UNUSED_RESULT_NOTHROW_NONNULL)
 /* Nothrow malloc leaf functions whose pointer parameter(s) are all nonnull.  */
-DEF_ATTR_TREE_LIST (ATTR_MALLOC_NOTHROW_NONNULL_LEAF, ATTR_MALLOC, ATTR_NULL, \
+DEF_ATTR_TREE_LIST (ATTR_WARN_UNUSED_RESULT_NOTHROW_NONNULL_LEAF, ATTR_WARN_UNUSED_RESULT, ATTR_NULL, \
                        ATTR_NOTHROW_NONNULL_LEAF)
+DEF_ATTR_TREE_LIST (ATTR_MALLOC_WARN_UNUSED_RESULT_NOTHROW_NONNULL_LEAF, ATTR_MALLOC, ATTR_NULL, \
+                       ATTR_WARN_UNUSED_RESULT_NOTHROW_NONNULL_LEAF)
 
 /* Construct a tree for the format attribute (and implicitly nonnull).  */
 #define DEF_FORMAT_ATTRIBUTE(TYPE, FA, VALUES)                          \
index c92292aeab9da21cb8268e6483078a6be9e49d95..6d41bdb4f44e874d2a9af8934e474388296b63c5 100644 (file)
@@ -288,7 +288,7 @@ DEF_C99_BUILTIN        (BUILT_IN_ACOSH, "acosh", BT_FN_DOUBLE_DOUBLE, ATTR_MATHF
 DEF_C99_BUILTIN        (BUILT_IN_ACOSHF, "acoshf", BT_FN_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING_ERRNO)
 DEF_C99_BUILTIN        (BUILT_IN_ACOSHL, "acoshl", BT_FN_LONGDOUBLE_LONGDOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO)
 DEF_C99_C90RES_BUILTIN (BUILT_IN_ACOSL, "acosl", BT_FN_LONGDOUBLE_LONGDOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO)
-DEF_C11_BUILTIN        (BUILT_IN_ALIGNED_ALLOC, "aligned_alloc", BT_FN_PTR_SIZE_SIZE, ATTR_ALLOC_SIZE_2_NOTHROW_LIST)
+DEF_C11_BUILTIN        (BUILT_IN_ALIGNED_ALLOC, "aligned_alloc", BT_FN_PTR_SIZE_SIZE, ATTR_ALLOC_WARN_UNUSED_RESULT_SIZE_2_NOTHROW_LIST)
 DEF_LIB_BUILTIN        (BUILT_IN_ASIN, "asin", BT_FN_DOUBLE_DOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO)
 DEF_C99_C90RES_BUILTIN (BUILT_IN_ASINF, "asinf", BT_FN_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING_ERRNO)
 DEF_C99_BUILTIN        (BUILT_IN_ASINH, "asinh", BT_FN_DOUBLE_DOUBLE, ATTR_MATHFN_FPROUNDING)
@@ -702,8 +702,8 @@ DEF_LIB_BUILTIN        (BUILT_IN_STRCHR, "strchr", BT_FN_STRING_CONST_STRING_INT
 DEF_LIB_BUILTIN        (BUILT_IN_STRCMP, "strcmp", BT_FN_INT_CONST_STRING_CONST_STRING, ATTR_PURE_NOTHROW_NONNULL_LEAF)
 DEF_LIB_BUILTIN        (BUILT_IN_STRCPY, "strcpy", BT_FN_STRING_STRING_CONST_STRING, ATTR_RET1_NOTHROW_NONNULL_LEAF)
 DEF_LIB_BUILTIN        (BUILT_IN_STRCSPN, "strcspn", BT_FN_SIZE_CONST_STRING_CONST_STRING, ATTR_PURE_NOTHROW_NONNULL_LEAF)
-DEF_EXT_LIB_BUILTIN    (BUILT_IN_STRDUP, "strdup", BT_FN_STRING_CONST_STRING, ATTR_MALLOC_NOTHROW_NONNULL_LEAF)
-DEF_EXT_LIB_BUILTIN    (BUILT_IN_STRNDUP, "strndup", BT_FN_STRING_CONST_STRING_SIZE, ATTR_MALLOC_NOTHROW_NONNULL_LEAF)
+DEF_EXT_LIB_BUILTIN    (BUILT_IN_STRDUP, "strdup", BT_FN_STRING_CONST_STRING, ATTR_MALLOC_WARN_UNUSED_RESULT_NOTHROW_NONNULL_LEAF)
+DEF_EXT_LIB_BUILTIN    (BUILT_IN_STRNDUP, "strndup", BT_FN_STRING_CONST_STRING_SIZE, ATTR_MALLOC_WARN_UNUSED_RESULT_NOTHROW_NONNULL_LEAF)
 DEF_LIB_BUILTIN        (BUILT_IN_STRLEN, "strlen", BT_FN_SIZE_CONST_STRING, ATTR_PURE_NOTHROW_NONNULL_LEAF)
 DEF_EXT_LIB_BUILTIN    (BUILT_IN_STRNCASECMP, "strncasecmp", BT_FN_INT_CONST_STRING_CONST_STRING_SIZE, ATTR_PURE_NOTHROW_NONNULL_LEAF)
 DEF_LIB_BUILTIN        (BUILT_IN_STRNCAT, "strncat", BT_FN_STRING_STRING_CONST_STRING_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
@@ -811,7 +811,7 @@ DEF_GCC_BUILTIN        (BUILT_IN_UMULLL_OVERFLOW, "umulll_overflow", BT_FN_BOOL_
 DEF_LIB_BUILTIN        (BUILT_IN_ABORT, "abort", BT_FN_VOID, ATTR_TMPURE_NORETURN_NOTHROW_LEAF_COLD_LIST)
 DEF_LIB_BUILTIN        (BUILT_IN_ABS, "abs", BT_FN_INT_INT, ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_GCC_BUILTIN        (BUILT_IN_AGGREGATE_INCOMING_ADDRESS, "aggregate_incoming_address", BT_FN_PTR_VAR, ATTR_LEAF_LIST)
-DEF_EXT_LIB_BUILTIN    (BUILT_IN_ALLOCA, "alloca", BT_FN_PTR_SIZE, ATTR_ALLOCA_SIZE_1_NOTHROW_LEAF_LIST)
+DEF_EXT_LIB_BUILTIN    (BUILT_IN_ALLOCA, "alloca", BT_FN_PTR_SIZE, ATTR_ALLOCA_WARN_UNUSED_RESULT_SIZE_1_NOTHROW_LEAF_LIST)
 DEF_GCC_BUILTIN        (BUILT_IN_APPLY, "apply", BT_FN_PTR_PTR_FN_VOID_VAR_PTR_SIZE, ATTR_NULL)
 DEF_GCC_BUILTIN        (BUILT_IN_APPLY_ARGS, "apply_args", BT_FN_PTR_VAR, ATTR_LEAF_LIST)
 DEF_GCC_BUILTIN        (BUILT_IN_BSWAP16, "bswap16", BT_FN_UINT16_UINT16, ATTR_CONST_NOTHROW_LEAF_LIST)
@@ -819,7 +819,7 @@ DEF_GCC_BUILTIN        (BUILT_IN_BSWAP32, "bswap32", BT_FN_UINT32_UINT32, ATTR_C
 DEF_GCC_BUILTIN        (BUILT_IN_BSWAP64, "bswap64", BT_FN_UINT64_UINT64, ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_EXT_LIB_BUILTIN    (BUILT_IN_CLEAR_CACHE, "__clear_cache", BT_FN_VOID_PTR_PTR, ATTR_NOTHROW_LEAF_LIST)
 /* [trans-mem]: Adjust BUILT_IN_TM_CALLOC if BUILT_IN_CALLOC is changed.  */
-DEF_LIB_BUILTIN        (BUILT_IN_CALLOC, "calloc", BT_FN_PTR_SIZE_SIZE, ATTR_MALLOC_SIZE_1_2_NOTHROW_LEAF_LIST)
+DEF_LIB_BUILTIN        (BUILT_IN_CALLOC, "calloc", BT_FN_PTR_SIZE_SIZE, ATTR_MALLOC_WARN_UNUSED_RESULT_SIZE_1_2_NOTHROW_LEAF_LIST)
 DEF_GCC_BUILTIN        (BUILT_IN_CLASSIFY_TYPE, "classify_type", BT_FN_INT_VAR, ATTR_LEAF_LIST)
 DEF_GCC_BUILTIN        (BUILT_IN_CLZ, "clz", BT_FN_INT_UINT, ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_GCC_BUILTIN        (BUILT_IN_CLZIMAX, "clzimax", BT_FN_INT_UINTMAX, ATTR_CONST_NOTHROW_LEAF_LIST)
@@ -896,7 +896,7 @@ DEF_LIB_BUILTIN        (BUILT_IN_LABS, "labs", BT_FN_LONG_LONG, ATTR_CONST_NOTHR
 DEF_C99_BUILTIN        (BUILT_IN_LLABS, "llabs", BT_FN_LONGLONG_LONGLONG, ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_GCC_BUILTIN        (BUILT_IN_LONGJMP, "longjmp", BT_FN_VOID_PTR_INT, ATTR_NORETURN_NOTHROW_LIST)
 /* [trans-mem]: Adjust BUILT_IN_TM_MALLOC if BUILT_IN_MALLOC is changed.  */
-DEF_LIB_BUILTIN        (BUILT_IN_MALLOC, "malloc", BT_FN_PTR_SIZE, ATTR_MALLOC_SIZE_1_NOTHROW_LEAF_LIST)
+DEF_LIB_BUILTIN        (BUILT_IN_MALLOC, "malloc", BT_FN_PTR_SIZE, ATTR_MALLOC_WARN_UNUSED_RESULT_SIZE_1_NOTHROW_LEAF_LIST)
 DEF_GCC_BUILTIN        (BUILT_IN_NEXT_ARG, "next_arg", BT_FN_PTR_VAR, ATTR_LEAF_LIST)
 DEF_GCC_BUILTIN        (BUILT_IN_PARITY, "parity", BT_FN_INT_UINT, ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_GCC_BUILTIN        (BUILT_IN_PARITYIMAX, "parityimax", BT_FN_INT_UINTMAX, ATTR_CONST_NOTHROW_LEAF_LIST)
@@ -908,7 +908,7 @@ DEF_GCC_BUILTIN        (BUILT_IN_POPCOUNTL, "popcountl", BT_FN_INT_ULONG, ATTR_C
 DEF_GCC_BUILTIN        (BUILT_IN_POPCOUNTLL, "popcountll", BT_FN_INT_ULONGLONG, ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_EXT_LIB_BUILTIN    (BUILT_IN_POSIX_MEMALIGN, "posix_memalign", BT_FN_INT_PTRPTR_SIZE_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
 DEF_GCC_BUILTIN        (BUILT_IN_PREFETCH, "prefetch", BT_FN_VOID_CONST_PTR_VAR, ATTR_NOVOPS_LEAF_LIST)
-DEF_LIB_BUILTIN        (BUILT_IN_REALLOC, "realloc", BT_FN_PTR_PTR_SIZE, ATTR_ALLOC_SIZE_2_NOTHROW_LEAF_LIST)
+DEF_LIB_BUILTIN        (BUILT_IN_REALLOC, "realloc", BT_FN_PTR_PTR_SIZE, ATTR_ALLOC_WARN_UNUSED_RESULT_SIZE_2_NOTHROW_LEAF_LIST)
 DEF_GCC_BUILTIN        (BUILT_IN_RETURN, "return", BT_FN_VOID_PTR, ATTR_NORETURN_NOTHROW_LEAF_LIST)
 DEF_GCC_BUILTIN        (BUILT_IN_RETURN_ADDRESS, "return_address", BT_FN_PTR_UINT, ATTR_LEAF_LIST)
 DEF_GCC_BUILTIN        (BUILT_IN_SAVEREGS, "saveregs", BT_FN_PTR_VAR, ATTR_NULL)
index b348a5097d23a1e88c8123c3fded883f9af8e62b..d5f5cd469f0c1e76e14b79eee122a9ce0a6473f4 100644 (file)
@@ -1,3 +1,19 @@
+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.
+
 2019-06-06  Iain Sandoe  <iain@sandoe.co.uk>
 
        * g++.dg/cpp0x/alignas4.C: Amend test to check for zerofill syntax
index 55345fdb3a5843f61ad3d06be6d0bc871a984934..3050d3ba94b1f640a7cf592671231ab9ce2e796a 100644 (file)
@@ -17,7 +17,7 @@ __attribute__((noinline)) void foo(int len) {
   top = &x;
   volatile char array[len];
   assert(!((uintptr_t) array & 31L));
-  __builtin_alloca(len);
+  void *p = __builtin_alloca(len);
   for (int i = 0; i < thirty_two; ++i) {
     char array[i];
     bot = array;
index aab8a4c4c9cb2b9e0bb1bf3a814214e6b34ddf3c..fd3fbf1a73a68f1e88c64065eee8f5f0b7d4f965 100644 (file)
@@ -10,5 +10,5 @@ main ()
   A b;
   int *p = &b;
   *(p - 1) = 123;
-  __builtin_alloca (b);
+  void *p2 = __builtin_alloca (b);
 }
index b1d52f7cf437c645a8b3fb995b3aa09e87a5df4d..edfd1a10ac46a09c767eae4e7ca206aa9c0ec3a0 100644 (file)
@@ -69,7 +69,7 @@ using std::C3; using other::C3;
   long C3 (long) throw ();
 
 int main () {
-  malloc (0);
+  void *p = malloc (0);
   exit (0);
 
   _exit (0); // { dg-error "ambiguous" }
index 26ee43f87deeb694b72922be634e25cfb370a173..7aa7cbf0c72fcec49e80ef3109c5456ffeeff8e6 100644 (file)
@@ -230,5 +230,5 @@ test_alloca (size_t n)
 {
   extern void* alloca (size_t);
 
-  alloca (0);
+  alloca (0); /* { dg-warning "ignoring return value of '.*' declared with attribute 'warn_unused_result'" } */
 }
index 040248c53aa7a19fe4b6209219d20d6aa0227cf9..6f7bc4f429517ede15ffb304e1bee626c3172cab 100644 (file)
@@ -56,8 +56,8 @@ foo (void *p, char *s)
   __builtin_strspn (s, NULL);  /* { dg-warning "null" "null pointer check" } */
   __builtin_strchr (NULL, 16);  /* { dg-warning "null" "null pointer check" } */
   __builtin_strrchr (NULL, 16);  /* { dg-warning "null" "null pointer check" } */
-  __builtin_strdup (NULL);  /* { dg-warning "null" "null pointer check" } */
-  __builtin_strndup (NULL, 16);  /* { dg-warning "null" "null pointer check" } */
+  void *p1 = __builtin_strdup (NULL);  /* { dg-warning "null" "null pointer check" } */
+  void *p2 = __builtin_strndup (NULL, 16);  /* { dg-warning "null" "null pointer check" } */
 
   __builtin_nan (NULL);  /* { dg-warning "null" "null pointer check" } */
   __builtin_nanf (NULL);  /* { dg-warning "null" "null pointer check" } */
index b0c57c0a6dc3e891d2984a27b980fcaf5aeb1ece..43896abd85af2442a1ad6d00bb28dcdbc037839e 100644 (file)
@@ -10,9 +10,9 @@ extern char *strdup (const char *);
 void
 func(char *a, char *b, char *c)
 {
-  strdup(a);
-  strdup(b);
-  strdup(c);
+  void *p = strdup(a);
+  p = strdup(b);
+  p = strdup(c);
 }
 
 int
index e49020aa063412d888141eb91cdeaf1b03bd599e..64e4f32197f054e40302be4280c984ba482bd045 100644 (file)
@@ -242,7 +242,7 @@ stdlib (void *p, void *q, __SIZE_TYPE__ sz)
 {
   abort (); /* { dg-warning "incompatible implicit" } */
   /* { dg-message "include ..stdlib.h.." "" { target *-*-* } .-1 } */
-  calloc (sz, 1); /* { dg-warning "incompatible implicit" } */
+  void *p1 = calloc (sz, 1); /* { dg-warning "incompatible implicit" } */
   /* { dg-message "include ..stdlib.h.." "" { target *-*-* } .-1 } */
   exit (1); /* { dg-warning "incompatible implicit" } */
   /* { dg-message "include ..stdlib.h.." "" { target *-*-* } .-1 } */
@@ -252,11 +252,11 @@ stdlib (void *p, void *q, __SIZE_TYPE__ sz)
   /* { dg-message "include ..stdlib.h.." "" { target *-*-* } .-1 } */
   llabs (1LL); /* { dg-warning "incompatible implicit" } */
   /* { dg-message "include ..stdlib.h.." "" { target *-*-* } .-1 } */
-  malloc (sz); /* { dg-warning "incompatible implicit" } */
+  void *p2 = malloc (sz); /* { dg-warning "incompatible implicit" } */
   /* { dg-message "include ..stdlib.h.." "" { target *-*-* } .-1 } */
-  realloc (p, sz); /* { dg-warning "incompatible implicit" } */
+  void *p3 = realloc (p, sz); /* { dg-warning "incompatible implicit" } */
   /* { dg-message "include ..stdlib.h.." "" { target *-*-* } .-1 } */
-  aligned_alloc (sz, sz); /* { dg-warning "incompatible implicit" } */
+  void *p4 = aligned_alloc (sz, sz); /* { dg-warning "incompatible implicit" } */
   /* { dg-message "include ..stdlib.h.." "" { target *-*-* } .-1 } */
 }
 
diff --git a/gcc/testsuite/gcc.dg/pr78902.c b/gcc/testsuite/gcc.dg/pr78902.c
new file mode 100644 (file)
index 0000000..49efc97
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+
+void *ptr;
+
+void foo(void)
+{
+ __builtin_malloc (1); /* { dg-warning "ignoring return value of '__builtin_malloc' declared with attribute 'warn_unused_result'" } */
+ __builtin_calloc (10, 20); /* { dg-warning "ignoring return value of '__builtin_calloc' declared with attribute 'warn_unused_result'" } */
+ __builtin_alloca (10); /* { dg-warning "ignoring return value of '__builtin_alloca' declared with attribute 'warn_unused_result'" } */
+ __builtin_realloc (ptr, 100); /* { dg-warning "ignoring return value of '__builtin_realloc' declared with attribute 'warn_unused_result'" } */
+ __builtin_aligned_alloc (10, 16); /* { dg-warning "ignoring return value of '__builtin_aligned_alloc' declared with attribute 'warn_unused_result'" } */
+ __builtin_strdup ("pes"); /* { dg-warning "ignoring return value of '__builtin_strdup' declared with attribute 'warn_unused_result'" } */
+ __builtin_strndup ("pes", 10); /* { dg-warning "ignoring return value of '__builtin_strndup' declared with attribute 'warn_unused_result'" } */
+}
index 179fad85cd19acd0c7f4318228410ecb94154b3b..be37ad921bddcacceddff700859258d8195d3f85 100644 (file)
@@ -11,7 +11,7 @@ void *realloc();
 int ext2fs_resize_mem(void *p1) {
     int size = 0;
     memcpy(&ext2fs_resize_mem_p, p1, sizeof(ext2fs_resize_mem_p));
-    realloc(&ext2fs_resize_mem_p, size);
+    void *p = realloc(&ext2fs_resize_mem_p, size);
     return 0;
 }
 struct ext2_icount_el *insert_icount_el() {
index de22b83ad25750e52af32ca74500be197fce8e3a..7f62891b77bde749944a5ccf3e8c47d9ff76a597 100644 (file)
@@ -7,6 +7,6 @@ void *malloc(size_t x);
 void foo(void)
 {
  volatile int i;
- malloc(1);
void *p = malloc(1);
  i;
 }
index 973ec0dc1937a0cfa4c0d420c6e3387cba9c3af9..e62efd5de617cc91ac0032945085aa27caa4c53b 100644 (file)
@@ -3,17 +3,17 @@
 
 void f(void)
 {
-  __builtin_strdup ("abc");
+  __builtin_strdup ("abc"); /* { dg-warning "ignoring return value of '__builtin_strdup' declared with attribute 'warn_unused_result'" } */
 }
 
 void g(void)
 {
-  __builtin_strndup ("abc", 3);
+  __builtin_strndup ("abc", 3); /* { dg-warning "ignoring return value of '__builtin_strndup' declared with attribute 'warn_unused_result'" } */
 }
 
 void h(void)
 {
-  __builtin_realloc (0, 10);
+  __builtin_realloc (0, 10); /* { dg-warning "ignoring return value of '__builtin_realloc' declared with attribute 'warn_unused_result'" } */
 }
 
 /* { dg-final { scan-tree-dump "Deleting : __builtin_strdup" "cddce1" } } */