diff mbox series

[2/4] Fix GNU coding style.

Message ID 2d5ffb19bb43b80218f7adcce67244e5aa8ab51e.1541405092.git.mliska@suse.cz
State New
Headers show
Series Enhance and fix various issues in -fmem-report | expand

Commit Message

Martin Liška Nov. 2, 2018, 10:37 a.m. UTC
gcc/ChangeLog:

2018-11-02  Martin Liska  <mliska@suse.cz>

	* mem-stats.h (mem_alloc_description::get_list): Fix GNU coding
	style.
	* vec.c: Likewise.
---
 gcc/mem-stats.h | 61 +++++++++++++++++++++----------------------------
 gcc/vec.c       |  1 -
 2 files changed, 26 insertions(+), 36 deletions(-)

Comments

Richard Biener Nov. 5, 2018, 9:53 a.m. UTC | #1
On Mon, Nov 5, 2018 at 9:07 AM marxin <mliska@suse.cz> wrote:
>

OK

> gcc/ChangeLog:
>
> 2018-11-02  Martin Liska  <mliska@suse.cz>
>
>         * mem-stats.h (mem_alloc_description::get_list): Fix GNU coding
>         style.
>         * vec.c: Likewise.
> ---
>  gcc/mem-stats.h | 61 +++++++++++++++++++++----------------------------
>  gcc/vec.c       |  1 -
>  2 files changed, 26 insertions(+), 36 deletions(-)
>
Martin Sebor Nov. 5, 2018, 5:08 p.m. UTC | #2
On 11/02/2018 04:37 AM, marxin wrote:
>
> gcc/ChangeLog:
>
> 2018-11-02  Martin Liska  <mliska@suse.cz>
>
> 	* mem-stats.h (mem_alloc_description::get_list): Fix GNU coding
> 	style.
> 	* vec.c: Likewise.

I have no preference here or even know what the style guide calls
for (nor have I been able to find it) but I've always assumed
the convention for declaring functions that return pointers (and
variables of pointer types) was

   T *func (...);

with a space after the type and before the name) as opposed to
either of:

   T* func (...);
or
   T * func (...);

The former also appears to be dominant style in GCC.

So I'm mostly just curious: is there a recommended or preferred
style or does it not matter?

Thanks
Martin
Martin Liška Nov. 7, 2018, 9:12 a.m. UTC | #3
On 11/5/18 6:08 PM, Martin Sebor wrote:
> On 11/02/2018 04:37 AM, marxin wrote:
>>
>> gcc/ChangeLog:
>>
>> 2018-11-02  Martin Liska  <mliska@suse.cz>
>>
>>     * mem-stats.h (mem_alloc_description::get_list): Fix GNU coding
>>     style.
>>     * vec.c: Likewise.
> 
> I have no preference here or even know what the style guide calls
> for (nor have I been able to find it) but I've always assumed
> the convention for declaring functions that return pointers (and
> variables of pointer types) was

Hi.

> 
>   T *func (...);

Yes, I also like this format.

> 
> with a space after the type and before the name) as opposed to
> either of:
> 
>   T* func (...);
> or
>   T * func (...);
> 
> The former also appears to be dominant style in GCC.
> 
> So I'm mostly just curious: is there a recommended or preferred
> style or does it not matter?

I'm attaching obvious patch that fixes that. Martin can you please send
a patch to our coding style that will clarify that? And maybe I would also
include how operators should be formatted?

bool operator == (const native_float &b) const
or
bool operator== (const native_float &b) const
or
bool operator ==(const native_float &b) const

Thanks,
Martin

> 
> Thanks
> Martin
From 857838dc0fa1fca4b47b6f16aef4cd67db85baa3 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Wed, 7 Nov 2018 10:05:41 +0100
Subject: [PATCH] Fix GNU coding style (V2).

gcc/ChangeLog:

