From patchwork Thu Sep 9 13:50:31 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 64301 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 4E6B8B70D1 for ; Thu, 9 Sep 2010 23:51:15 +1000 (EST) Received: (qmail 21016 invoked by alias); 9 Sep 2010 13:51:11 -0000 Received: (qmail 21004 invoked by uid 22791); 9 Sep 2010 13:51:09 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, TW_FN, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from nikam-dmz.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 09 Sep 2010 13:50:33 +0000 Received: from localhost (occam.ms.mff.cuni.cz [195.113.18.121]) by nikam.ms.mff.cuni.cz (Postfix) with ESMTP id 661C89ACA81; Thu, 9 Sep 2010 15:50:31 +0200 (CEST) Received: by localhost (Postfix, from userid 16202) id 613CB5641B5; Thu, 9 Sep 2010 15:50:31 +0200 (CEST) Date: Thu, 9 Sep 2010 15:50:31 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org, rguenther@suse.de, mark@codesourcery.com Subject: [c++] Fix invalid type conversion in vtable constructors Message-ID: <20100909135031.GC19675@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 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)); } }