From patchwork Tue Mar 29 08:39:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 64583 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp1879535lbc; Tue, 29 Mar 2016 01:40:17 -0700 (PDT) X-Received: by 10.66.199.66 with SMTP id ji2mr1540382pac.34.1459240817473; Tue, 29 Mar 2016 01:40:17 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id uq12si8144690pab.30.2016.03.29.01.40.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Mar 2016 01:40:17 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-423916-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-423916-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-423916-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=U9KnsmI2fjTiHF1ipdQw20wtuRqU8jbrmG07dXD9KPE8iN Jy8KN2DrlEUcpuOibbr/VgDg8I9RfSCSzdCYwhD/H6B8Leg5WMUhvkCu7Jrlv3qc iR5fSSnxkWsGNWH254cwnOdH4FsK6s2yddoKPoqCC413p6PJoggR/ARZUSyLE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=NYFyUAL53IWiLWubpXw5CrvV9qg=; b=eJ3qs4jed1ug4kWF8NfQ ws0I9VXizJhEUWw+NTpMMJjGcByl4jvOqtGfw0CZhoQmBLO80Gxo8CNoqXHKd9U8 j1XjofsxIRcNnEJPIGs6r1yfQYAhizDyNRCravM3eiV4n9bivtYqXzJomjAASvCw Q2LeYgZY0aK8EfHFqxghvIQ= Received: (qmail 61088 invoked by alias); 29 Mar 2016 08:39:59 -0000 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 Received: (qmail 61073 invoked by uid 89); 29 Mar 2016 08:39:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=captures X-HELO: mail-ig0-f176.google.com Received: from mail-ig0-f176.google.com (HELO mail-ig0-f176.google.com) (209.85.213.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 29 Mar 2016 08:39:48 +0000 Received: by mail-ig0-f176.google.com with SMTP id av4so71934400igc.1 for ; Tue, 29 Mar 2016 01:39:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to; bh=JIaH1WU8L9mXCJ8Y+356SK7bFA2UXKr+INEuUlPZBFQ=; b=MQS8XN31w5nJThLgRhjruE5spLqSi0ylsjkvee+kQMUWfLdYcGoSByYhK3bxraAZ5X I8pqyq5EKGHslOIZEXILuC1YspZCSC33EGSLp8UsJw1ChmnZjuunU+FnzY0UCLM+92h3 TudQR+CcB2NNS2iW5st3jbC8GCBV5nIQ+qfr1T4YzQxE5OCar7uYSWF29aIvqVjqkAMu nRlWQNN0mIz9jELko6B3aL1ZgaAcPq9LhxEnX6IVqbnZJyFvd9YGhsnrPV5sDiAj8bAQ Rr2TC34fFDswfQC5cIHPo8C++trjRq3VCFbh6US0JIbMPyE9nrTgYhUEEbIQwn8QRHYs wxPA== X-Gm-Message-State: AD7BkJLzOjdCSR/aWR9tK4t/IwutWGV43UqtPK2pmo8hivZFTyAFAUjE5DUhJf9ESGCJAlT38aL7z+bALmY2WqUN MIME-Version: 1.0 X-Received: by 10.50.111.8 with SMTP id ie8mr14655175igb.46.1459240786318; Tue, 29 Mar 2016 01:39:46 -0700 (PDT) Received: by 10.36.69.101 with HTTP; Tue, 29 Mar 2016 01:39:46 -0700 (PDT) Date: Tue, 29 Mar 2016 14:09:46 +0530 Message-ID: Subject: [genmatch] reject duplicate captures used as arguments in user-defined predicates From: Prathamesh Kulkarni To: Richard Biener , gcc Patches X-IsSubscribed: yes Hi, I suppose we should reject duplicate captures used as "arguments" in user defined predicates ? eg: (match (foo @0 @0) match-template) The attached patch prints error "duplicate capture id" for above pattern. Bootstrapped+tested on x86_64-pc-linux-gnu. Ok for trunk ? Thanks, Prathamesh diff --git a/gcc/genmatch.c b/gcc/genmatch.c index 1f5f45c..eca5508 100644 --- a/gcc/genmatch.c +++ b/gcc/genmatch.c @@ -3602,7 +3602,7 @@ private: const char *get_number (); id_base *parse_operation (); - operand *parse_capture (operand *, bool); + operand *parse_capture (operand *, bool, bool); operand *parse_expr (); c_expr *parse_c_expr (cpp_ttype); operand *parse_op (); @@ -3832,7 +3832,7 @@ parser::parse_operation () capture = '@' */ struct operand * -parser::parse_capture (operand *op, bool require_existing) +parser::parse_capture (operand *op, bool require_existing, bool error_on_existing = false) { source_location src_loc = eat_token (CPP_ATSIGN)->src_loc; const cpp_token *token = peek (); @@ -3852,6 +3852,8 @@ parser::parse_capture (operand *op, bool require_existing) fatal_at (src_loc, "unknown capture id"); num = next_id; } + else if (error_on_existing) + fatal_at (src_loc, "duplicate capture id"); return new capture (src_loc, num, op); } @@ -4530,7 +4532,7 @@ parser::parse_pattern () capture_ids = new cid_map_t; e = new expr (p, e_loc); while (peek ()->type == CPP_ATSIGN) - e->append_op (parse_capture (NULL, false)); + e->append_op (parse_capture (NULL, false, true)); eat_token (CPP_CLOSE_PAREN); } if (p->nargs != -1