Hi!

PCH remaps object addresses, so hash tables that use pointer hashing
don't work well across PCH, because the hash values can change and without
rehashing the hash tbales values might not be found.

The following patch fixes it by using DECL_UID as hash function instead,
which is stable across PCH save/restore.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2019-11-11  Jakub Jelinek  <ja...@redhat.com>

        PR c++/92458
        * constraint.cc: Include tree-hash-traits.h.
        (decl_tree_cache_traits): New type.
        (decl_tree_cache_map): New typedef.
        (decl_constraints): Change type to decl_tree_cache_map *
        from tree_cache_map *.

        * g++.dg/pch/pr92458.C: New test.
        * g++.dg/pch/pr92458.Hs: New test.

--- gcc/cp/constraint.cc.jj     2019-11-07 09:50:51.755239234 +0100
+++ gcc/cp/constraint.cc        2019-11-11 19:04:03.231862024 +0100
@@ -45,6 +45,7 @@ along with GCC; see the file COPYING3.
 #include "decl.h"
 #include "toplev.h"
 #include "type-utils.h"
+#include "tree-hash-traits.h"
 
 static tree satisfaction_value (tree t);
 
@@ -1113,7 +1114,10 @@ build_constraints (tree tr, tree dr)
 
 /* A mapping from declarations to constraint information.  */
 
-static GTY ((cache)) tree_cache_map *decl_constraints;
+struct decl_tree_cache_traits
+  : simple_cache_map_traits<tree_decl_hash, tree> { };
+typedef hash_map<tree,tree,decl_tree_cache_traits> decl_tree_cache_map;
+static GTY ((cache)) decl_tree_cache_map *decl_constraints;
 
 /* Returns the template constraints of declaration T. If T is not
    constrained, return NULL_TREE. Note that T must be non-null. */
--- gcc/testsuite/g++.dg/pch/pr92458.C.jj       2019-11-11 19:09:51.547614022 
+0100
+++ gcc/testsuite/g++.dg/pch/pr92458.C  2019-11-11 19:12:39.164088578 +0100
@@ -0,0 +1,5 @@
+// PR c++/92458
+// { dg-options "-std=c++2a" }
+
+#include "pr92458.H"
+S<int> s;
--- gcc/testsuite/g++.dg/pch/pr92458.Hs.jj      2019-11-11 19:09:25.091012637 
+0100
+++ gcc/testsuite/g++.dg/pch/pr92458.Hs 2019-11-11 19:12:47.626961060 +0100
@@ -0,0 +1,7 @@
+// PR c++/92458
+// { dg-options "-std=c++2a" }
+
+template<typename T> concept C = sizeof(T) > 1;
+template<typename T> struct S { };
+template<typename T> requires C<T> struct S<T> { };
+template<typename T> requires (!C<T>) struct S<T> { };

        Jakub

Reply via email to