re PR c/90677 (gcc-9.1.0 fails to build __gcc_diag__ souce: error: 'cgraph_node'...
authorJakub Jelinek <jakub@redhat.com>
Fri, 22 Nov 2019 21:45:27 +0000 (22:45 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 22 Nov 2019 21:45:27 +0000 (22:45 +0100)
PR c/90677
* c-common.h (identifier_global_tag): Declare.
* c-format.c (get_pointer_to_named_type): Renamed to ...
(get_named_type): ... this.  Use identifier_global_tag instead of
identifier_global_value, handle the return value being a TYPE_P.
(init_dynamic_diag_info): Adjust get_pointer_to_named_type callers
to call get_named_type instead.  Formatting fixes.
c/
* c-decl.c (identifier_global_tag): Define.
cp/
* cp-objcp-common.c (identifier_global_tag): Define.
testsuite/
* c-c++-common/pr90677.c: New test.

From-SVN: r278634

gcc/c-family/ChangeLog
gcc/c-family/c-common.h
gcc/c-family/c-format.c
gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/cp/ChangeLog
gcc/cp/cp-objcp-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/pr90677.c [new file with mode: 0644]

index d0b2ba23e6f74b440b47003f0632290b4f791ad9..1cf0fef54655d9b01143c23eaf715b1d613becd5 100644 (file)
@@ -1,5 +1,13 @@
 2019-11-22  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c/90677
+       * c-common.h (identifier_global_tag): Declare.
+       * c-format.c (get_pointer_to_named_type): Renamed to ...
+       (get_named_type): ... this.  Use identifier_global_tag instead of
+       identifier_global_value, handle the return value being a TYPE_P.
+       (init_dynamic_diag_info): Adjust get_pointer_to_named_type callers
+       to call get_named_type instead.  Formatting fixes.
+
        Implement P1920R1, Missing feature-test macros 2017-2019.
        * c-cppbuiltin.c (c_cpp_builtins): Bump __cpp_init_captures
        and __cpp_generic_lambdas for -std=c++2a.  Define
index bed4d0c8764e68942c102a5a8d9636cd65ade502..2bcb54f66b91f2f53a6fdc202c6abbf3247d9fd9 100644 (file)
@@ -811,6 +811,7 @@ extern void c_register_addr_space (const char *str, addr_space_t as);
 extern bool in_late_binary_op;
 extern const char *c_addr_space_name (addr_space_t as);
 extern tree identifier_global_value (tree);
+extern tree identifier_global_tag (tree);
 extern bool names_builtin_p (const char *);
 extern tree c_linkage_bindings (tree);
 extern void record_builtin_type (enum rid, const char *, tree);
index 3c291ca45003904a6713d5d16fa468285da13d2e..d70d1e0f9c2c61a9424d5cead96f3b952ccef132 100644 (file)
@@ -4899,31 +4899,32 @@ init_dynamic_gfc_info (void)
     }
 }
 
-/* Lookup the type named NAME and return a pointer-to-NAME type if found.
-   Otherwise, return void_type_node if NAME has not been used yet, or NULL_TREE if
-   NAME is not a type (issuing an error).  */
+/* Lookup the type named NAME and return a NAME type if found.
+   Otherwise, return void_type_node if NAME has not been used yet,
+   or NULL_TREE if NAME is not a type (issuing an error).  */
 
 static tree
-get_pointer_to_named_type (const char *name)
+get_named_type (const char *name)
 {
-  tree result;
-  if ((result = maybe_get_identifier (name)))
+  if (tree result = maybe_get_identifier (name))
     {
-      result = identifier_global_value (result);
+      result = identifier_global_tag (result);
       if (result)
        {
-         if (TREE_CODE (result) != TYPE_DECL)
+         if (TYPE_P (result))
+           ;
+         else if (TREE_CODE (result) == TYPE_DECL)
+           result = TREE_TYPE (result);
+         else
            {
              error ("%qs is not defined as a type", name);
              result = NULL_TREE;
            }
-         else
-           result = TREE_TYPE (result);
        }
+      return result;
     }
   else
-    result = void_type_node;
-  return result;
+    return void_type_node;
 }
 
 /* Determine the types of "tree" and "location_t" in the code being
@@ -4953,23 +4954,24 @@ init_dynamic_diag_info (void)
         an extra type level.  */
       if ((local_tree_type_node = maybe_get_identifier ("tree")))
        {
-         local_tree_type_node = identifier_global_value (local_tree_type_node);
+         local_tree_type_node
+           = identifier_global_value (local_tree_type_node);
          if (local_tree_type_node)
            {
              if (TREE_CODE (local_tree_type_node) != TYPE_DECL)
                {
                  error ("%<tree%> is not defined as a type");
-                 local_tree_type_node = 0;
+                 local_tree_type_node = NULL_TREE;
                }
              else if (TREE_CODE (TREE_TYPE (local_tree_type_node))
                       != POINTER_TYPE)
                {
                  error ("%<tree%> is not defined as a pointer type");
-                 local_tree_type_node = 0;
+                 local_tree_type_node = NULL_TREE;
                }
              else
-               local_tree_type_node =
-                 TREE_TYPE (TREE_TYPE (local_tree_type_node));
+               local_tree_type_node
+                 TREE_TYPE (TREE_TYPE (local_tree_type_node));
            }
        }
       else
