From 04f915037850166c05c73baf3d6e2ba10c790ea1 Mon Sep 17 00:00:00 2001
From: Markus Trippelsdorf <markus@trippelsdorf.de>
Date: Mon, 27 Nov 2017 12:53:16 +0000
Subject: [PATCH] Fix UB in hash-map.h

bootstrap-ubsan shows:
  gcc/hash-map.h:277:19: runtime error: member access within null pointer of type 'struct hash_map'

Fix the issue by returning early.

From-SVN: r255166
---
 gcc/ChangeLog  | 4 ++++
 gcc/hash-map.h | 3 ++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index a7066fb7ad19..98e49cdb9c0f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,7 @@
+2017-11-27  Markus Trippelsdorf  <markus@trippelsdorf.de>
+
+	* hash-map.h (gt_cleare_cache): Avoid UB.
+
 2017-11-27  Eric Botcazou  <ebotcazou@adacore.com>
 
 	* cfgloop.h (struct loop): Document usage of USHRT_MAX for unroll.
diff --git a/gcc/hash-map.h b/gcc/hash-map.h
index 6b8365a9d0a6..10ae52d194ad 100644
--- a/gcc/hash-map.h
+++ b/gcc/hash-map.h
@@ -274,7 +274,8 @@ template<typename K, typename V, typename H>
 static inline void
 gt_cleare_cache (hash_map<K, V, H> *h)
 {
-  gt_cleare_cache (&h->m_table);
+  if (h)
+    gt_cleare_cache (&h->m_table);
 }
 
 template<typename K, typename V, typename H>
-- 
GitLab