From patchwork Thu Sep 16 08:59:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "pc.wang" X-Patchwork-Id: 1528726 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: 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=M3ZJe2Pl; 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 (ip-8-43-85-97.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 ozlabs.org (Postfix) with ESMTPS id 4H99z22Ctrz9t0J for ; Thu, 16 Sep 2021 19:00:30 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A65733858C39 for ; Thu, 16 Sep 2021 09:00:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A65733858C39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1631782826; bh=Xv1oE+tjlpyT9Hy10ugyKtq7WT3m+FIo5t6fi0VJbu0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=M3ZJe2Pl7WffBvKqkso9N++AA4vIRTbRXMxwax94xumPp+qVqaUmtzf7HVaLrtxMf kkGD+zZZfZ8761mublKKyFUp3EqdA+zYn9L2PJdkJZJegk3ZLRD64CYX3NJ5OTJjtQ aJ7IqR5MuRfKjOJ9y4eGHbiwZZhGbTlj8KZ4MjxM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by sourceware.org (Postfix) with ESMTPS id 2B4573858D3C for ; Thu, 16 Sep 2021 08:59:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2B4573858D3C X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R181e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=e01e04395; MF=pc.wang@linux.alibaba.com; NM=1; PH=DS; RN=2; SR=0; TI=SMTPD_---0UoZo2TD_1631782764; Received: from localhost.localdomain(mailfrom:pc.wang@linux.alibaba.com fp:SMTPD_---0UoZo2TD_1631782764) by smtp.aliyun-inc.com(127.0.0.1); Thu, 16 Sep 2021 16:59:40 +0800 To: gcc-patches@gcc.gnu.org Subject: [PATCH] C++: add type checking for static local vector variable in template Date: Thu, 16 Sep 2021 16:59:01 +0800 Message-Id: <20210916085901.2912-1-pc.wang@linux.alibaba.com> X-Mailer: git-send-email 2.33.0.windows.1 MIME-Version: 1.0 X-Spam-Status: No, score=-21.4 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL 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: wangpc via Gcc-patches From: "pc.wang" Reply-To: wangpc Cc: wangpc Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch adds type checking for static local vector variable in C++ template, both AArch64 SVE and RISCV RVV are of sizeless type and they all have this issue. 2021-08-06 wangpc gcc/cp/ChangeLog * pt.c (tsubst_decl): Add type checking. gcc/testsuite/ChangeLog * g++.target/aarch64/sve/static-var-in-template.C: New test. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 90111e4c786..e3a06ea0858 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -7520,6 +7520,12 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, && DECL_INITIALIZED_IN_CLASS_P (decl)) check_static_variable_definition (decl, type); + if (VAR_P (decl) + && DECL_FUNCTION_SCOPE_P (decl) + && TREE_STATIC (decl)) + verify_type_context (DECL_SOURCE_LOCATION (decl), + TCTX_STATIC_STORAGE, type); + if (init && TREE_CODE (decl) == FUNCTION_DECL) { tree clone; diff --git a/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C new file mode 100644 index 00000000000..c2395d18d50 --- /dev/null +++ b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C @@ -0,0 +1,17 @@ +/* { dg-do compile } */ + +#include + +template +void f() +{ + static svbool_t pg = svwhilelt_b64(0, N); +} + +int main(int argc, char **argv) +{ + f<2>(); + return 0; +} + +/* { dg-error {SVE type 'svbool_t' does not have a fixed size} } */