@@ -4979,12 +4981,12 @@ init_dynamic_diag_info (void)
   /* Similar to the above but for gimple*.  */
   if (!local_gimple_ptr_node
       || local_gimple_ptr_node == void_type_node)
-    local_gimple_ptr_node = get_pointer_to_named_type ("gimple");
+    local_gimple_ptr_node = get_named_type ("gimple");
 
   /* Similar to the above but for cgraph_node*.  */
   if (!local_cgraph_node_ptr_node
       || local_cgraph_node_ptr_node == void_type_node)
-    local_cgraph_node_ptr_node = get_pointer_to_named_type ("cgraph_node");
+    local_cgraph_node_ptr_node = get_named_type ("cgraph_node");
 
   static tree hwi;
 
index 7b37842ca5b5b9cee7f8e4c0232724717937e9a1..cb1ea0948dd3f011186d2391e6d72922e65b54ad 100644 (file)
@@ -1,3 +1,8 @@
+2019-11-22  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/90677
+       * c-decl.c (identifier_global_tag): Define.
+
 2019-11-20  Richard Biener  <rguenther@suse.de>
 
        PR c/92088
index caa9c85897e8ee89a1611d7943955820f30144b5..7fd3cc26e87ec10642f5a7c97b8dc73387440cd4 100644 (file)
@@ -10168,6 +10168,20 @@ identifier_global_value        (tree t)
   return NULL_TREE;
 }
 
+/* Return the global value of tag T as a symbol.  */
+
+tree
+identifier_global_tag (tree t)
+{
+  struct c_binding *b;
+
+  for (b = I_TAG_BINDING (t); b; b = b->shadowed)
+    if (B_IN_FILE_SCOPE (b) || B_IN_EXTERNAL_SCOPE (b))
+      return b->decl;
+
+  return NULL_TREE;
+}
+
 /* Returns true if NAME refers to a built-in function or function-like
    operator.  */
 
index 93cf9e95f7182300134dba1a24fabb8b3dba27a8..762da085cb608bb1e440d79b7bef95554f61ee89 100644 (file)
@@ -1,5 +1,8 @@
 2019-11-22  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c/90677
+       * cp-objcp-common.c (identifier_global_tag): Define.
+
        PR c++/92458
        * init.c (nsdmi_inst): Change type to
        decl_tree_cache_map * from tree_cache_map *.
index d168e2a802fcfb00fbffd373e607d6d6ae7a14ee..a65802f5b8a31d7b03d43d5b2c6e1625fbe1e88e 100644 (file)
@@ -349,6 +349,15 @@ identifier_global_value (tree name)
   return get_global_binding (name);
 }
 
+/* Similarly, but return struct/class/union NAME instead.  */
+
+tree
+identifier_global_tag (tree name)
+{
+  return lookup_qualified_name (global_namespace, name, /*prefer_type*/2,
+                               /*complain*/false);
+}
+
 /* Returns true if NAME refers to a built-in function or function-like
    operator.  */
 
index 6f8c791d77694a100cf6af6c17387f2a14587622..201d044b7657d77cfc8d195a6ea053d1f8f7ad37 100644 (file)
@@ -1,5 +1,8 @@
 2019-11-22  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c/90677
+       * c-c++-common/pr90677.c: New test.
+
        PR c++/92458
        * g++.dg/pch/pr92458.C: New test.
        * g++.dg/pch/pr92458.Hs: New test.
diff --git a/gcc/testsuite/c-c++-common/pr90677.c b/gcc/testsuite/c-c++-common/pr90677.c
new file mode 100644 (file)
index 0000000..897fbc6
--- /dev/null
@@ -0,0 +1,11 @@
+/* PR c/90677 */
+/* { dg-do compile } */
+/* { dg-options "-W -Wall" } */
+
+struct cgraph_node;
+union tree_node;
+typedef union tree_node *tree;
+union gimple_statement_d;
+typedef union gimple_statement_d *gimple;
+struct cgraph_node *cgraph_node (tree);
+void foo (int, const char *, ...) __attribute__((__format__(__gcc_diag__, 2, 3)));