public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "pc.wang" <pc.wang@linux.alibaba.com>
To: "gcc-patches" <gcc-patches@gcc.gnu.org>,
	"Jason Merrill" <jason@redhat.com>
Subject: Re: [PATCH] C++: add type checking for static local vector variable in template
Date: Thu, 16 Sep 2021 17:06:37 +0800	[thread overview]
Message-ID: <203788e5-cfd0-4390-bba3-de5ba1d3810b.pc.wang@linux.alibaba.com> (raw)
In-Reply-To: <121dd01c-6732-c0e0-05c1-c2ce2fb7145d@redhat.com>

I move the verify_type_context code to cp_finish_decl and it works.
I will send the new patch later.
------------------------------------------------------------------
Sender:Jason Merrill <jason@redhat.com>
Sent At:2021 Sep. 16 (Thu.) 05:04
Recipient:wangpc <pc.wang@linux.alibaba.com>; gcc-patches <gcc-patches@gcc.gnu.org>
Subject:Re: [PATCH] C++: add type checking for static local vector variable in template

On 9/6/21 08:10, 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 thay all have this issue.
> 
> 2021-08-06  wangpc  <pc.wang@linux.alibaba.com>
> 
> gcc/cp/ChangeLog
> 
>          * pt.c (tsubst_decl): Add type checking.
> 
> gcc/testsuite/ChangeLog
> 
>          * g++.target/aarch64/sve/static-var-in-template.C: New test.
> ---
>   gcc/cp/pt.c                                    |  8 +++++++-
>   .../aarch64/sve/static-var-in-template.C       | 18 ++++++++++++++++++
>   2 files changed, 25 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
> 
> diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
> index f0aa626ab723..988f4cb1e73f 100644
> --- a/gcc/cp/pt.c
> +++ b/gcc/cp/pt.c
> @@ -14731,7 +14731,13 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
>      even if its underlying type is not.  */
>          TYPE_DEPENDENT_P_VALID (TREE_TYPE (r)) = false;
>      }
> -
> +    /* We should verify static local variable's type
> +    since vector type does not have a fixed size.  */
> +    if (TREE_STATIC (t)
> +      &&!verify_type_context (input_location, TCTX_STATIC_STORAGE, type))

It seems that the reason this was missed before was because we checked 
for this in start_decl, which isn't called for template instantiation. 
Would it work to move the verify_type_context code from start_decl to 
cp_finish_decl, near the other call to verify_type_context, instead of 
doing anything here?

> +    {
> +      RETURN (error_mark_node);
> +    }
>    layout_decl (r, 0);
>         }
>         break;
> 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 000000000000..26d397ca565d
> --- /dev/null
> +++ b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
> @@ -0,0 +1,18 @@
> +/* { dg-do compile } */
> +
> +#include <arm_sve.h>
> +
> +template <int N>
> +void f()
> +{
> +    int i = 0;
> +    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} } */
> 

  reply	other threads:[~2021-09-16  9:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-06 12:10 wangpc
2021-09-15 21:02 ` Jason Merrill
2021-09-16  9:06   ` pc.wang [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-09-16  9:11 wangpc
2021-09-16 15:19 ` Jason Merrill
2021-09-17  8:05   ` wangpc
2021-09-16  8:59 wangpc
2021-09-01  8:11 wangpc

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=203788e5-cfd0-4390-bba3-de5ba1d3810b.pc.wang@linux.alibaba.com \
    --to=pc.wang@linux.alibaba.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).