From patchwork Mon Nov 21 20:37:09 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Torvald Riegel X-Patchwork-Id: 126925 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 C24A2B6F75 for ; Tue, 22 Nov 2011 07:37:34 +1100 (EST) Received: (qmail 17673 invoked by alias); 21 Nov 2011 20:37:32 -0000 Received: (qmail 17576 invoked by uid 22791); 21 Nov 2011 20:37:31 -0000 X-SWARE-Spam-Status: No, hits=-7.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS 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 Nov 2011 20:37:13 +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 pALKbCOe001701 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 21 Nov 2011 15:37:12 -0500 Received: from [10.36.6.232] (vpn1-6-232.ams2.redhat.com [10.36.6.232]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id pALKbAQo008308; Mon, 21 Nov 2011 15:37:11 -0500 Subject: [patch] PR47747: Fix error messages for calls to transaction_unsafe virtual functions. From: Torvald Riegel To: GCC Patches Cc: Richard Henderson , Aldy Hernandez Date: Mon, 21 Nov 2011 21:37:09 +0100 Message-ID: <1321907829.12248.150.camel@triegel.csb> Mime-Version: 1.0 X-IsSubscribed: yes 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 This just tweaks the error message to use an expression (%qE) instead of a declaration (%qD) when we complain about an indirect call being unsafe. The output isn't very pretty, but it does seem to do the job. Also, if it is a direct call, it should hopefully always be some kind of expression. All the other uses of %qD I saw in trans-mem.c seemed to indeed be for full declarations AFAICT, so I left them as-is. OK for trunk? commit c7e5c91a935737a0725607a35b9e6bb9d67be09b Author: Torvald Riegel Date: Mon Nov 21 16:43:17 2011 +0100 PR47747: Fix error messages for calls to unsafe virtual functions. gcc/ * trans-mem.c (diagnose_tm_1): Print an expression instead of a declaration in error messages for indirect calls. testsuite/ g++.dg/tm/pr47747.C: New test. diff --git a/gcc/testsuite/g++.dg/tm/pr47747.C b/gcc/testsuite/g++.dg/tm/pr47747.C new file mode 100644 index 0000000..3b50904 --- /dev/null +++ b/gcc/testsuite/g++.dg/tm/pr47747.C @@ -0,0 +1,21 @@ +// { dg-do compile } +// { dg-options "-fgnu-tm -O" } + +class InputStream +{ + public: +// __attribute__((transaction_safe)) + virtual unsigned int readUint32 () = 0; +}; + +class Building +{ + public: + __attribute__((transaction_safe)) + Building (InputStream *stream); +}; + +Building::Building (InputStream *stream) +{ + stream->readUint32 (); /* { dg-error "InputStream::readUint32" } */ +} diff --git a/gcc/trans-mem.c b/gcc/trans-mem.c index 3c0bd60..347183b 100644 --- a/gcc/trans-mem.c +++ b/gcc/trans-mem.c @@ -659,13 +659,27 @@ diagnose_tm_1 (gimple_stmt_iterator *gsi, bool *handled_ops_p, if (TREE_CODE (fn) == ADDR_EXPR) fn = TREE_OPERAND (fn, 0); if (d->block_flags & DIAG_TM_SAFE) - error_at (gimple_location (stmt), - "unsafe function call %qD within " - "atomic transaction", fn); + { + if (direct_call_p) + error_at (gimple_location (stmt), + "unsafe function call %qD within " + "atomic transaction", fn); + else + error_at (gimple_location (stmt), + "unsafe function call %qE within " + "atomic transaction", fn); + } else - error_at (gimple_location (stmt), - "unsafe function call %qD within " - "% function", fn); + { + if (direct_call_p) + error_at (gimple_location (stmt), + "unsafe function call %qD within " + "% function", fn); + else + error_at (gimple_location (stmt), + "unsafe function call %qE within " + "% function", fn); + } } } }