public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] add missing GTY support for hash-map (PR 100463)
@ 2021-05-24 16:46 Martin Sebor
  2021-05-24 21:14 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Sebor @ 2021-05-24 16:46 UTC (permalink / raw)
  To: gcc-patches, Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 780 bytes --]

Instantiating a hash_map on a number of integer types including,
for example, int or unsigned int (such as location_t), or
HOST_WIDE_INT, and using it with the garbage collector causes many
cryptic compilation errors due to incomplete support for such types
(the PR shows a few examples).  I ran into these errors as I was
prototyping a new feature and they took me egregiously long to
figure out, even with help from others.

The attached patch adds the missing functions necessary to complete
the support for all integer types to avoid these errors.  This is
prerequisite for a future patch of mine.  The patch uses just one
of these hash_map instances but others shouldn't have to run into
the same errors if they happen to choose one of them.

Tested on x86_64-linux.

Martin

[-- Attachment #2: gcc-100463.diff --]
[-- Type: text/x-patch, Size: 3142 bytes --]

PR other/100463 - many errors using GTY and hash_map

gcc/ChangeLog:
	* ggc.h (gt_ggc_mx): Add overloads for all integers.
	(gt_pch_nx):  Same.
	* hash-map.h (class hash_map): Add pch_nx_helper overloads for all
	integers.
	(hash_map::operator==): New function.

diff --git a/gcc/ggc.h b/gcc/ggc.h
index 65f6cb4d19d..92884717f5c 100644
--- a/gcc/ggc.h
+++ b/gcc/ggc.h
@@ -332,19 +332,30 @@ gt_pch_nx (const char *)
 {
 }
 
-inline void
-gt_ggc_mx (int)
-{
-}
-
-inline void
-gt_pch_nx (int)
-{
-}
-
-inline void
-gt_pch_nx (unsigned int)
-{
-}
+inline void gt_pch_nx (bool) { }
+inline void gt_pch_nx (char) { }
+inline void gt_pch_nx (signed char) { }
+inline void gt_pch_nx (unsigned char) { }
+inline void gt_pch_nx (short) { }
+inline void gt_pch_nx (unsigned short) { }
+inline void gt_pch_nx (int) { }
+inline void gt_pch_nx (unsigned int) { }
+inline void gt_pch_nx (long int) { }
+inline void gt_pch_nx (unsigned long int) { }
+inline void gt_pch_nx (long long int) { }
+inline void gt_pch_nx (unsigned long long int) { }
+
+inline void gt_ggc_mx (bool) { }
+inline void gt_ggc_mx (char) { }
+inline void gt_ggc_mx (signed char) { }
+inline void gt_ggc_mx (unsigned char) { }
+inline void gt_ggc_mx (short) { }
+inline void gt_ggc_mx (unsigned short) { }
+inline void gt_ggc_mx (int) { }
+inline void gt_ggc_mx (unsigned int) { }
+inline void gt_ggc_mx (long int) { }
+inline void gt_ggc_mx (unsigned long int) { }
+inline void gt_ggc_mx (long long int) { }
+inline void gt_ggc_mx (unsigned long long int) { }
 
 #endif
diff --git a/gcc/hash-map.h b/gcc/hash-map.h
index 0779c930f0a..dd039f10343 100644
--- a/gcc/hash-map.h
+++ b/gcc/hash-map.h
@@ -107,27 +107,31 @@ class GTY((user)) hash_map
 	  gt_pch_nx (&x, op, cookie);
 	}
 
-    static void
-      pch_nx_helper (int, gt_pointer_operator, void *)
-	{
-	}
-
-    static void
-      pch_nx_helper (unsigned int, gt_pointer_operator, void *)
-	{
-	}
-
-    static void
-      pch_nx_helper (bool, gt_pointer_operator, void *)
-	{
-	}
-
     template<typename T>
       static void
       pch_nx_helper (T *&x, gt_pointer_operator op, void *cookie)
 	{
 	  op (&x, cookie);
 	}
+
+    /* The overloads below should match those in ggc.h.  */
+#define DEFINE_PCH_HELPER(T)			\
+    static void pch_nx_helper (T, gt_pointer_operator, void *) { }
+
+    DEFINE_PCH_HELPER (bool);
+    DEFINE_PCH_HELPER (char);
+    DEFINE_PCH_HELPER (signed char);
+    DEFINE_PCH_HELPER (unsigned char);
+    DEFINE_PCH_HELPER (short);
+    DEFINE_PCH_HELPER (unsigned short);
+    DEFINE_PCH_HELPER (int);
+    DEFINE_PCH_HELPER (unsigned int);
+    DEFINE_PCH_HELPER (long);
+    DEFINE_PCH_HELPER (unsigned long);
+    DEFINE_PCH_HELPER (long long);
+    DEFINE_PCH_HELPER (unsigned long long);
+
+#undef DEFINE_PCH_HELPER
   };
 
 public:
@@ -273,8 +277,12 @@ public:
       return reference_pair (e.m_key, e.m_value);
     }
 
-    bool
-    operator != (const iterator &other) const
+    bool operator== (const iterator &other) const
+    {
+      return m_iter == other.m_iter;
+    }
+
+    bool operator != (const iterator &other) const
     {
       return m_iter != other.m_iter;
     }


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] add missing GTY support for hash-map (PR 100463)
  2021-05-24 16:46 [PATCH] add missing GTY support for hash-map (PR 100463) Martin Sebor
@ 2021-05-24 21:14 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2021-05-24 21:14 UTC (permalink / raw)
  To: Martin Sebor, gcc-patches

On 5/24/21 12:46 PM, Martin Sebor wrote:
> Instantiating a hash_map on a number of integer types including,
> for example, int or unsigned int (such as location_t), or
> HOST_WIDE_INT, and using it with the garbage collector causes many
> cryptic compilation errors due to incomplete support for such types
> (the PR shows a few examples).  I ran into these errors as I was
> prototyping a new feature and they took me egregiously long to
> figure out, even with help from others.
> 
> The attached patch adds the missing functions necessary to complete
> the support for all integer types to avoid these errors.  This is
> prerequisite for a future patch of mine.  The patch uses just one
> of these hash_map instances but others shouldn't have to run into
> the same errors if they happen to choose one of them.
> 
> Tested on x86_64-linux.

OK.

Jason


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-24 21:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-24 16:46 [PATCH] add missing GTY support for hash-map (PR 100463) Martin Sebor
2021-05-24 21:14 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).