From patchwork Fri Apr 22 23:57:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1621281 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Z2l4RuCF; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KlWZd3Njvz9s0r for ; Sat, 23 Apr 2022 09:58:32 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3B3783856DFA for ; Fri, 22 Apr 2022 23:58:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B3783856DFA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1650671908; bh=KNSXPl83H6//InKP8lM8w5IntRBd06PVlxL9avIQ2Ws=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Z2l4RuCF3Z4cB9htp9oyKEB2kSz4ph0qrdazmEfj/wTrkkPNIY5+8pcEvwHa7V7K4 qyj06CQ96NZ/fPq4CoVqUVGGcrZDXSfrvISZ0OeCjvv1UHBRRECBjRLWtUthNKmdSz gE+DD0RFrGlzq35eNBb2J17jW/u96hg+iZdI6AJQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 658A73858C2C for ; Fri, 22 Apr 2022 23:57:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 658A73858C2C Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-636-mtZu_kM_O-2n2h4jfKB6wg-1; Fri, 22 Apr 2022 19:57:43 -0400 X-MC-Unique: mtZu_kM_O-2n2h4jfKB6wg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E23C51C051AD; Fri, 22 Apr 2022 23:57:41 +0000 (UTC) Received: from pdp-11.hsd1.ma.comcast.net (unknown [10.22.34.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id BBD6C1468F2C; Fri, 22 Apr 2022 23:57:41 +0000 (UTC) To: GCC Patches , Jason Merrill Subject: [PATCH] c++: __builtin_shufflevector with value-dep expr [PR105353] Date: Fri, 22 Apr 2022 19:57:34 -0400 Message-Id: <20220422235734.121463-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Marek Polacek via Gcc-patches From: Marek Polacek Reply-To: Marek Polacek Cc: Richard Biener Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Here we issue an error from c_build_shufflevector while parsing a template because it got a TEMPLATE_PARM_INDEX, but this function expects INTEGER_CSTs (except the first two arguments). It checks if any of the arguments are type-dependent, if so, we leave the processing for later, but it should also check value-dependency for the 3rd+ arguments, so as to avoid the problem above. This is not a regression -- __builtin_shufflevector was introduced in GCC 12, but it looks safe enough. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? PR c++/105353 gcc/cp/ChangeLog: * typeck.cc (build_x_shufflevector): Use instantiation_dependent_expression_p except for the first two arguments. gcc/testsuite/ChangeLog: * g++.dg/ext/builtin-shufflevector-3.C: New test. --- gcc/cp/typeck.cc | 4 +++- .../g++.dg/ext/builtin-shufflevector-3.C | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/ext/builtin-shufflevector-3.C base-commit: 7c21556daf385fe9ece37319f574776dd7d8ab1c diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index 26a7cb4b50d..0da6f2485d0 100644 --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -6315,7 +6315,9 @@ build_x_shufflevector (location_t loc, vec *args, if (processing_template_decl) { for (unsigned i = 0; i < args->length (); ++i) - if (type_dependent_expression_p ((*args)[i])) + if (i <= 1 + ? type_dependent_expression_p ((*args)[i]) + : instantiation_dependent_expression_p ((*args)[i])) { tree exp = build_min_nt_call_vec (NULL, args); CALL_EXPR_IFN (exp) = IFN_SHUFFLEVECTOR; diff --git a/gcc/testsuite/g++.dg/ext/builtin-shufflevector-3.C b/gcc/testsuite/g++.dg/ext/builtin-shufflevector-3.C new file mode 100644 index 00000000000..0f3cbbee563 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/builtin-shufflevector-3.C @@ -0,0 +1,23 @@ +// PR c++/105353 +// { dg-do compile { target c++17 } } +// { dg-additional-options "-Wno-psabi" } + +typedef unsigned char Simd128U8VectT __attribute__((__vector_size__(16))); + +template +static inline Simd128U8VectT ShufFunc(Simd128U8VectT vect) noexcept { + if constexpr(unsigned(ShuffleIndex) >= 16) + return Simd128U8VectT { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + else if constexpr(ShuffleIndex == 0) + return vect; + else + return __builtin_shufflevector(vect, vect, ShuffleIndex, ShuffleIndex + 1, + ShuffleIndex + 2, ShuffleIndex + 3, ShuffleIndex + 4, ShuffleIndex + 5, + ShuffleIndex + 6, ShuffleIndex + 7, ShuffleIndex + 8, ShuffleIndex + 9, + ShuffleIndex + 10, ShuffleIndex + 11, ShuffleIndex + 12, ShuffleIndex + 13, + ShuffleIndex + 14, ShuffleIndex + 15); +} + +auto func1(Simd128U8VectT vect) noexcept { + return ShufFunc<5>(vect); +}