]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR debug/36278 (ICE with typedef void in namespace and using the defined type...
authorJakub Jelinek <jakub@redhat.com>
Thu, 31 Jul 2008 08:01:25 +0000 (10:01 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 31 Jul 2008 08:01:25 +0000 (10:01 +0200)
PR debug/36278
* dwarf2out.c (get_context_die): New function.
(force_decl_die, force_type_die): Use it.
(dwarf2out_imported_module_or_decl): Likewise.  If base_type_die
returns NULL, force generation of DW_TAG_typedef and put that into
DW_AT_import.

* g++.dg/debug/namespace2.C: New test.

From-SVN: r138361

gcc/ChangeLog
gcc/dwarf2out.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/debug/namespace2.C [new file with mode: 0644]

index 57a4f1640ab15e6092813fd22f8bac564b316fa1..49799a84695deb7cc5eab30312590b543aa003d3 100644 (file)
@@ -1,5 +1,12 @@
 2008-07-31  Jakub Jelinek  <jakub@redhat.com>
 
+       PR debug/36278
+       * dwarf2out.c (get_context_die): New function.
+       (force_decl_die, force_type_die): Use it.
+       (dwarf2out_imported_module_or_decl): Likewise.  If base_type_die
+       returns NULL, force generation of DW_TAG_typedef and put that into
+       DW_AT_import.
+
        PR preprocessor/36649
        * c-pch.c (c_common_read_pch): Save and restore
        line_table->trace_includes across PCH restore.
index f553f2e454ac25022e2914d165e6d7b15044f954..dbf5105604b8652fe4996418a3c2790f4d6948fc 100644 (file)
@@ -14068,6 +14068,22 @@ is_redundant_typedef (const_tree decl)
   return 0;
 }
 
+/* Returns the DIE for a context.  */
+
+static inline dw_die_ref
+get_context_die (tree context)
+{
+  if (context)
+    {
+      /* Find die that represents this context.  */
+      if (TYPE_P (context))
+       return force_type_die (context);
+      else
+       return force_decl_die (context);
+    }
+  return comp_unit_die;
+}
+
 /* Returns the DIE for decl.  A DIE will always be returned.  */
 
 static dw_die_ref
@@ -14079,18 +14095,7 @@ force_decl_die (tree decl)
   decl_die = lookup_decl_die (decl);
   if (!decl_die)
     {
-      dw_die_ref context_die;
-      tree decl_context = DECL_CONTEXT (decl);
-      if (decl_context)
-       {
-         /* Find die that represents this context.  */
-         if (TYPE_P (decl_context))
-           context_die = force_type_die (decl_context);
-         else
-           context_die = force_decl_die (decl_context);
-       }
-      else
-       context_die = comp_unit_die;
+      dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
 
       decl_die = lookup_decl_die (decl);
       if (decl_die)
@@ -14145,16 +14150,7 @@ force_type_die (tree type)
   type_die = lookup_type_die (type);
   if (!type_die)
     {
-      dw_die_ref context_die;
-      if (TYPE_CONTEXT (type))
-       {
-         if (TYPE_P (TYPE_CONTEXT (type)))
-           context_die = force_type_die (TYPE_CONTEXT (type));
-         else
-           context_die = force_decl_die (TYPE_CONTEXT (type));
-       }
-      else
-       context_die = comp_unit_die;
+      dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
 
       type_die = modified_type_die (type, TYPE_READONLY (type),
                                    TYPE_VOLATILE (type), context_die);
@@ -14476,16 +14472,11 @@ dwarf2out_imported_module_or_decl (tree decl, tree context)
 
   /* Get the scope die for decl context. Use comp_unit_die for global module
      or decl. If die is not found for non globals, force new die.  */
-  if (!context)
-    scope_die = comp_unit_die;
-  else if (TYPE_P (context))
-    {
-      if (!should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
-       return;
-    scope_die = force_type_die (context);
-    }
-  else
-    scope_die = force_decl_die (context);
+  if (context
+      && TYPE_P (context)
+      && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
+    return;
+  scope_die = get_context_die (context);
 
   /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE.  */
   if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
@@ -14494,6 +14485,16 @@ dwarf2out_imported_module_or_decl (tree decl, tree context)
        at_import_die = base_type_die (TREE_TYPE (decl));
       else
        at_import_die = force_type_die (TREE_TYPE (decl));
+      /* For namespace N { typedef void T; } using N::T; base_type_die
+        returns NULL, but DW_TAG_imported_declaration requires
+        the DW_AT_import tag.  Force creation of DW_TAG_typedef.  */
+      if (!at_import_die)
+       {
+         gcc_assert (TREE_CODE (decl) == TYPE_DECL);
+         gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
+         at_import_die = lookup_type_die (TREE_TYPE (decl));
+         gcc_assert (at_import_die);
+       }
     }
   else
     {
@@ -14505,21 +14506,14 @@ dwarf2out_imported_module_or_decl (tree decl, tree context)
          if (TREE_CODE (decl) == FIELD_DECL)
            {
              tree type = DECL_CONTEXT (decl);
-             dw_die_ref type_context_die;
 
-             if (TYPE_CONTEXT (type))
-               if (TYPE_P (TYPE_CONTEXT (type)))
-                 {
-                   if (!should_emit_struct_debug (TYPE_CONTEXT (type),
-                                                  DINFO_USAGE_DIR_USE))
-                     return;
-                 type_context_die = force_type_die (TYPE_CONTEXT (type));
-                 }
-             else
-               type_context_die = force_decl_die (TYPE_CONTEXT (type));
-             else
-               type_context_die = comp_unit_die;
-             gen_type_die_for_member (type, decl, type_context_die);
+             if (TYPE_CONTEXT (type)
+                 && TYPE_P (TYPE_CONTEXT (type))
+                 && !should_emit_struct_debug (TYPE_CONTEXT (type),
+                                               DINFO_USAGE_DIR_USE))
+               return;
+             gen_type_die_for_member (type, decl,
+                                      get_context_die (TYPE_CONTEXT (type)));
            }
          at_import_die = force_decl_die (decl);
        }
index 8534f8c1a271e3f57ef8f2128f0e33f7f3f36fd4..0df56e856ee79727bf164ba031c86f90be117405 100644 (file)
@@ -3,6 +3,11 @@
        PR debug/36278
        * g++.dg/debug/namespace2.C: New test.
 
+       * gcc.dg/pch/cpp-3.c: New test.
+       * gcc.dg/pch/cpp-3.hs: New file.
+       * gcc.dg/pch/cpp-3a.h: New file.
+       * gcc.dg/pch/cpp-3b.h: New file.
+
 2008-07-30  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/boolean_expr.ad[sb]: New test.
diff --git a/gcc/testsuite/g++.dg/debug/namespace2.C b/gcc/testsuite/g++.dg/debug/namespace2.C
new file mode 100644 (file)
index 0000000..f70bc8f
--- /dev/null
@@ -0,0 +1,8 @@
+// PR debug/36278
+// { dg-do compile }
+
+namespace N
+{
+  typedef void T;
+}
+using N::T;