From patchwork Fri Feb 22 14:53:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 222540 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 748C02C0090 for ; Sat, 23 Feb 2013 01:54:10 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1362149651; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=CGIw5Qg rFnsD63oN0K57SlwKzvI=; b=Y3QNmKubuKJ0V7qWIc4LWOMk5zORHuFN5rcjw3U qRMLF5WLXXZDa9jMUNkGPIy4NZwRmtxcFqOsYroPGxkjUBnCubAVCCjvfVEI3oA5 f1HSLnPZ7nalSeJnM7YzqvZRstfVT9so2/okTiuYTumNdD5oTDg7UM9QEYDcP8em 4A/I= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=mXjB5c5S178MIMZeJGUj45dL1Bua2vDMxmtHziIYciKw1x45qNRIHnUjWdocj7 B7d4Sf8cXSWSB5FeF+wiffbx2PZpNwlEXBZTFOfwsMXKa1wKm70r5EwFnFcS2F0i 8ikCZLoz3YasoiQFCbSNIbTjvN9I5I8LfX+Osqc6cB4cQ=; Received: (qmail 755 invoked by alias); 22 Feb 2013 14:54:03 -0000 Received: (qmail 746 invoked by uid 22791); 22 Feb 2013 14:54:02 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_TM 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; Fri, 22 Feb 2013 14:53:48 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1MErltg025866 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 22 Feb 2013 09:53:48 -0500 Received: from houston.quesejoda.com (vpn-54-222.rdu2.redhat.com [10.10.54.222]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r1MErlN3018088; Fri, 22 Feb 2013 09:53:47 -0500 Message-ID: <5127867A.1000507@redhat.com> Date: Fri, 22 Feb 2013 08:53:46 -0600 From: Aldy Hernandez User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: gcc-patches , Jason Merrill , Richard Henderson Subject: [PR 56419/c++]: C++ front end silently drops transactions 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 In the following snippet, the C++ front-end drops the transaction altogether: +int x = 0; +int inc_func(int i) { + for (int j = 0; j < i; ++j) + { + __transaction_atomic { x+=1; } + } + return 0; This was caused by http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186546 The problem here is that genericize_cp_loop() calls append_to_statement_list() to add the TRANSACTION_EXPR, but in this case, TREE_SIDE_EFFECTS is not set, so it is silently ignored. Frankly, I don't understand finish_transaction_stmt(), and why it sets TREE_SIDE_EFFECTS only if the [noexcept] clause is set. I'm C++ ignorant, but I would've thought the opposite to be true. Anyways, I've fixed the problem by setting TREE_SIDE_EFFECTS if the transaction body has side effects. Perhaps we should do this for build_transaction_expr() as well? What do y'all prefer? commit 01704e6a117846458dbc11cb76284504673f2d3c Author: Aldy Hernandez Date: Fri Feb 22 08:28:14 2013 -0600 PR c++/56419 * semantics.c (finish_transaction_stmt): Set TREE_SIDE_EFFECTS if the body has side effects. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 458ed26..c446cd6 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -5135,6 +5135,9 @@ finish_transaction_stmt (tree stmt, tree compound_stmt, int flags, tree noex) TRANSACTION_EXPR_BODY (stmt) = body; } + if (TREE_SIDE_EFFECTS (TRANSACTION_EXPR_BODY (stmt))) + TREE_SIDE_EFFECTS (stmt) = 1; + if (compound_stmt) finish_compound_stmt (compound_stmt); finish_stmt (); diff --git a/gcc/testsuite/g++.dg/tm/pr56419.C b/gcc/testsuite/g++.dg/tm/pr56419.C new file mode 100644 index 0000000..c9a33a8 --- /dev/null +++ b/gcc/testsuite/g++.dg/tm/pr56419.C @@ -0,0 +1,13 @@ +// { dg-do compile } +// { dg-options "-fgnu-tm" } + +int x = 0; +int inc_func(int i) { + for (int j = 0; j < i; ++j) + { + __transaction_atomic { x+=1; } + } + return 0; +} + +// { dg-final { scan-assembler "ITM_commitTransaction" } }