Patchwork [c++] Fix invalid type conversion in vtable constructors

login
register
mail settings
Submitter Jan Hubicka
Date Sept. 9, 2010, 1:50 p.m.
Message ID <20100909135031.GC19675@kam.mff.cuni.cz>
Download mbox | patch
Permalink /patch/64301/
State New
Headers show

Comments

Jan Hubicka - Sept. 9, 2010, 1:50 p.m.
Hi,
fixing constant folding on array constructors with implicit indexes leads to
problem with C++ frontend producing wrong ADDR_EXPR in constructors of vtables.
ADDR_EXPR type is vfunc_ptr_type_node while the METHOD_DECL within ADDR_EXPR
has type corresponding to the partiuclar virtual function.

This patch adds the missing NOP_EXPR to avoid ICE with the folding patch i
would like to submit.

Bootstrapped/regtested x86_64-linux, OK?

Honza

	PR tree-optimization/45605
	* cp/class.c (build_vtbl_initializer): Avoid wrong type conversion in ADDR_EXPR
Mark Mitchell - Sept. 9, 2010, 2:03 p.m.
On 9/9/2010 6:50 AM, Jan Hubicka wrote:

> 	PR tree-optimization/45605
> 	* cp/class.c (build_vtbl_initializer): Avoid wrong type conversion in ADDR_EXPR

OK.
H.J. Lu - Sept. 10, 2010, 2:53 p.m.
On Thu, Sep 9, 2010 at 6:50 AM, Jan Hubicka <hubicka@ucw.cz> wrote:
> Hi,
> fixing constant folding on array constructors with implicit indexes leads to
> problem with C++ frontend producing wrong ADDR_EXPR in constructors of vtables.
> ADDR_EXPR type is vfunc_ptr_type_node while the METHOD_DECL within ADDR_EXPR
> has type corresponding to the partiuclar virtual function.
>
> This patch adds the missing NOP_EXPR to avoid ICE with the folding patch i
> would like to submit.
>
> Bootstrapped/regtested x86_64-linux, OK?
>
> Honza
>
>        PR tree-optimization/45605
>        * cp/class.c (build_vtbl_initializer): Avoid wrong type conversion in ADDR_EXPR

This may have caused:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45635

Patch

Index: cp/class.c
===================================================================
--- cp/class.c	(revision 164080)
+++ cp/class.c	(working copy)
@@ -7797,7 +7797,8 @@  build_vtbl_initializer (tree binfo,
 	    {
 	      fn = abort_fndecl;
 	      if (abort_fndecl_addr == NULL)
-		abort_fndecl_addr = build1 (ADDR_EXPR, vfunc_ptr_type_node, fn);
+		abort_fndecl_addr = fold_convert (vfunc_ptr_type_node,
+					          build_fold_addr_expr (fn));
 	      init = abort_fndecl_addr;
 	    }
 	  else
@@ -7810,7 +7810,7 @@  build_vtbl_initializer (tree binfo,
 		}
 	      /* Take the address of the function, considering it to be of an
 		 appropriate generic type.  */
-	      init = build1 (ADDR_EXPR, vfunc_ptr_type_node, fn);
+	      init = fold_convert (vfunc_ptr_type_node, build_fold_addr_expr (fn));
 	    }
 	}