[PATCH] Add warn_unused_result for malloc-like functions (PR tree-optimization/78902).

Jeff Law law@redhat.com
Fri Jun 7 00:02:00 GMT 2019


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.
> 
> Ready to be installed?
> Thanks,
> Martin
> 
> gcc/ChangeLog:
> 
> 2019-06-06  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.
> 
> gcc/testsuite/ChangeLog:
> 
> 2019-06-06  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.
OK.

Any thoughts on whether or not we'd want to IPA propagate this attribute
like we do for the malloc attribute?

jeff
> ---



More information about the Gcc-patches mailing list