]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree.c (free_lang_data_in_decl): Remove types from DECL_CONTEXT when possible.
authorJan Hubicka <jh@suse.cz>
Tue, 21 Aug 2018 10:36:37 +0000 (12:36 +0200)
committerJan Hubicka <hubicka@gcc.gnu.org>
Tue, 21 Aug 2018 10:36:37 +0000 (10:36 +0000)
* tree.c (free_lang_data_in_decl): Remove types from DECL_CONTEXT
when possible.

From-SVN: r263697

gcc/ChangeLog
gcc/tree.c

index 66ca10b96b9fca752a30b1567fe08a82c15f885c..c19038bc31cd4644f400e2f6b5142f67f2fb79ef 100644 (file)
@@ -1,3 +1,8 @@
+2018-08-21  Jan Hubicka  <jh@suse.cz>
+
+       * tree.c (free_lang_data_in_decl): Remove types from DECL_CONTEXT
+       when possible.
+
 2018-08-21  Tamar Christina  <tamar.christina@arm.com>
 
        * expmed.c (extract_low_bits): Reject invalid subregs early.
index dd3439f60c9649fa925bfedc551c9708fc1b4bdf..8d1e010d7a2d9c89fb4695e987ee1104d2b21a86 100644 (file)
@@ -5380,6 +5380,29 @@ free_lang_data_in_decl (tree decl)
            nextp = &TREE_CHAIN (var);
         }
     }
+  /* We need to keep field decls associated with their trees. Otherwise tree
+     merging may merge some fileds and keep others disjoint wich in turn will
+     not do well with TREE_CHAIN pointers linking them.
+
+     Also do not drop containing types for virtual methods and tables because
+     these are needed by devirtualization.  */
+  if (TREE_CODE (decl) != FIELD_DECL
+      && ((TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
+          || !DECL_VIRTUAL_P (decl)))
+    {
+      tree ctx = DECL_CONTEXT (decl);
+      /* Variably modified types are needed for tree_is_indexable to decide
+        whether the type needs to go to local or global section.
+        This code is semi-broken but for now it is easiest to keep contexts
+        as expected.  */
+      if (ctx && TYPE_P (ctx)
+         && !variably_modified_type_p (ctx, NULL_TREE))
+        {
+          while (ctx && TYPE_P (ctx))
+            ctx = TYPE_CONTEXT (ctx);
+          DECL_CONTEXT (decl) = ctx;
+        }
+    }
 }