This is the mail archive of the gcc@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]

[RFC] Fix ADDR_EXPR type mismatches in C++ frontend


With this patch we can build the C++ frontend and libraries
with an instrumented build1 that checks ADDR_EXPR types to
match as far as sharing the same TYPE_MAIN_VARIANT.

Comments?

Richard.


2005-05-18  Richard Guenther  <rguenth@gcc.gnu.org>

	* class.c (dfs_accumulate_vtbl_inits): Create ADDR_EXPR
	with correct types.
	(build_vtbl_initializer): Likewise.
	* except.c (build_throw): Likewise.

	* tree.c (build1_stat): Instrument for incorrectly typed
	ADDR_EXPRs.


Index: cp/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/class.c,v
retrieving revision 1.717
diff -c -3 -p -r1.717 class.c
*** cp/class.c	8 May 2005 02:17:54 -0000	1.717
--- cp/class.c	18 May 2005 12:03:12 -0000
*************** dfs_accumulate_vtbl_inits (tree binfo,
*** 7069,7075 ****

        /* Figure out the position to which the VPTR should point.  */
        vtbl = TREE_PURPOSE (l);
!       vtbl = build1 (ADDR_EXPR, vtbl_ptr_type_node, vtbl);
        index = size_binop (PLUS_EXPR,
  			  size_int (non_fn_entries),
  			  size_int (list_length (TREE_VALUE (l))));
--- 7069,7075 ----

        /* Figure out the position to which the VPTR should point.  */
        vtbl = TREE_PURPOSE (l);
!       vtbl = build_fold_addr_expr (vtbl);
        index = size_binop (PLUS_EXPR,
  			  size_int (non_fn_entries),
  			  size_int (list_length (TREE_VALUE (l))));
*************** build_vtbl_initializer (tree binfo,
*** 7247,7253 ****
  	    {
  	      fn = abort_fndecl;
  	      if (abort_fndecl_addr == NULL)
! 		abort_fndecl_addr = build1 (ADDR_EXPR, vfunc_ptr_type_node, fn);
  	      init = abort_fndecl_addr;
  	    }
  	  else
--- 7247,7254 ----
  	    {
  	      fn = abort_fndecl;
  	      if (abort_fndecl_addr == NULL)
! 		abort_fndecl_addr = convert (vfunc_ptr_type_node,
! 					     build_fold_addr_expr (fn));
  	      init = abort_fndecl_addr;
  	    }
  	  else
*************** build_vtbl_initializer (tree binfo,
*** 7260,7266 ****
  		}
  	      /* Take the address of the function, considering it to be of an
  		 appropriate generic type.  */
! 	      init = build1 (ADDR_EXPR, vfunc_ptr_type_node, fn);
  	    }
  	}

--- 7261,7268 ----
  		}
  	      /* Take the address of the function, considering it to be of an
  		 appropriate generic type.  */
! 	      init = convert (vfunc_ptr_type_node,
! 			      build_fold_addr_expr (fn));
  	    }
  	}

Index: cp/except.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/except.c,v
retrieving revision 1.182
diff -c -3 -p -r1.182 except.c
*** cp/except.c	23 Apr 2005 21:28:53 -0000	1.182
--- cp/except.c	18 May 2005 12:03:21 -0000
*************** build_throw (tree exp)
*** 744,750 ****
  	  mark_used (cleanup);
  	  cxx_mark_addressable (cleanup);
  	  /* Pretend it's a normal function.  */
! 	  cleanup = build1 (ADDR_EXPR, cleanup_type, cleanup);
  	}
        else
  	cleanup = build_int_cst (cleanup_type, 0);
--- 744,751 ----
  	  mark_used (cleanup);
  	  cxx_mark_addressable (cleanup);
  	  /* Pretend it's a normal function.  */
! 	  cleanup = convert (cleanup_type,
! 			     build_fold_addr_expr (cleanup));
  	}
        else
  	cleanup = build_int_cst (cleanup_type, 0);
Index: tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.c,v
retrieving revision 1.479
diff -c -3 -p -r1.479 tree.c
*** tree.c	11 May 2005 16:25:29 -0000	1.479
--- tree.c	18 May 2005 12:05:56 -0000
*************** build1_stat (enum tree_code code, tree t
*** 2560,2565 ****
--- 2560,2569 ----
      case ADDR_EXPR:
        if (node)
  	recompute_tree_invarant_for_addr_expr (t);
+       if (TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) != ARRAY_TYPE
+ 	  && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (t)))
+ 	     != TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (t, 0))))
+ 	gcc_unreachable ();
        break;

      default:


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