Refactor fileptr_type_node handling
authorMarc Glisse <marc.glisse@inria.fr>
Fri, 23 Jun 2017 09:05:47 +0000 (11:05 +0200)
committerMarc Glisse <glisse@gcc.gnu.org>
Fri, 23 Jun 2017 09:05:47 +0000 (09:05 +0000)
2017-06-23  Marc Glisse  <marc.glisse@inria.fr>

gcc/
* tree.h (builtin_structptr_type): New type.
(builtin_structptr_types): Declare new array.
* tree.c (builtin_structptr_types): New array.
(free_lang_data, build_common_tree_nodes): Use it.

gcc/c-family/
* c-common.c (c_common_nodes_and_builtins): Use builtin_structptr_types.

gcc/cp/
* decl.c (duplicate_decls): Use builtin_structptr_types.

gcc/lto/
* lto-lang.c (lto_init): Use builtin_structptr_types.

From-SVN: r249585

gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/lto/ChangeLog
gcc/lto/lto-lang.c
gcc/tree.c
gcc/tree.h

index e3245dfcf84e3cec5b70d0cab43a0032ce8cc6a1..4f750a63dd1d46cf4407cba104d114d68af0e9d9 100644 (file)
@@ -1,3 +1,10 @@
+2017-06-23  Marc Glisse  <marc.glisse@inria.fr>
+
+       * tree.h (builtin_structptr_type): New type.
+       (builtin_structptr_types): Declare new array.
+       * tree.c (builtin_structptr_types): New array.
+       (free_lang_data, build_common_tree_nodes): Use it.
+
 2017-06-23  Jonathan Wakely  <jwakely@redhat.com>
 
        PR c++/81187
index e8d1d57ae91d0365b2484b3da71739977897919c..a61bb56ee80555d886107e4a56ef156eb7c0b7a0 100644 (file)
@@ -1,3 +1,7 @@
+2017-06-23  Marc Glisse  <marc.glisse@inria.fr>
+
+       * c-common.c (c_common_nodes_and_builtins): Use builtin_structptr_types.
+
 2017-06-15  Martin Sebor  <msebor@redhat.com>
 
        PR c++/80560
index 4395e51847ca16550cdaf10c72ede8e2c2e9a708..f6a9d05c3da2ec9de6b4730a55d838f98e31a6df 100644 (file)
@@ -4181,10 +4181,14 @@ c_common_nodes_and_builtins (void)
   if (c_dialect_cxx ())
     {
       /* For C++, make fileptr_type_node a distinct void * type until
-        FILE type is defined.  */
-      fileptr_type_node = build_variant_type_copy (ptr_type_node);
-      /* Likewise for const struct tm*.  */
-      const_tm_ptr_type_node = build_variant_type_copy (const_ptr_type_node);
+        FILE type is defined.  Likewise for const struct tm*.  */
+      for (unsigned i = 0;
+          i < sizeof (builtin_structptr_types)
+              / sizeof (builtin_structptr_type);
+          ++i)
+       builtin_structptr_types[i].node =
+         build_variant_type_copy (builtin_structptr_types[i].base);
+
     }
 
   record_builtin_type (RID_VOID, NULL, void_type_node);
index 6acbe8b6f706a09973cfad0315c905a229fa910e..92f478a0b487d895185f7aecf4609169b402d252 100644 (file)
@@ -1,3 +1,7 @@
+2017-06-23  Marc Glisse  <marc.glisse@inria.fr>
+
+       * decl.c (duplicate_decls): Use builtin_structptr_types.
+
 2017-06-22  Nathan Sidwell  <nathan@acm.org>
 
        Reorder IDENTIFIER flags
index b0a34de5dd9303eda21660fc777d0c243603ecec..0361357a14e0457042febae5da972e24f7242712 100644 (file)
@@ -1470,53 +1470,41 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend)
                   t2 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
                   t1 || t2;
                   t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
