From patchwork Sat Sep 18 05:53:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "pc.wang" X-Patchwork-Id: 45153 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 C2A253857C47 for ; Sat, 18 Sep 2021 05:55:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C2A253857C47 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1631944531; bh=VECW+GQGIMYtdrB0LmOP2JII+tFE3BV58Svl64XZlsY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=b3XmbXmXcGuAPBGn5EY1ed93vfbBPvbBUfB4EPnTyPnpUApks92UJtzv3CqiN7LKq KbRmMUtOFYs39P00czG4rVCQGprQo4/2KZHIRydbSBwftttF+ZAEzHg2uuPHhsGo6n eVnUVU6qEZ1aOm311i6XoShNrQc3eaXF4Wm5qdDM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out30-45.freemail.mail.aliyun.com (out30-45.freemail.mail.aliyun.com [115.124.30.45]) by sourceware.org (Postfix) with ESMTPS id 804683857C47 for ; Sat, 18 Sep 2021 05:54:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 804683857C47 X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R101e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=e01e04423; MF=pc.wang@linux.alibaba.com; NM=1; PH=DS; RN=3; SR=0; TI=SMTPD_---0UolAIx6_1631944479; Received: from localhost.localdomain(mailfrom:pc.wang@linux.alibaba.com fp:SMTPD_---0UolAIx6_1631944479) by smtp.aliyun-inc.com(127.0.0.1); Sat, 18 Sep 2021 13:54:52 +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: Sat, 18 Sep 2021 13:53:09 +0800 Message-Id: <20210918055309.4799-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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This patch moves verify_type_context from start_decl_1 to cp_finish_decl to do more type checking such as static local vector variable in C++ template. 2021-08-06 wangpc gcc/cp/ChangeLog * decl.c (start_decl_1): Move verify_type_context to ... (cp_finish_decl): ... to here. 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..deaa6c56a8f 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,14 @@ 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) && 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 (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..74237ff7c57 --- /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" "" { target *-*-* } 0 } */