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]

[C++ PATCH] Minor type safety issue building RTTI type info


The following patch is another facet of the middle-end TREE_OVERFLOW
clean-up.  It turns out that cp/rtti.c's get_pseudo_ti_init constructs
the initializers for base type info, with a mismatched type.  The
__base_class_type_info_pseudo struct maintains an offset field that
should be of "itk_long" type, but the initializer that we construct
for it, contains mistyped constants that are unsigned.  This would
normally be harmless, but because the C++ front-end is using it's own
high-level front-end conversion routines, some changes I've been
investigating manage to trigger a compiler warning when using -Wall :-)

The patch below tweaks this code both to build the correct type, and
to use the lower-level middle-end interfaces for constructing these
"internal" trees (to avoid any possibility of issuing inappropriate
diagnostics).


The following patch has been tested on x86_64-unknown-linux-gnu, with
a full "make boostrap", all default languages, and regression tested
with a top-level "make -k check" with no new failures.

Ok for mainline?



2006-11-12  Roger Sayle  <roger@eyesopen.com>

	* rtti.c (get_pseudo_ti_init): Ensure that the offset field of the
	base type info initializer has the correct type.


Index: rtti.c
===================================================================
*** rtti.c	(revision 118625)
--- rtti.c	(working copy)
*************** get_pseudo_ti_init (tree type, unsigned
*** 1037,1042 ****
--- 1037,1043 ----
  	tree binfo = TYPE_BINFO (type);
  	int nbases = BINFO_N_BASE_BINFOS (binfo);
  	VEC(tree,gc) *base_accesses = BINFO_BASE_ACCESSES (binfo);
+ 	tree offset_type = integer_types[itk_long];
  	tree base_inits = NULL_TREE;
  	int ix;

*************** get_pseudo_ti_init (tree type, unsigned
*** 1059,1075 ****
  		/* We store the vtable offset at which the virtual
  		   base offset can be found.  */
  		offset = BINFO_VPTR_FIELD (base_binfo);
- 		offset = convert (sizetype, offset);
  		flags |= 1;
  	      }
  	    else
  	      offset = BINFO_OFFSET (base_binfo);

  	    /* Combine offset and flags into one field.  */
! 	    offset = cp_build_binary_op (LSHIFT_EXPR, offset,
! 					 build_int_cst (NULL_TREE, 8));
! 	    offset = cp_build_binary_op (BIT_IOR_EXPR, offset,
! 					 build_int_cst (NULL_TREE, flags));
  	    base_init = tree_cons (NULL_TREE, offset, base_init);
  	    base_init = tree_cons (NULL_TREE, tinfo, base_init);
  	    base_init = build_constructor_from_list (NULL_TREE, base_init);
--- 1060,1076 ----
  		/* We store the vtable offset at which the virtual
  		   base offset can be found.  */
  		offset = BINFO_VPTR_FIELD (base_binfo);
  		flags |= 1;
  	      }
  	    else
  	      offset = BINFO_OFFSET (base_binfo);

  	    /* Combine offset and flags into one field.  */
! 	    offset = fold_convert (offset_type, offset);
! 	    offset = fold_build2 (LSHIFT_EXPR, offset_type, offset,
! 				  build_int_cst (offset_type, 8));
! 	    offset = fold_build2 (BIT_IOR_EXPR, offset_type, offset,
! 				  build_int_cst (offset_type, flags));
  	    base_init = tree_cons (NULL_TREE, offset, base_init);
  	    base_init = tree_cons (NULL_TREE, tinfo, base_init);
  	    base_init = build_constructor_from_list (NULL_TREE, base_init);


Roger
--


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