-               if (!t1 || !t2)
-                 break;
-               /* Deal with fileptr_type_node.  FILE type is not known
-                  at the time we create the builtins.  */
-               else if (TREE_VALUE (t2) == fileptr_type_node)
-                 {
-                   tree t = TREE_VALUE (t1);
-
-                   if (TYPE_PTR_P (t)
-                       && TYPE_IDENTIFIER (TREE_TYPE (t))
-                          == get_identifier ("FILE")
-                       && compparms (TREE_CHAIN (t1), TREE_CHAIN (t2)))
+               {
+                 if (!t1 || !t2)
+                   break;
+                 /* FILE, tm types are not known at the time
+                    we create the builtins.  */
+                 for (unsigned i = 0;
+                      i < sizeof (builtin_structptr_types)
+                          / sizeof (builtin_structptr_type);
+                      ++i)
+                   if (TREE_VALUE (t2) == builtin_structptr_types[i].node)
                      {
-                       tree oldargs = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
-
-                       TYPE_ARG_TYPES (TREE_TYPE (olddecl))
-                         = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
-                       types_match = decls_match (newdecl, olddecl);
-                       if (types_match)
-                         return duplicate_decls (newdecl, olddecl,
-                                                 newdecl_is_friend);
-                       TYPE_ARG_TYPES (TREE_TYPE (olddecl)) = oldargs;
-                     }
-                 }
-               /* Likewise for const struct tm*.  */
-               else if (TREE_VALUE (t2) == const_tm_ptr_type_node)
-                 {
-                   tree t = TREE_VALUE (t1);
+                       tree t = TREE_VALUE (t1);
 
-                   if (TYPE_PTR_P (t)
-                       && TYPE_IDENTIFIER (TREE_TYPE (t))
-                          == get_identifier ("tm")
-                       && compparms (TREE_CHAIN (t1), TREE_CHAIN (t2)))
-                     {
-                       tree oldargs = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
-
-                       TYPE_ARG_TYPES (TREE_TYPE (olddecl))
-                         = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
-                       types_match = decls_match (newdecl, olddecl);
-                       if (types_match)
-                         return duplicate_decls (newdecl, olddecl,
-                                                 newdecl_is_friend);
-                       TYPE_ARG_TYPES (TREE_TYPE (olddecl)) = oldargs;
+                       if (TYPE_PTR_P (t)
+                           && TYPE_IDENTIFIER (TREE_TYPE (t))
+                           == get_identifier (builtin_structptr_types[i].str)
+                           && compparms (TREE_CHAIN (t1), TREE_CHAIN (t2)))
+                         {
+                           tree oldargs = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
+
+                           TYPE_ARG_TYPES (TREE_TYPE (olddecl))
+                             = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
+                           types_match = decls_match (newdecl, olddecl);
+                           if (types_match)
+                             return duplicate_decls (newdecl, olddecl,
+                                                     newdecl_is_friend);
+                           TYPE_ARG_TYPES (TREE_TYPE (olddecl)) = oldargs;
+                         }
+                       goto next_arg;
                      }
-                 }
-               else if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
-                 break;
+
+                 if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
+                   break;
+next_arg:;
+               }
 
              warning_at (DECL_SOURCE_LOCATION (newdecl),
                          OPT_Wbuiltin_declaration_mismatch,
index 58601c54b46d92e5240c2ac99a2215bae47a9aea..41f034372d94cd6efba2b0592a937cef71895844 100644 (file)
@@ -1,3 +1,7 @@
+2017-06-23  Marc Glisse  <marc.glisse@inria.fr>
+
+       * lto-lang.c (lto_init): Use builtin_structptr_types.
+
 2017-06-15  Jan Hubicka  <hubicka@ucw.cz>
            Thomas Preud'homme  <thomas.preudhomme@arm.com>
 
index 52ab2a8cb812a0b33d6dc0cd21de1bec45541b8f..58935172b2c5e1b94a1de71ccdb76fbe4a2c28c0 100644 (file)
@@ -1220,13 +1220,17 @@ lto_init (void)
   /* In the C++ front-end, fileptr_type_node is defined as a variant
      copy of ptr_type_node, rather than ptr_node itself.  The
      distinction should only be relevant to the front-end, so we
-     always use the C definition here in lto1.  */
-  gcc_assert (fileptr_type_node == ptr_type_node);
-  gcc_assert (TYPE_MAIN_VARIANT (fileptr_type_node) == ptr_type_node);
-  /* Likewise for const struct tm*.  */
-  gcc_assert (const_tm_ptr_type_node == const_ptr_type_node);
-  gcc_assert (TYPE_MAIN_VARIANT (const_tm_ptr_type_node)
-             == const_ptr_type_node);
+     always use the C definition here in lto1.
+     Likewise for const struct tm*.  */
+  for (unsigned i = 0;
+       i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
+       ++i)
+    {
+      gcc_assert (builtin_structptr_types[i].node
+                 == builtin_structptr_types[i].base);
+      gcc_assert (TYPE_MAIN_VARIANT (builtin_structptr_types[i].node)
+                 == builtin_structptr_types[i].base);
+    }
 
   lto_build_c_type_nodes ();
   gcc_assert (va_list_type_node);
index 260280317bceb261f04e323edc5455bc0f79e52f..13c6c90ba9817500ac671507e3e8095dda5c897f 100644 (file)
@@ -5983,8 +5983,10 @@ free_lang_data (void)
   free_lang_data_in_cgraph ();
 
   /* Create gimple variants for common types.  */
-  fileptr_type_node = ptr_type_node;
-  const_tm_ptr_type_node = const_ptr_type_node;
+  for (unsigned i = 0;
+       i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
+       ++i)
+    builtin_structptr_types[i].node = builtin_structptr_types[i].base;
 
   /* Reset some langhooks.  Do not reset types_compatible_p, it may
      still be used indirectly via the get_alias_set langhook.  */
@@ -10449,8 +10451,10 @@ build_common_tree_nodes (bool signed_char)
   ptr_type_node = build_pointer_type (void_type_node);
   const_ptr_type_node
     = build_pointer_type (build_type_variant (void_type_node, 1, 0));
-  fileptr_type_node = ptr_type_node;
-  const_tm_ptr_type_node = const_ptr_type_node;
+  for (unsigned i = 0;
+       i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
+       ++i)
+    builtin_structptr_types[i].node = builtin_structptr_types[i].base;
 
   pointer_sized_int_node = build_nonstandard_integer_type (POINTER_SIZE, 1);
 
@@ -14544,6 +14548,16 @@ get_nonnull_args (const_tree fntype)
   return argmap;
 }
 
+/* List of pointer types used to declare builtins before we have seen their
+   real declaration.
+
+   Keep the size up to date in tree.h !  */
+const builtin_structptr_type builtin_structptr_types[2] = 
+{
+  { fileptr_type_node, ptr_type_node, "FILE" },
+  { const_tm_ptr_type_node, const_ptr_type_node, "tm" }
+};
+
 #if CHECKING_P
 
 namespace selftest {
index bfe83f7c0a2803b554d8c5f4c86ac0ecc8184393..7a4f5d64f19082992a1dcf58820e5bba8644781e 100644 (file)
@@ -5523,4 +5523,13 @@ desired_pro_or_demotion_p (const_tree to_type, const_tree from_type)
   return to_type_precision <= TYPE_PRECISION (from_type);
 }
 
+/* Pointer type used to declare builtins before we have seen its real
+   declaration.  */
+struct builtin_structptr_type
+{
+  tree& node;
+  tree& base;
+  const char *str;
+};
+extern const builtin_structptr_type builtin_structptr_types[2];
 #endif  /* GCC_TREE_H  */