From patchwork Fri Sep 17 07:58:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "pc.wang" X-Patchwork-Id: 45114 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 5BCE43857412 for ; Fri, 17 Sep 2021 08:00:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5BCE43857412 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1631865626; bh=7+L8ZI5oL22KmN6RDjd0eq+55Pu1XhqohWesRzHJP5E=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=HtAfmEMXeFw5mSzd66PhaLuamERkxPJ4a8IEuw6+B8eHDJCC61FuzGG/rjPDix3tg /ajo0CFGMDbVNazRfIUXGctW2Ki88GX6bT9KyPYhPcWJLGrBBhI6h7Rl+rl4SFqZle SbDrH8mMRv4yZ7pOslM0R0PRvA9+Y6kFDxEYKRtY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by sourceware.org (Postfix) with ESMTPS id D182A3858401 for ; Fri, 17 Sep 2021 07:59:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D182A3858401 X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R561e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=e01e04357; MF=pc.wang@linux.alibaba.com; NM=1; PH=DS; RN=3; SR=0; TI=SMTPD_---0UofBaN1_1631865575; Received: from localhost.localdomain(mailfrom:pc.wang@linux.alibaba.com fp:SMTPD_---0UofBaN1_1631865575) by smtp.aliyun-inc.com(127.0.0.1); Fri, 17 Sep 2021 15:59:53 +0800 To: gcc-patches@gcc.gnu.org, jason@redhat.com Subject: [PATCH v2] C++: add type checking for static local vector variable in template Date: Fri, 17 Sep 2021 15:58:59 +0800 Message-Id: <20210917075859.4147-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.6 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This patch moves verify_type_context from start_decl_1 to cp_finish_decl and adds type checking for static local vector variable in C++ template. 2021-08-06 wangpc gcc/cp/ChangeLog * decl.c (start_decl_1): Remove verify_type_context. (cp_finish_decl): Add more 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..d411963896a 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5491,13 +5491,6 @@ start_decl_1 (tree decl, bool initialized) cp_apply_type_quals_to_decl (cp_type_quals (type), decl); } - if (is_global_var (decl)) - { - type_context_kind context = (DECL_THREAD_LOCAL_P (decl) - ? TCTX_THREAD_STORAGE - : TCTX_STATIC_STORAGE); - verify_type_context (input_location, context, TREE_TYPE (decl)); - } if (initialized) /* Is it valid for this decl to have an initializer at all? */ { @@ -7520,6 +7513,22 @@ 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 (!processing_template_decl && VAR_P (decl)) + { + if (is_global_var (decl)) + { + type_context_kind context = (DECL_THREAD_LOCAL_P (decl) + ? TCTX_THREAD_STORAGE + : TCTX_STATIC_STORAGE); + verify_type_context (input_location, context, TREE_TYPE (decl)); + } + + if (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} } */