This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC 3.2


On Tue, 30 Jul 2002 00:32:14 +0100, Jason Merrill <jason@redhat.com> wrote:

> It's possible that we are copying the tail padding when assigning a C3; I'm
> not seeing that, but am continuing to investigate.

Indeed we are; I needed to specify -malign-double so there would be tail
padding on the x86 for us to handle wrong.  :)

> If so, that's a serious bug, but fixing it will not impact the ABI.  In
> other words, it can wait for 3.2.1.

This is still true, but I have a preliminary patch for which testing is not
yet complete, which adds a langhook to expr_size.  I believe that returning
the unpadded size from expr_size is correct, as expr_size is interested in
the value, not the allocated space.  Comments welcome.  The other option
was to add another size field to types; a langhook seemed more
space-efficient.

With this patch, the empty class passing hackery can go away, hurrah.

BTW, why do we use stubs for langhook defaults?  I would think leaving the
hook entry NULL would be more efficient for languages that are happy with
the default, as a comparison to zero is much cheaper than an indirect
jump...

2002-07-31  Jason Merrill  <jason@redhat.com>

	* langhooks-def.h (LANG_HOOKS_EXPR_SIZE): New macro.
	* langhooks.c (lhd_expr_size): Define default.
	* langhooks.h (struct lang_hooks): Add expr_size.
	* explow.c (expr_size): Call it.

2002-07-31  Jason Merrill  <jason@redhat.com>

	* class.c (cp_expr_size): New fn.
	* cp-tree.h: Declare it.
	* cp-lang.c (LANG_HOOKS_EXPR_SIZE): Define.
	* call.c (build_over_call): Lose empty class hackery.

*** ./cp/class.c.~1~	Tue Jul 30 00:43:54 2002
--- ./cp/class.c	Tue Jul 30 17:49:25 2002
*************** build_vtable_entry (delta, vcall_index, 
*** 8048,8050 ****
--- 8048,8065 ----
  #endif
    return entry;
  }
+ 
+ /* Langhook for expr_size: Tell the backend that the value of an expression
+    of non-POD class type does not include any tail padding; a derived class
+    might have allocated something there.  */
+ 
+ tree
+ cp_expr_size (exp)
+      tree exp;
+ {
+   if (CLASS_TYPE_P (TREE_TYPE (exp)))
+     return CLASSTYPE_SIZE_UNIT (TREE_TYPE (exp));
+   else
+     /* Use the default code.  */
+     return NULL_TREE;
+ }
*** ./cp/cp-lang.c.~1~	Sun May 26 17:23:43 2002
--- ./cp/cp-lang.c	Tue Jul 30 15:41:20 2002
*************** static HOST_WIDE_INT cxx_get_alias_set P
*** 91,96 ****
--- 91,98 ----
  #define LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN cp_dump_tree
  #undef LANG_HOOKS_TREE_DUMP_TYPE_QUALS_FN
  #define LANG_HOOKS_TREE_DUMP_TYPE_QUALS_FN cp_type_quals
+ #undef LANG_HOOKS_EXPR_SIZE
+ #define LANG_HOOKS_EXPR_SIZE cp_expr_size
  
  /* Each front end provides its own hooks, for toplev.c.  */
  const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
*** ./cp/cp-tree.h.~1~	Tue Jul 30 00:43:55 2002
--- ./cp/cp-tree.h	Tue Jul 30 15:52:07 2002
*************** extern tree get_vtbl_decl_for_binfo     
*** 3628,3633 ****
--- 3628,3634 ----
  extern tree in_charge_arg_for_name              PARAMS ((tree));
  extern tree get_vtt_name                        PARAMS ((tree));
  extern tree get_primary_binfo                   PARAMS ((tree));
+ extern tree cp_expr_size			PARAMS ((tree));
  
  /* in cvt.c */
  extern tree convert_to_reference		PARAMS ((tree, tree, int, int, tree));
*** ./cp/call.c.~1~	Thu May  9 16:55:25 2002
--- ./cp/call.c	Tue Jul 30 17:42:58 2002
*************** build_over_call (cand, args, flags)
*** 4298,4312 ****
  	  else if (TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn)))
  	    return build_target_expr_with_type (arg, DECL_CONTEXT (fn));
  	}
!       else if ((!real_lvalue_p (arg)
! 		|| TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn)))
! 	       /* Empty classes have padding which can be hidden
! 	          inside an (empty) base of the class. This must not
! 	          be touched as it might overlay things. When the
! 	          gcc core learns about empty classes, we can treat it
! 	          like other classes. */
! 	       && !(is_empty_class (DECL_CONTEXT (fn))
! 		    && TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn))))
  	{
  	  tree address;
  	  tree to = stabilize_reference
--- 4298,4305 ----
  	  else if (TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn)))
  	    return build_target_expr_with_type (arg, DECL_CONTEXT (fn));
  	}
!       else if (!real_lvalue_p (arg)
! 	       || TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn)))
  	{
  	  tree address;
  	  tree to = stabilize_reference
*************** build_over_call (cand, args, flags)
*** 4328,4351 ****
  	(build_indirect_ref (TREE_VALUE (converted_args), 0));
  
        arg = build_indirect_ref (TREE_VALUE (TREE_CHAIN (converted_args)), 0);
!       if (is_empty_class (TREE_TYPE (to)))
! 	{
! 	  TREE_USED (arg) = 1;
! 
! 	  val = build (COMPOUND_EXPR, DECL_CONTEXT (fn), arg, to);
! 	  /* Even though the assignment may not actually result in any
! 	     code being generated, we do not want to warn about the
! 	     assignment having no effect.  That would be confusing to
! 	     users who may be performing the assignment as part of a
! 	     generic algorithm, for example.
! 	     
! 	     Ideally, the notions of having side-effects and of being
! 	     useless would be orthogonal.  */
! 	  TREE_SIDE_EFFECTS (val) = 1;
! 	  TREE_NO_UNUSED_WARNING (val) = 1;
! 	}
!       else
! 	val = build (MODIFY_EXPR, TREE_TYPE (to), to, arg);
        return val;
      }
  
