From patchwork Mon Feb 21 22:41:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 83884 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 EF453B6EEE for ; Tue, 22 Feb 2011 09:42:01 +1100 (EST) Received: (qmail 19253 invoked by alias); 21 Feb 2011 22:41:59 -0000 Received: (qmail 19244 invoked by uid 22791); 21 Feb 2011 22:41:58 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_TM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 21 Feb 2011 22:41:53 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p1LMfq0i013039 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 21 Feb 2011 17:41:52 -0500 Received: from houston.quesejoda.com (vpn-224-150.phx2.redhat.com [10.3.224.150]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p1LMfpPm022522; Mon, 21 Feb 2011 17:41:51 -0500 Message-ID: <4D62EA2F.7090306@redhat.com> Date: Mon, 21 Feb 2011 16:41:51 -0600 From: Aldy Hernandez User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b3pre Thunderbird/3.1.7 MIME-Version: 1.0 To: Richard Henderson , gcc-patches , Patrick MARLIER Subject: [trans-mem] PR47746: handle OBJ_TYPE_REF correctly 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 While building the call to TM_GETTMCLONE, we discard OBJ_TYPE_REF's if we can't fold them: /* Discard OBJ_TYPE_REF, since we weren't able to fold it. */ if (TREE_CODE (old_fn) == OBJ_TYPE_REF) old_fn = OBJ_TYPE_REF_EXPR (old_fn); However, this discard can get rid of an implicit conversion. In the attached testcase, the inner type of the OBJ_TYPE_REF_EXPR is signed, but the type of the OBJ_TYPE_REF_EXPR is unsigned. This causes an ICE while verifying the gimple call. I have fixed this by adding an appropriate conversion after the GETTMCLONE call. I can make sure the conversion only happens for the OBJ_TYPE_REF, but I was lazy. I don't think it'll hurt. OK for branch? PR 47746 * trans-mem.c (ipa_tm_insert_gettmclone_call): Verify type compatibility in call. Index: testsuite/g++.dg/tm/pr47746.C =================================================================== --- testsuite/g++.dg/tm/pr47746.C (revision 0) +++ testsuite/g++.dg/tm/pr47746.C (revision 0) @@ -0,0 +1,27 @@ +// { dg-do compile } +// { dg-options "-fgnu-tm" } + +class InputStream +{ + public: + virtual unsigned int readUint32 () = 0; +}; + +class Building +{ + public: + __attribute__((transaction_safe)) Building (InputStream *stream); + __attribute__((transaction_safe)) void freeGradients (); + void load (InputStream *stream); +}; + +Building::Building (InputStream *stream) +{ + load(stream); +} + +void Building::load (InputStream *stream) +{ + int j = (int)stream->readUint32 (); + freeGradients (); +} Index: trans-mem.c =================================================================== --- trans-mem.c (revision 170360) +++ trans-mem.c (working copy) @@ -4274,6 +4274,27 @@ ipa_tm_insert_gettmclone_call (struct cg gimple_call_set_noinline_p (stmt); gimple_call_set_fn (stmt, callfn); + + /* Discard OBJ_TYPE_REF above, may produce incompatible LHS and RHS + for a call statement. Fix it. */ + { + tree lhs = gimple_call_lhs (stmt); + tree rettype = TREE_TYPE (TREE_TYPE (TREE_TYPE (callfn))); + if (lhs + && !useless_type_conversion_p (TREE_TYPE (lhs), rettype)) + { + tree temp; + + temp = make_rename_temp (rettype, 0); + gimple_call_set_lhs (stmt, temp); + + g2 = gimple_build_assign (lhs, + fold_build1 (VIEW_CONVERT_EXPR, + TREE_TYPE (lhs), temp)); + gsi_insert_after (gsi, g2, GSI_SAME_STMT); + } + } + update_stmt (stmt); return true;