From patchwork Sat Nov 5 00:34:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 123724 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 62089B6F9A for ; Sat, 5 Nov 2011 11:35:24 +1100 (EST) Received: (qmail 27931 invoked by alias); 5 Nov 2011 00:35:21 -0000 Received: (qmail 27825 invoked by uid 22791); 5 Nov 2011 00:35:20 -0000 X-SWARE-Spam-Status: No, hits=-7.0 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; Sat, 05 Nov 2011 00:34:59 +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 pA50YxAN012531 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 4 Nov 2011 20:34:59 -0400 Received: from anchor.twiddle.net (vpn-225-81.phx2.redhat.com [10.3.225.81]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id pA50Yw4J024574; Fri, 4 Nov 2011 20:34:58 -0400 Message-ID: <4EB484B2.6010409@redhat.com> Date: Fri, 04 Nov 2011 17:34:58 -0700 From: Richard Henderson User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0) Gecko/20110927 Thunderbird/7.0 MIME-Version: 1.0 To: GCC Patches CC: Jason Merrill , Torvald Riegel Subject: [trans-mem] Avoid ICE with transaction expressions vs constant expressions. 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 There we actually two ICEs here -- one with -fgnu-tm that Torvald pointed me at, and one without -fgnu-tm that I of course stumbled upon while fumble-fingering the command-line to test the thing. Committed to branch. r~ * cp/parser.c (enum non_integral_constant): Add NIC_TRANSACTION. (cp_parser_non_integral_constant_expression): Handle it. (cp_parser_transaction_expression): Generate an error if TM is not enabled. Use cp_parser_non_integral_constant_expression. * testsuite/c-c++-common/tm/trxn-expr-2.c: New test. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index d52a75d..7a7cfe8 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -106,7 +106,9 @@ typedef enum non_integral_constant { /* a comma operator */ NIC_COMMA, /* a call to a constructor */ - NIC_CONSTRUCTOR + NIC_CONSTRUCTOR, + /* a transaction expression */ + NIC_TRANSACTION } non_integral_constant; /* The various kinds of errors about name-lookup failing. */ @@ -2682,6 +2684,10 @@ cp_parser_non_integral_constant_expression (cp_parser *parser, error ("a call to a constructor " "cannot appear in a constant-expression"); return true; + case NIC_TRANSACTION: + error ("a transaction expression " + "cannot appear in a constant-expression"); + return true; case NIC_THIS: msg = "this"; break; @@ -26656,6 +26662,14 @@ cp_parser_transaction_expression (cp_parser *parser, enum rid keyword) gcc_assert (keyword == RID_TRANSACTION_ATOMIC || keyword == RID_TRANSACTION_RELAXED); + + if (!flag_tm) + error (keyword == RID_TRANSACTION_RELAXED + ? "%<__transaction_relaxed%> without transactional memory " + "support enabled" + : "%<__transaction_atomic%> without transactional memory " + "support enabled"); + token = cp_parser_require_keyword (parser, keyword, (keyword == RID_TRANSACTION_ATOMIC ? RT_TRANSACTION_ATOMIC : RT_TRANSACTION_RELAXED)); @@ -26680,7 +26694,10 @@ cp_parser_transaction_expression (cp_parser *parser, enum rid keyword) } parser->in_transaction = old_in; - return ret; + if (cp_parser_non_integral_constant_expression (parser, NIC_TRANSACTION)) + return error_mark_node; + + return (flag_tm ? ret : error_mark_node); } /* Parse a function-transaction-block. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index cb92178..e75589e 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -8140,6 +8140,7 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags) case STMT_EXPR: case EXPR_STMT: case BIND_EXPR: + case TRANSACTION_EXPR: if (flags & tf_error) error ("expression %qE is not a constant-expression", t); return false; diff --git a/gcc/testsuite/c-c++-common/tm/trxn-expr-2.c b/gcc/testsuite/c-c++-common/tm/trxn-expr-2.c new file mode 100644 index 0000000..0ef6526 --- /dev/null +++ b/gcc/testsuite/c-c++-common/tm/trxn-expr-2.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* Make sure that we don't just crash without -fgnu-tm enabled. */ +/* { dg-options "" } */ + +int x; + +int foo(void) +{ + return __transaction_atomic (x + 1); /* { dg-error "" } */ +} + +int bar(void) +{ + return __transaction_relaxed (x + 1); /* { dg-error "" } */ +}