2018-11-07  Martin Liska  <mliska@suse.cz>

	* mem-stats.h: Fix GNU coding style.
---
 gcc/mem-stats.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/gcc/mem-stats.h b/gcc/mem-stats.h
index 10b41651bf3..7e169d6e9fc 100644
--- a/gcc/mem-stats.h
+++ b/gcc/mem-stats.h
@@ -316,23 +316,23 @@ public:
   bool contains_descriptor_for_instance (const void *ptr);
 
   /* Return descriptor for instance PTR.  */
-  T * get_descriptor_for_instance (const void *ptr);
+  T *get_descriptor_for_instance (const void *ptr);
 
   /* Register memory allocation descriptor for container PTR which is
      described by a memory LOCATION.  */
-  T * register_descriptor (const void *ptr, mem_location *location);
+  T *register_descriptor (const void *ptr, mem_location *location);
 
   /* Register memory allocation descriptor for container PTR.  ORIGIN identifies
      type of container and GGC identifes if the allocation is handled in GGC
      memory.  Each location is identified by file NAME, LINE in source code and
      FUNCTION name.  */
-  T * register_descriptor (const void *ptr, mem_alloc_origin origin,
+  T *register_descriptor (const void *ptr, mem_alloc_origin origin,
 			   bool ggc, const char *name, int line,
 			   const char *function);
 
   /* Register instance overhead identified by PTR pointer. Allocation takes
      SIZE bytes.  */
-  T * register_instance_overhead (size_t size, const void *ptr);
+  T *register_instance_overhead (size_t size, const void *ptr);
 
   /* For containers (and GGC) where we want to track every instance object,
      we register allocation of SIZE bytes, identified by PTR pointer, belonging
@@ -342,7 +342,7 @@ public:
   /* Release PTR pointer of SIZE bytes. If REMOVE_FROM_MAP is set to true,
      remove the instance from reverse map.  Return memory usage that belongs
      to this memory description.  */
-  T * release_instance_overhead (void *ptr, size_t size,
+  T *release_instance_overhead (void *ptr, size_t size,
 				 bool remove_from_map = false);
 
   /* Release intance object identified by PTR pointer.  */
@@ -355,7 +355,7 @@ public:
      are filtered by ORIGIN type, LENGTH is return value where we register
      the number of elements in the list. If we want to process custom order,
      CMP comparator can be provided.  */
-  mem_list_t * get_list (mem_alloc_origin origin, unsigned *length,
+  mem_list_t *get_list (mem_alloc_origin origin, unsigned *length,
 			 int (*cmp) (const void *first,
 				     const void *second) = NULL);
Martin Liška Nov. 7, 2018, 9:15 a.m. UTC | #4
The version I've just installed.

M.
From ff99a2f57f3372c66aa25ed0c8e36697b49fee56 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Wed, 7 Nov 2018 10:05:41 +0100
Subject: [PATCH] Fix GNU coding style (V2).

gcc/ChangeLog:

2018-11-07  Martin Liska  <mliska@suse.cz>

	* mem-stats.h: Fix GNU coding style.
---
 gcc/mem-stats.h | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/gcc/mem-stats.h b/gcc/mem-stats.h
index 10b41651bf3..6ab92211cf4 100644
--- a/gcc/mem-stats.h
+++ b/gcc/mem-stats.h
@@ -316,23 +316,23 @@ public:
   bool contains_descriptor_for_instance (const void *ptr);
 
   /* Return descriptor for instance PTR.  */
-  T * get_descriptor_for_instance (const void *ptr);
+  T *get_descriptor_for_instance (const void *ptr);
 
   /* Register memory allocation descriptor for container PTR which is
      described by a memory LOCATION.  */
-  T * register_descriptor (const void *ptr, mem_location *location);
+  T *register_descriptor (const void *ptr, mem_location *location);
 
   /* Register memory allocation descriptor for container PTR.  ORIGIN identifies
      type of container and GGC identifes if the allocation is handled in GGC
      memory.  Each location is identified by file NAME, LINE in source code and
      FUNCTION name.  */
-  T * register_descriptor (const void *ptr, mem_alloc_origin origin,
-			   bool ggc, const char *name, int line,
-			   const char *function);
+  T *register_descriptor (const void *ptr, mem_alloc_origin origin,
+			  bool ggc, const char *name, int line,
+			  const char *function);
 
   /* Register instance overhead identified by PTR pointer. Allocation takes
      SIZE bytes.  */
-  T * register_instance_overhead (size_t size, const void *ptr);
+  T *register_instance_overhead (size_t size, const void *ptr);
 
   /* For containers (and GGC) where we want to track every instance object,
      we register allocation of SIZE bytes, identified by PTR pointer, belonging
@@ -342,8 +342,8 @@ public:
   /* Release PTR pointer of SIZE bytes. If REMOVE_FROM_MAP is set to true,
      remove the instance from reverse map.  Return memory usage that belongs
      to this memory description.  */
-  T * release_instance_overhead (void *ptr, size_t size,
-				 bool remove_from_map = false);
+  T *release_instance_overhead (void *ptr, size_t size,
+				bool remove_from_map = false);
 
   /* Release intance object identified by PTR pointer.  */
   void release_object_overhead (void *ptr);
@@ -355,9 +355,9 @@ public:
      are filtered by ORIGIN type, LENGTH is return value where we register
      the number of elements in the list. If we want to process custom order,
      CMP comparator can be provided.  */
-  mem_list_t * get_list (mem_alloc_origin origin, unsigned *length,
-			 int (*cmp) (const void *first,
-				     const void *second) = NULL);
+  mem_list_t *get_list (mem_alloc_origin origin, unsigned *length,
+			int (*cmp) (const void *first,
+				    const void *second) = NULL);
 
   /* Dump all tracked instances of type ORIGIN. If we want to process custom
      order, CMP comparator can be provided.  */
Jakub Jelinek Nov. 7, 2018, 9:17 a.m. UTC | #5
On Wed, Nov 07, 2018 at 10:12:17AM +0100, Martin Liška wrote:
>    /* Register memory allocation descriptor for container PTR.  ORIGIN identifies
>       type of container and GGC identifes if the allocation is handled in GGC
>       memory.  Each location is identified by file NAME, LINE in source code and
>       FUNCTION name.  */
> -  T * register_descriptor (const void *ptr, mem_alloc_origin origin,
> +  T *register_descriptor (const void *ptr, mem_alloc_origin origin,
>  			   bool ggc, const char *name, int line,
>  			   const char *function);

This can't be right, if you move the ( one column to the left, then the
following lines need to be moved one column to the left too.  Likewise
below:

> @@ -342,7 +342,7 @@ public:
>    /* Release PTR pointer of SIZE bytes. If REMOVE_FROM_MAP is set to true,
>       remove the instance from reverse map.  Return memory usage that belongs
>       to this memory description.  */
> -  T * release_instance_overhead (void *ptr, size_t size,
> +  T *release_instance_overhead (void *ptr, size_t size,
>  				 bool remove_from_map = false);
>  
>    /* Release intance object identified by PTR pointer.  */
> @@ -355,7 +355,7 @@ public:
>       are filtered by ORIGIN type, LENGTH is return value where we register
>       the number of elements in the list. If we want to process custom order,
>       CMP comparator can be provided.  */
> -  mem_list_t * get_list (mem_alloc_origin origin, unsigned *length,
> +  mem_list_t *get_list (mem_alloc_origin origin, unsigned *length,
>  			 int (*cmp) (const void *first,
>  				     const void *second) = NULL);
>  

	Jakub
Martin Liška Nov. 7, 2018, 9:26 a.m. UTC | #6
On 11/7/18 10:17 AM, Jakub Jelinek wrote:
> On Wed, Nov 07, 2018 at 10:12:17AM +0100, Martin Liška wrote:
>>    /* Register memory allocation descriptor for container PTR.  ORIGIN identifies
>>       type of container and GGC identifes if the allocation is handled in GGC
>>       memory.  Each location is identified by file NAME, LINE in source code and
>>       FUNCTION name.  */
>> -  T * register_descriptor (const void *ptr, mem_alloc_origin origin,
>> +  T *register_descriptor (const void *ptr, mem_alloc_origin origin,
>>  			   bool ggc, const char *name, int line,
>>  			   const char *function);
> 
> This can't be right, if you move the ( one column to the left, then the
> following lines need to be moved one column to the left too.  Likewise
> below:

Thanks, I noticed that and installed proper version.

Martin

> 
>> @@ -342,7 +342,7 @@ public:
>>    /* Release PTR pointer of SIZE bytes. If REMOVE_FROM_MAP is set to true,
>>       remove the instance from reverse map.  Return memory usage that belongs
>>       to this memory description.  */
>> -  T * release_instance_overhead (void *ptr, size_t size,
>> +  T *release_instance_overhead (void *ptr, size_t size,
>>  				 bool remove_from_map = false);
>>  
>>    /* Release intance object identified by PTR pointer.  */
>> @@ -355,7 +355,7 @@ public:
>>       are filtered by ORIGIN type, LENGTH is return value where we register
>>       the number of elements in the list. If we want to process custom order,
>>       CMP comparator can be provided.  */
>> -  mem_list_t * get_list (mem_alloc_origin origin, unsigned *length,
>> +  mem_list_t *get_list (mem_alloc_origin origin, unsigned *length,
>>  			 int (*cmp) (const void *first,
>>  				     const void *second) = NULL);
>>  
> 
> 	Jakub
>
diff mbox series

Patch

diff --git a/gcc/mem-stats.h b/gcc/mem-stats.h
index 140691e8ec1..3ef6d53dfa6 100644
--- a/gcc/mem-stats.h
+++ b/gcc/mem-stats.h
@@ -282,21 +282,21 @@  public:
     static hashval_t
     hash (value_type l)
     {
-	inchash::hash hstate;
+      inchash::hash hstate;
 
-	hstate.add_ptr ((const void *)l->m_filename);
-	hstate.add_ptr (l->m_function);
-	hstate.add_int (l->m_line);
+      hstate.add_ptr ((const void *)l->m_filename);
+      hstate.add_ptr (l->m_function);
+      hstate.add_int (l->m_line);
 
-	return hstate.end ();
+      return hstate.end ();
     }
 
     static bool
     equal (value_type l1, value_type l2)
     {
-      return l1->m_filename == l2->m_filename
-	&& l1->m_function == l2->m_function
-	&& l1->m_line == l2->m_line;
+      return (l1->m_filename == l2->m_filename
+	      && l1->m_function == l2->m_function
+	      && l1->m_line == l2->m_line);
     }
   };
 
@@ -313,59 +313,50 @@  public:
   ~mem_alloc_description ();
 
   /* Returns true if instance PTR is registered by the memory description.  */
-  bool
-  contains_descriptor_for_instance (const void *ptr);
+  bool contains_descriptor_for_instance (const void *ptr);
 
   /* Return descriptor for instance PTR.  */
-  T *
-  get_descriptor_for_instance (const void *ptr);
+  T * get_descriptor_for_instance (const void *ptr);
 
   /* Register memory allocation descriptor for container PTR which is
      described by a memory LOCATION.  */
-  T *
-  register_descriptor (const void *ptr, mem_location *location);
+  T * register_descriptor (const void *ptr, mem_location *location);
 
   /* Register memory allocation descriptor for container PTR.  ORIGIN identifies
      type of container and GGC identifes if the allocation is handled in GGC
      memory.  Each location is identified by file NAME, LINE in source code and
      FUNCTION name.  */
-  T *
-  register_descriptor (const void *ptr, mem_alloc_origin origin,
-			  bool ggc, const char *name, int line,
-			  const char *function);
+  T * register_descriptor (const void *ptr, mem_alloc_origin origin,
+			   bool ggc, const char *name, int line,
+			   const char *function);
 
   /* Register instance overhead identified by PTR pointer. Allocation takes
      SIZE bytes.  */
-  T *
-  register_instance_overhead (size_t size, const void *ptr);
+  T * register_instance_overhead (size_t size, const void *ptr);
 
   /* For containers (and GGC) where we want to track every instance object,
      we register allocation of SIZE bytes, identified by PTR pointer, belonging
      to USAGE descriptor.  */
-  void
-  register_object_overhead (T *usage, size_t size, const void *ptr);
+  void register_object_overhead (T *usage, size_t size, const void *ptr);
 
   /* Release PTR pointer of SIZE bytes. If REMOVE_FROM_MAP is set to true,
      remove the instance from reverse map.  */
-  void
-  release_instance_overhead (void *ptr, size_t size,
+  void release_instance_overhead (void *ptr, size_t size,
 				  bool remove_from_map = false);
 
   /* Release intance object identified by PTR pointer.  */
-  void
-  release_object_overhead (void *ptr);
+  void release_object_overhead (void *ptr);
 
   /* Get sum value for ORIGIN type of allocation for the descriptor.  */
-  T
-  get_sum (mem_alloc_origin origin);
+  T get_sum (mem_alloc_origin origin);
 
   /* Get all tracked instances registered by the description. Items
      are filtered by ORIGIN type, LENGTH is return value where we register
      the number of elements in the list. If we want to process custom order,
      CMP comparator can be provided.  */
-  mem_list_t *
-  get_list (mem_alloc_origin origin, unsigned *length,
-	    int (*cmp) (const void *first, const void *second) = NULL);
+  mem_list_t * get_list (mem_alloc_origin origin, unsigned *length,
+			 int (*cmp) (const void *first,
+				     const void *second) = NULL);
 
   /* Dump all tracked instances of type ORIGIN. If we want to process custom
      order, CMP comparator can be provided.  */
@@ -391,7 +382,6 @@  private:
   reverse_mem_map_t *m_reverse_map;
 };
 
-
 /* Returns true if instance PTR is registered by the memory description.  */
 
 template <class T>
@@ -410,9 +400,9 @@  mem_alloc_description<T>::get_descriptor_for_instance (const void *ptr)
   return m_reverse_map->get (ptr) ? (*m_reverse_map->get (ptr)).usage : NULL;
 }
 
+/* Register memory allocation descriptor for container PTR which is
+   described by a memory LOCATION.  */
 
-  /* Register memory allocation descriptor for container PTR which is
-     described by a memory LOCATION.  */
 template <class T>
 inline T*
 mem_alloc_description<T>::register_descriptor (const void *ptr,
@@ -584,7 +574,8 @@  template <class T>
 inline
 typename mem_alloc_description<T>::mem_list_t *
 mem_alloc_description<T>::get_list (mem_alloc_origin origin, unsigned *length,
-			int (*cmp) (const void *first, const void *second))
+				    int (*cmp) (const void *first,
+						const void *second))
 {
   /* vec data structure is not used because all vectors generate memory
      allocation info a it would create a cycle.  */
diff --git a/gcc/vec.c b/gcc/vec.c
index ac3226b5fcb..ff2456aead9 100644
--- a/gcc/vec.c
+++ b/gcc/vec.c
@@ -141,7 +141,6 @@  vec_prefix::release_overhead (void *ptr, size_t size, bool in_dtor
   vec_mem_desc.release_instance_overhead (ptr, size, in_dtor);
 }
 
-
 /* Calculate the number of slots to reserve a vector, making sure that
    it is of at least DESIRED size by growing ALLOC exponentially.  */