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: 602779 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qZ43G2T0rz9s8d for ; Tue, 29 Mar 2016 19:40:10 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=k6msneRT; dkim-atps=neutral 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=rDa3oNQH9jZJ7dC29eb6nLYDVX6u9sxr58P1RQ58GDzPgA zzXlCIRBNCYCbN1hhgOsM9z389aJ1dCiPYPw1te1qSR7iegyfkhbmaS8DCE1cKTu uZC1VMBu0xOaCkUK9dpapQzmc1vGF8FwHO4U452tSePDMnoEKF0No0YRrpG8Y= 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=k6msneRT3fFqKkPjk1K+ DdBYjrjx5p0W2mR1IHQYjV2nAWrzumI0m+qNvVzMIc8GgxnH+cKDK7uhA3a4pZZj uASMST5AU29s9al6oJvdBDeGx3t4//nXhayeLeSOg73P7SHt9efyw2r5c+iTGHzD YGkH6/1PhItFAe/QDOwPDQc= 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