diff mbox series

[2/2] Add warn_unused_result attribute for memory-related, functions in libiberty.

Message ID f79544de-4af1-2358-03f1-9396bdb3884e@suse.cz
State New
Headers show
Series [1/2] Add alloc_size for libiberty memory allocation functions. | expand

Commit Message

Martin Liška June 7, 2019, 7:08 a.m. UTC
Part 2.

Comments

Jeff Law June 7, 2019, 5:13 p.m. UTC | #1
On 6/7/19 1:08 AM, Martin Liška wrote:
> Part 2.
> 
> 
> 0002-Add-warn_unused_result-attribute-for-memory-related-.patch
> 
> From 52f1ae0aa86b11fc3ae17e3e224b58aa8b8519a6 Mon Sep 17 00:00:00 2001
> From: Martin Liska <mliska@suse.cz>
> Date: Fri, 7 Jun 2019 08:14:17 +0200
> Subject: [PATCH 2/2] Add warn_unused_result attribute for memory-related
>  functions in libiberty.
> 
> include/ChangeLog:
> 
> 2019-06-07  Martin Liska  <mliska@suse.cz>
> 
> 	* ansidecl.h (ATTRIBUTE_WARN_UNUSED_RESULT): New macro.
> 	* libiberty.h (xmalloc): Use it.
> 	(xrealloc): Likewise.
> 	(xcalloc): Likewise.
> 	(xstrdup): Likewise.
> 	(xstrndup): Likewise.
> 	(xmemdup): Likewise.
OK
jeff
diff mbox series

Patch

From 52f1ae0aa86b11fc3ae17e3e224b58aa8b8519a6 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Fri, 7 Jun 2019 08:14:17 +0200
Subject: [PATCH 2/2] Add warn_unused_result attribute for memory-related
 functions in libiberty.

include/ChangeLog:

2019-06-07  Martin Liska  <mliska@suse.cz>

	* ansidecl.h (ATTRIBUTE_WARN_UNUSED_RESULT): New macro.
	* libiberty.h (xmalloc): Use it.
	(xrealloc): Likewise.
	(xcalloc): Likewise.
	(xstrdup): Likewise.
	(xstrndup): Likewise.
	(xmemdup): Likewise.
---
 include/ansidecl.h  |  9 +++++++++
 include/libiberty.h | 12 ++++++------
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/include/ansidecl.h b/include/ansidecl.h
index 3035c33b8aa..445c8c3fb58 100644
--- a/include/ansidecl.h
+++ b/include/ansidecl.h
@@ -317,6 +317,15 @@  So instead we use the macro below and test it against specific values.  */
 #endif
 #endif
 
+/* Attribute `warn_unused_result' was valid as of gcc 3.3.  */
+#ifndef ATTRIBUTE_WARN_UNUSED_RESULT
+# if GCC_VERSION >= 3003
+#  define ATTRIBUTE_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
+# else
+#  define ATTRIBUTE_WARN_UNUSED_RESULT
+# endif
+#endif
+
 /* We use __extension__ in some places to suppress -pedantic warnings
    about GCC extensions.  This feature didn't work properly before
    gcc 2.8.  */
diff --git a/include/libiberty.h b/include/libiberty.h
index 0870163d945..635519e088a 100644
--- a/include/libiberty.h
+++ b/include/libiberty.h
@@ -310,30 +310,30 @@  extern void xmalloc_failed (size_t) ATTRIBUTE_NORETURN;
    message to stderr (using the name set by xmalloc_set_program_name,
    if any) and then call xexit.  */
 
-extern void *xmalloc (size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_RESULT_SIZE_1;
+extern void *xmalloc (size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_RESULT_SIZE_1 ATTRIBUTE_WARN_UNUSED_RESULT;
 
 /* Reallocate memory without fail.  This works like xmalloc.  Note,
    realloc type functions are not suitable for attribute malloc since
    they may return the same address across multiple calls. */
 
-extern void *xrealloc (void *, size_t) ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_RESULT_SIZE_2;
+extern void *xrealloc (void *, size_t) ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_RESULT_SIZE_2 ATTRIBUTE_WARN_UNUSED_RESULT;
 
 /* Allocate memory without fail and set it to zero.  This works like
    xmalloc.  */
 
-extern void *xcalloc (size_t, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_RESULT_SIZE_1_2;
+extern void *xcalloc (size_t, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_RESULT_SIZE_1_2 ATTRIBUTE_WARN_UNUSED_RESULT;
 
 /* Copy a string into a memory buffer without fail.  */
 
-extern char *xstrdup (const char *) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL;
+extern char *xstrdup (const char *) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_WARN_UNUSED_RESULT;
 
 /* Copy at most N characters from string into a buffer without fail.  */
 
-extern char *xstrndup (const char *, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL;
+extern char *xstrndup (const char *, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_WARN_UNUSED_RESULT;
 
 /* Copy an existing memory buffer to a new memory buffer without fail.  */
 
-extern void *xmemdup (const void *, size_t, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL;
+extern void *xmemdup (const void *, size_t, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_WARN_UNUSED_RESULT;
 
 /* Physical memory routines.  Return values are in BYTES.  */
 extern double physmem_total (void);
-- 
2.21.0