--- 4321,4327 ----
  	(build_indirect_ref (TREE_VALUE (converted_args), 0));
  
        arg = build_indirect_ref (TREE_VALUE (TREE_CHAIN (converted_args)), 0);
!       val = build (MODIFY_EXPR, TREE_TYPE (to), to, arg);
        return val;
      }
  
*** ./explow.c.~1~	Sun Mar 17 17:48:49 2002
--- ./explow.c	Tue Jul 30 17:36:43 2002
*************** Software Foundation, 59 Temple Place - S
*** 34,39 ****
--- 34,40 ----
  #include "insn-config.h"
  #include "ggc.h"
  #include "recog.h"
+ #include "langhooks.h"
  
  static rtx break_out_memory_refs	PARAMS ((rtx));
  static void emit_stack_probe		PARAMS ((rtx));
*************** rtx
*** 285,294 ****
  expr_size (exp)
       tree exp;
  {
!   tree size;
  
!   if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'd'
!       && DECL_SIZE_UNIT (exp) != 0)
      size = DECL_SIZE_UNIT (exp);
    else
      size = size_in_bytes (TREE_TYPE (exp));
--- 286,297 ----
  expr_size (exp)
       tree exp;
  {
!   tree size = (*lang_hooks.expr_size) (exp);
  
!   if (size)
!     /* The frontend specified a size.  */;
!   else if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'd'
! 	   && DECL_SIZE_UNIT (exp) != 0)
      size = DECL_SIZE_UNIT (exp);
    else
      size = size_in_bytes (TREE_TYPE (exp));
*************** expr_size (exp)
*** 298,304 ****
      size = build (WITH_RECORD_EXPR, sizetype, size, exp);
  
    return expand_expr (size, NULL_RTX, TYPE_MODE (sizetype), 0);
- 
  }
  
  /* Return a copy of X in which all memory references
--- 301,306 ----
*** ./langhooks.h.~1~	Sun May 26 17:22:52 2002
--- ./langhooks.h	Tue Jul 30 17:41:11 2002
*************** struct lang_hooks
*** 156,161 ****
--- 156,165 ----
       warning that the front end does not use such a parser.  */
    void (*set_yydebug) PARAMS ((int));
  
+   /* Called from expr_size to calculate the size of the value of an
+      expression in a language-dependent way.  */
+   tree (*expr_size) PARAMS ((tree));
+ 
    struct lang_hooks_for_tree_inlining tree_inlining;
    
    struct lang_hooks_for_tree_dump tree_dump;
*** ./langhooks-def.h.~1~	Sun May 26 17:22:51 2002
--- ./langhooks-def.h	Tue Jul 30 16:02:44 2002
*************** extern int lhd_staticp PARAMS ((tree));
*** 48,53 ****
--- 48,54 ----
  extern void lhd_clear_binding_stack PARAMS ((void));
  extern void lhd_print_tree_nothing PARAMS ((FILE *, tree, int));
  extern void lhd_set_yydebug PARAMS ((int));
+ extern tree lhd_expr_size PARAMS ((tree));
  
  /* Declarations of default tree inlining hooks.  */
  tree lhd_tree_inlining_walk_subtrees		PARAMS ((tree *, int *,
*************** tree lhd_tree_inlining_convert_parm_for_
*** 85,90 ****
--- 86,92 ----
  #define LANG_HOOKS_PRINT_TYPE		lhd_print_tree_nothing
  #define LANG_HOOKS_PRINT_IDENTIFIER	lhd_print_tree_nothing
  #define LANG_HOOKS_SET_YYDEBUG		lhd_set_yydebug
+ #define LANG_HOOKS_EXPR_SIZE		lhd_expr_size
  
  /* Tree inlining hooks.  */
  #define LANG_HOOKS_TREE_INLINING_WALK_SUBTREES lhd_tree_inlining_walk_subtrees
*************** int lhd_tree_dump_type_quals			PARAMS ((
*** 156,161 ****
--- 158,164 ----
    LANG_HOOKS_PRINT_TYPE, \
    LANG_HOOKS_PRINT_IDENTIFIER, \
    LANG_HOOKS_SET_YYDEBUG, \
+   LANG_HOOKS_EXPR_SIZE, \
    LANG_HOOKS_TREE_INLINING_INITIALIZER, \
    LANG_HOOKS_TREE_DUMP_INITIALIZER \
  }
*** ./langhooks.c.~1~	Wed Apr  3 20:59:05 2002
--- ./langhooks.c	Tue Jul 30 17:40:03 2002
*************** lhd_tree_dump_type_quals (t)
*** 303,305 ****
--- 303,314 ----
    return TYPE_QUALS (t);
  }
  
+ /* lang_hooks.expr_size: Determine the size of the value of an expression T
+    in a language-specific way.  */
+ 
+ tree
+ lhd_expr_size (t)
+      tree t ATTRIBUTE_UNUSED;
+ {
+   return NULL_TREE;
+ }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]