Fix args kipping code (PR 37357, 37358, 37345)

Jan Hubicka jh@suse.cz
Wed Sep 3 19:41:00 GMT 2008


Hi,
this patch fixes problem in build_function_type_skip_args that modify
type returned by build_function_type.  This is wrong, since
build_function_type hash types and will return same node again when
asked to build same type, so we need to build separate copy.
I also added code copying TYPE_CONTEXT that is used by debug info.
We probably ought to copy attributes and other items too, I will send
separate patch for this.

There is also problem in build_function_decl_skip_args that overwrite
type of original declaration instead of new declaration. Amazingly this
breaks only for C++ mangling (i.e. the mangled function names suddenly
change) and finally clears DECL_VINDEX when THIS argument of method is
dropped so the method becomes normal function.  This prevents
decl_function_context from looking at type of (expected) THIS argument
and returning garbage.

Bootstrapped/regtested i686-linux, OK?

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();                                                                                                                                                  
} 

	PR tree-optimization/37345
	PR tree-optimizatoin/37358
	PR tree-optimizatoin/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.

Index: tree.c
===================================================================
--- tree.c	(revision 139938)
+++ tree.c	(working copy)
@@ -5925,7 +5925,12 @@ build_function_type_skip_args (tree orig
       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
   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;
 }
 



More information about the Gcc-patches mailing list