]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c/90677 (gcc-9.1.0 fails to build __gcc_diag__ souce: error: 'cgraph_...
authorJakub Jelinek <jakub@redhat.com>
Fri, 20 Dec 2019 16:56:30 +0000 (17:56 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 20 Dec 2019 16:56:30 +0000 (17:56 +0100)
Backported from mainline
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.

* c-decl.c (identifier_global_tag): Define.

* cp-objcp-common.c (identifier_global_tag): Define.

* c-c++-common/pr90677.c: New test.

From-SVN: r279650

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 e7f0127dcf262f7183f0a8a37d9e2e57b1dc2805..47b03901a5740e3bddd3806a69e864ab19b9b844 100644 (file)
@@ -1,3 +1,16 @@
+2019-12-20  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       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.
+
 2019-11-13  Eric Botcazou  <ebotcazou@adacore.com>
 
        * c-ada-spec.c (get_underlying_decl): Do not look through typedefs.
index e9ef16aff29e6a1010ad2f3711769e1f8a6fb247..68376426721ba84559b1646b2ef3e1c660de2ddb 100644 (file)
@@ -800,6 +800,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 tree c_linkage_bindings (tree);
 extern void record_builtin_type (enum rid, const char *, tree);
 extern tree build_void_list_node (void);
index a7f76c1c01d043eca592c99ab48eaecb94cc3d15..f706793a4791d13f32c5a4224da7869ac500247f 100644 (file)
@@ -3909,31 +3909,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
@@ -3963,23 +3964,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
@@ -3989,12 +3991,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 1295ca2c2a576d757c38ddaa1d2173192635b918..67f52ddd56277eb74cc3b70989a858cd77042fc6 100644 (file)
@@ -1,3 +1,11 @@
+2019-12-20  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2019-11-22  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/90677
+       * c-decl.c (identifier_global_tag): Define.
+
 2019-12-02  Sandra Loosemore  <sandra@codesourcery.com>
 
        Fix bugs relating to flexibly-sized objects in nios2 backend.
index c423a0c41d2550e01cf1f87aa60a503a3992f3c2..c632e4afd24fa7fc0c47060f8a3485c18b8ab3e8 100644 (file)
@@ -9941,6 +9941,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;
+}
+
 /* In C, the only C-linkage public declaration is at file scope.  */
 
 tree
index f11c453d208a020f13b782ee1ccb70ea53017ecd..26d109c6d7587543c9446ca80db1af1aa3061289 100644 (file)
@@ -1,6 +1,11 @@
 2019-12-20  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2019-11-22  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/90677
+       * cp-objcp-common.c (identifier_global_tag): Define.
+
        2019-11-21  Jakub Jelinek  <jakub@redhat.com>
                    Jason Merrill  <jason@redhat.com>
 
index 47651040008d8aa42401f57a827983c178ec6f78..a1c976e33a1c26b777f473204408c5c55552c3b9 100644 (file)
@@ -352,6 +352,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);
+}
+
 /* Register c++-specific dumps.  */
 
 void
index 0c3b578dda03adb3e8eeb8625d73aedfed8bc10c..c1d3e99b58a3812277e11a92c34dd3fcd60bcb29 100644 (file)
@@ -1,6 +1,11 @@
 2019-12-20  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2019-11-22  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/90677
+       * c-c++-common/pr90677.c: New test.
+
        2019-11-21  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/90842
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)));