From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out30-54.freemail.mail.aliyun.com (out30-54.freemail.mail.aliyun.com [115.124.30.54]) by sourceware.org (Postfix) with ESMTPS id B8772385702C for ; Fri, 17 Sep 2021 08:05:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B8772385702C X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R141e4; 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_---0UofoBF._1631865909; Received: from 30.225.212.162(mailfrom:pc.wang@linux.alibaba.com fp:SMTPD_---0UofoBF._1631865909) by smtp.aliyun-inc.com(127.0.0.1); Fri, 17 Sep 2021 16:05:09 +0800 Message-ID: <190bf8fa-977d-a64d-d8b4-6d886ac95e95@linux.alibaba.com> Date: Fri, 17 Sep 2021 16:05:08 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.1.1 Subject: [PATCH] C++: add type checking for static local vector variable in template Content-Language: en-CA To: Jason Merrill , gcc-patches@gcc.gnu.org References: <20210916091153.3035-1-pc.wang@linux.alibaba.com> From: wangpc In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-20.2 required=5.0 tests=BAYES_00, BODY_8BITS, 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-List-Received-Date: Fri, 17 Sep 2021 08:05:16 -0000 Thanks for your advice, I have misunderstood what you meant. I have sent a second version patch, please review whether it is OK. On 2021/9/16 23:19, Jason Merrill wrote: > On 9/16/21 05:11, wangpc via Gcc-patches wrote: >> 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); > > I was thinking to move the verify_type_context code from start_decl, > which handles more cases: > >>   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)); >>     } > > Jason