From patchwork Mon Oct 31 15:45:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 689413 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 3t6zJ82GBlz9t80 for ; Tue, 1 Nov 2016 02:47:04 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=ArwrqYmi; 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:date :from:to:cc:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=rUJSD9ZGLO27V93nH 2LmJc2w1k+5T7neIYEFAP31ihbO3LCRgngvqypBp56jJLtfs7s3jsraTPwbTsBgQ +KGaAwGyUMaxLG3E9c5BL7bAnZJu5kPJ1WYe89XxwVN3A4CS/lEeRie7mzmrUgQL e0lukOdSkSO2sP2Z8kVW/ojosU= 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:date :from:to:cc:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; s=default; bh=0jgRnWUFjmvjr4V3YiKq38G iue8=; b=ArwrqYmi8mtY9MGJfZozsV1dOK5a/k/FAgn13t9AV6/WCNFvnEmLpJb DPBNxLdfEr4ZzIGFBxK5D9mfkbW3tshsmB/HZir4kQkZRPBhILJp89+10+V7hP7l d+2IdPEZ2qox23W26cVLv+jOm8jbNsDgQTLfxLrzjulzdEDjdlZI= Received: (qmail 66516 invoked by alias); 31 Oct 2016 15:45:52 -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 66413 invoked by uid 89); 31 Oct 2016 15:45:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 31 Oct 2016 15:45:48 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DBE2281254 for ; Mon, 31 Oct 2016 15:45:46 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-204-19.brq.redhat.com [10.40.204.19]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9VFjj5w024333 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 31 Oct 2016 11:45:46 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id u9VFjipM004714; Mon, 31 Oct 2016 16:45:44 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id u9VFjhfo004713; Mon, 31 Oct 2016 16:45:43 +0100 Date: Mon, 31 Oct 2016 16:45:43 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix postfix-expression parsing (PR c++/78089, take 2) Message-ID: <20161031154543.GF3541@tucnak.redhat.com> Reply-To: Jakub Jelinek References: <20161024142025.GM7282@tucnak.redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20161024142025.GM7282@tucnak.redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes Hi! On Mon, Oct 24, 2016 at 04:20:25PM +0200, Jakub Jelinek wrote: > While writing a testcase for __builtin_launder, I've noticed we don't parse > __builtin_shuffle or __builtin_addressof properly (as well as do error > recovery e.g. for typeid in constant expression etc.). > > The problem is that several spots would return something; from the first > switch in cp_parser_postfix_expression, but that is not something we really > want, that primary expression part can be followed by [, ., -> etc. to form > postfix-expression, but this is done in the same function. So instead of > returning, we need to set postfix_expression to whatever we were returning > and just get out of the first switch, then continue parsing in the loop > after that. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > For release branches, __builtin_addressof doesn't apply and the > __builtin_shuffle code is differently formatted, but the bug is there > for __builtin_shuffle, ok to backport to the release branches too? The patch doesn't apply any longer, as the __builtin_launder patch has been committed earlier. So here is the same patch updated for current trunk, bootstrapped/regtested on x86_64-linux and i686-linux again, ok for trunk? 2016-10-31 Jakub Jelinek PR c++/78089 * parser.c (cp_parser_postfix_expression): Replace return statement in the first switch with setting postfix_expression to the return expression and break;. * c-c++-common/builtin-shuffle-1.c: New test. * g++.dg/cpp0x/addressof3.C: New test. Jakub --- gcc/cp/parser.c.jj 2016-10-22 20:58:11.000000000 +0200 +++ gcc/cp/parser.c 2016-10-31 13:03:57.504037757 +0200 @@ -6441,7 +6441,10 @@ cp_parser_postfix_expression (cp_parser can be used in constant-expressions. */ if (!cast_valid_in_integral_constant_expression_p (type) && cp_parser_non_integral_constant_expression (parser, NIC_CAST)) - return error_mark_node; + { + postfix_expression = error_mark_node; + break; + } switch (keyword) { @@ -6521,7 +6524,7 @@ cp_parser_postfix_expression (cp_parser parser->type_definition_forbidden_message = saved_message; /* `typeid' may not appear in an integral constant expression. */ if (cp_parser_non_integral_constant_expression (parser, NIC_TYPEID)) - return error_mark_node; + postfix_expression = error_mark_node; } break; @@ -6615,7 +6618,10 @@ cp_parser_postfix_expression (cp_parser /*cast_p=*/false, /*allow_expansion_p=*/true, /*non_constant_p=*/NULL); if (vec == NULL) - return error_mark_node; + { + postfix_expression = error_mark_node; + break; + } FOR_EACH_VEC_ELT (*vec, i, p) mark_exp_read (p); @@ -6624,10 +6630,15 @@ cp_parser_postfix_expression (cp_parser { case RID_ADDRESSOF: if (vec->length () == 1) - return cp_build_addressof (loc, (*vec)[0], tf_warning_or_error); - error_at (loc, "wrong number of arguments to " - "%<__builtin_addressof%>"); - return error_mark_node; + postfix_expression + = cp_build_addressof (loc, (*vec)[0], tf_warning_or_error); + else + { + error_at (loc, "wrong number of arguments to " + "%<__builtin_addressof%>"); + postfix_expression = error_mark_node; + } + break; case RID_BUILTIN_LAUNDER: if (vec->length () == 1) @@ -6643,14 +6654,20 @@ cp_parser_postfix_expression (cp_parser case RID_BUILTIN_SHUFFLE: if (vec->length () == 2) - return build_x_vec_perm_expr (loc, (*vec)[0], NULL_TREE, - (*vec)[1], tf_warning_or_error); + postfix_expression + = build_x_vec_perm_expr (loc, (*vec)[0], NULL_TREE, + (*vec)[1], tf_warning_or_error); else if (vec->length () == 3) - return build_x_vec_perm_expr (loc, (*vec)[0], (*vec)[1], - (*vec)[2], tf_warning_or_error); - error_at (loc, "wrong number of arguments to " - "%<__builtin_shuffle%>"); - return error_mark_node; + postfix_expression + = build_x_vec_perm_expr (loc, (*vec)[0], (*vec)[1], + (*vec)[2], tf_warning_or_error); + else + { + error_at (loc, "wrong number of arguments to " + "%<__builtin_shuffle%>"); + postfix_expression = error_mark_node; + } + break; default: gcc_unreachable (); --- gcc/testsuite/c-c++-common/builtin-shuffle-1.c.jj 2016-10-24 09:37:45.161340576 +0200 +++ gcc/testsuite/c-c++-common/builtin-shuffle-1.c 2016-10-24 09:44:35.804156775 +0200 @@ -0,0 +1,22 @@ +/* PR c++/78089 */ +/* { dg-do run } */ + +typedef int V __attribute__((vector_size (16))); +V a, b, c; + +int +foo () +{ + return __builtin_shuffle (a, b, c)[3]; +} + +int +main () +{ + a = (V) { 1, 2, 3, 4 }; + b = (V) { 5, 6, 7, 8 }; + c = (V) { 7, 2, 5, 6 }; + if (foo () != 7) + __builtin_abort (); + return 0; +} --- gcc/testsuite/g++.dg/cpp0x/addressof3.C.jj 2016-10-24 09:47:24.175031324 +0200 +++ gcc/testsuite/g++.dg/cpp0x/addressof3.C 2016-10-24 09:50:36.000000000 +0200 @@ -0,0 +1,9 @@ +// { dg-do compile } + +struct S { int foo (); int s; }; +int a[10]; +int b; +S c; +int d = __builtin_addressof (a)[0][0]; +int e = __builtin_addressof (b)[0]; +int f = __builtin_addressof (c)->foo ();