re PR tree-optimization/37345 (Segfault in decl_function_context (TYPE_MAIN_VARIANT))
authorJan Hubicka <jh@suse.cz>
Thu, 4 Sep 2008 10:30:26 +0000 (12:30 +0200)
committerJan Hubicka <hubicka@gcc.gnu.org>
Thu, 4 Sep 2008 10:30:26 +0000 (10:30 +0000)
PR tree-optimization/37345
PR tree-optimization/37358
PR tree-optimization/37357
* tree.c (build_function_type_skip_args): Build distinct type copy;
set TYPE_CONTEXT.
(build_function_decl_skip_args): Set type of new decl not orig decl;
clear DECL_VINDEX for methods turned into functions.

From-SVN: r139980

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/torture/pr37345.C [new file with mode: 0644]
gcc/tree.c

index d3d023ebc44b8e0c5a87d6e59e5a72a9dd943116..eba838bab8e0302b1db2d621d94cca62394df0b9 100644 (file)
@@ -1,3 +1,13 @@
+2008-09-04  Jan Hubicka  <jh@suse.cz>
+
+       PR tree-optimization/37345
+       PR tree-optimization/37358
+       PR tree-optimization/37357
+       * tree.c (build_function_type_skip_args): Build distinct type copy;
+       set TYPE_CONTEXT.
+       (build_function_decl_skip_args): Set type of new decl not orig decl;
+       clear DECL_VINDEX for methods turned into functions.
+
 2008-09-04  Nick Clifton  <nickc@redhat.com>
 
        * configure.ac (HAVE_GAS_LCOMM_WITH_ALIGNMENT): New assembler
index 7348b958eee3db651ccc5bb804538004b606ea9b..40bf497a77fdfc9506070b16dce5eb1cb868887e 100644 (file)
@@ -1,3 +1,10 @@
+2008-09-03  Jan Hubicka  <jh@suse.cz>
+
+       PR tree-optimization/37345
+       PR tree-optimization/37358
+       PR tree-optimization/37357
+       * g++.dg/torture/pr37345.c: New file.
+
 2008-09-03  Tobias Grosser  <grosser@fim.uni-passau.de>
 
        * lib/target-supports.exp (check_effective_target_fgraphite): Fix test.
diff --git a/gcc/testsuite/g++.dg/torture/pr37345.C b/gcc/testsuite/g++.dg/torture/pr37345.C
new file mode 100644 (file)
index 0000000..5b49f53
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+class EbmlElement {                                                                                                                                                    
+    virtual EbmlElement * Clone() const;                                                                                                                               
+};                                                                                                                                                                     
+class KaxTracks : public EbmlElement {                                                                                                                                 
+public:                                                                                                                                                                
+    EbmlElement * Clone() const {                                                                                                                                      
+        return new KaxTracks(*this);                                                                                                                                   
+    }                                                                                                                                                                  
+};                                                                                                                                                                     
+KaxTracks kax_tracks;                                                                                                                                                  
+void finish_file(void)                                                                                                                                                 
+{                                                                                                                                                                      
+  kax_tracks.Clone();                                                                                                                                                  
+} 
index 95680bacb6123f9ab727730e518464816b35a0bd..71267bdb82c57ebd15c457ebc0d9c00e91b51e8e 100644 (file)
@@ -5925,7 +5925,12 @@ build_function_type_skip_args (tree orig_type, bitmap args_to_skip)
       TYPE_ARG_TYPES (new_type) = new_reversed;
     }
   else
-    new_type = build_function_type (TREE_TYPE (orig_type), new_reversed);
+    {
+      new_type
+        = build_distinct_type_copy (build_function_type (TREE_TYPE (orig_type),
+                                                        new_reversed));
+      TYPE_CONTEXT (new_type) = TYPE_CONTEXT (orig_type);
+    }
 
   /* This is a new type, not a copy of an old type.  Need to reassociate
      variants.  We can handle everything except the main variant lazily.  */
@@ -5959,7 +5964,12 @@ build_function_decl_skip_args (tree orig_decl, bitmap args_to_skip)
   new_type = TREE_TYPE (orig_decl);
   if (prototype_p (new_type))
     new_type = build_function_type_skip_args (new_type, args_to_skip);
-  TREE_TYPE (orig_decl) = new_type;
+  TREE_TYPE (new_decl) = new_type;
+
+  /* For declarations setting DECL_VINDEX (i.e. methods)
+     we expect first argument to be THIS pointer.   */
+  if (bitmap_bit_p (args_to_skip, 0))
+    DECL_VINDEX (new_decl) = NULL_TREE;
   return new_decl;
 }