diff mbox series

[1/2] Add alloc_size for libiberty memory allocation functions.

Message ID 236f0327-c3b1-608e-08fd-78243801d6eb@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:07 a.m. UTC
Hi.

I'm sending 2 follow up patches that touch libiberty memory allocation
functions.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

Comments

Jeff Law June 7, 2019, 5:13 p.m. UTC | #1
On 6/7/19 1:07 AM, Martin Liška wrote:
> Hi.
> 
> I'm sending 2 follow up patches that touch libiberty memory allocation
> functions.
> 
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
> 
> Ready to be installed?
> Thanks,
> Martin
> 
> 
> 0001-Add-alloc_size-for-libiberty-memory-allocation-funct.patch
> 
> From bd430388cffe4b72d6be52cbaeda9eb9c8f8a248 Mon Sep 17 00:00:00 2001
> From: Martin Liska <mliska@suse.cz>
> Date: Fri, 7 Jun 2019 08:09:36 +0200
> Subject: [PATCH 1/2] Add alloc_size for libiberty memory allocation functions.
> 
> include/ChangeLog:
> 
> 2019-06-07  Martin Liska  <mliska@suse.cz>
> 
> 	* ansidecl.h:
> 	(ATTRIBUTE_RESULT_SIZE_1): Define new macro.
> 	(ATTRIBUTE_RESULT_SIZE_2): Likewise.
> 	(ATTRIBUTE_RESULT_SIZE_1_2): Likewise.
> 	* libiberty.h (xmalloc): Add RESULT_SIZE attribute.
> 	(xrealloc): Likewise.
> 	(xcalloc): Likewise.
OK.
jeff
diff mbox series

Patch

From bd430388cffe4b72d6be52cbaeda9eb9c8f8a248 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Fri, 7 Jun 2019 08:09:36 +0200
Subject: [PATCH 1/2] Add alloc_size for libiberty memory allocation functions.

include/ChangeLog:

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

	* ansidecl.h:
	(ATTRIBUTE_RESULT_SIZE_1): Define new macro.
	(ATTRIBUTE_RESULT_SIZE_2): Likewise.
	(ATTRIBUTE_RESULT_SIZE_1_2): Likewise.
	* libiberty.h (xmalloc): Add RESULT_SIZE attribute.
	(xrealloc): Likewise.
	(xcalloc): Likewise.
---
 include/ansidecl.h  | 25 +++++++++++++++++++++++++
 include/libiberty.h |  6 +++---
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/include/ansidecl.h b/include/ansidecl.h
index 0395c4d0e19..3035c33b8aa 100644
--- a/include/ansidecl.h
+++ b/include/ansidecl.h
@@ -292,6 +292,31 @@  So instead we use the macro below and test it against specific values.  */
 # endif
 #endif
 
+/* Attribute `alloc_size' was valid as of gcc 4.3.  */
+#ifndef ATTRIBUTE_RESULT_SIZE_1
+# if (GCC_VERSION >= 4003)
+#  define ATTRIBUTE_RESULT_SIZE_1 __attribute__ ((alloc_size (1)))
+# else
+#  define ATTRIBUTE_RESULT_SIZE_1
+#endif
+#endif
+
+#ifndef ATTRIBUTE_RESULT_SIZE_2
+# if (GCC_VERSION >= 4003)
+#  define ATTRIBUTE_RESULT_SIZE_2 __attribute__ ((alloc_size (2)))
+# else
+#  define ATTRIBUTE_RESULT_SIZE_2
+#endif
+#endif
+
+#ifndef ATTRIBUTE_RESULT_SIZE_1_2
+# if (GCC_VERSION >= 4003)
+#  define ATTRIBUTE_RESULT_SIZE_1_2 __attribute__ ((alloc_size (1, 2)))
+# else
+#  define ATTRIBUTE_RESULT_SIZE_1_2
+#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 e11aa97f0ba..0870163d945 100644
--- a/include/libiberty.h
+++ b/include/libiberty.h
@@ -310,18 +310,18 @@  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;
+extern void *xmalloc (size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_RESULT_SIZE_1;
 
 /* 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;
+extern void *xrealloc (void *, size_t) ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_RESULT_SIZE_2;
 
 /* 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;
+extern void *xcalloc (size_t, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_RESULT_SIZE_1_2;
 
 /* Copy a string into a memory buffer without fail.  */
 
-- 
2.21.0