From patchwork Thu Sep 16 09:11:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "pc.wang" X-Patchwork-Id: 45071 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8F16B385841B for ; Thu, 16 Sep 2021 09:13:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F16B385841B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1631783618; bh=Fiy8mJZh258v/kHLmH95XPM4cHmMbTsISj11ocZG8M0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=JpSR9nqRvhYfyn4F7QVRuB599kTanOqpCixBoLz9Fo2qVw/Dgy0/WLX5+TAGCwDjN zgD+RclmeDEVqRVmhEGpotZG98M7JKM38ZDYQUwUbWttjuJUx31rWcty/DfsisrJgu MjHAZi2L0FtdfiO2iF6kF+gn5E/wmXLbVaBYINls= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by sourceware.org (Postfix) with ESMTPS id D8C0A385840E for ; Thu, 16 Sep 2021 09:12:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D8C0A385840E X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R701e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=e01e04426; MF=pc.wang@linux.alibaba.com; NM=1; PH=DS; RN=2; SR=0; TI=SMTPD_---0UoZo4mz_1631783533; Received: from localhost.localdomain(mailfrom:pc.wang@linux.alibaba.com fp:SMTPD_---0UoZo4mz_1631783533) by smtp.aliyun-inc.com(127.0.0.1); Thu, 16 Sep 2021 17:12:27 +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 17:11:53 +0800 Message-Id: <20210916091153.3035-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.5 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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+patchwork=sourceware.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 * decl.c (cp_finish_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} } */