From: Jason Merrill <jason@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c++: Reject pack expansion of assume attribute [PR109756]
Date: Tue, 9 May 2023 09:59:26 -0400 [thread overview]
Message-ID: <be5467af-106c-5e5e-5821-121eb6efa6fb@redhat.com> (raw)
In-Reply-To: <ZFoCsXiB7fN8rsW5@tucnak>
On 5/9/23 04:22, Jakub Jelinek wrote:
> Hi!
>
> http://eel.is/c++draft/dcl.attr#grammar-4 says
> "In an attribute-list, an ellipsis may appear only if that attribute's
> specification permits it."
> and doesn't explicitly permit it on any standard attribute.
> The https://wg21.link/p1774r8 paper which introduced assume attribute says
> "We could therefore hypothetically permit the assume attribute to directly
> support pack expansion:
> template <int... args>
> void f() {
> [[assume(args >= 0)...]];
> }
> However, we do not propose this. It would require substantial additional work
I question "substantial"; it could easily be treated as a
fold-expression internally. But the patch is OK.
> for a very rare use case. Note that this can instead be expressed with a fold
> expression, which is equivalent to the above and works out of the box without
> any extra effort:
> template <int... args>
> void f() {
> [[assume(((args >= 0) && ...))]];
> }
> ", but as the testcase shows, GCC 13+ ICEs on assume attribute followed by
> ... if it contains packs.
> The following patch rejects those instead of ICE and for C++17 or later
> suggests using fold expressions instead (it doesn't make sense to suggest
> it for C++14 and earlier when we'd error on the fold expressions).
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/13.2?
>
> 2023-05-09 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/109756
> * gp-gimplify.cc (process_stmt_assume_attribute): Diagnose pack
> expansion of assume attribute.
>
> * g++.dg/cpp23/attr-assume11.C: New test.
>
> --- gcc/cp/cp-gimplify.cc.jj 2023-05-04 12:13:50.791647593 +0200
> +++ gcc/cp/cp-gimplify.cc 2023-05-08 13:20:33.191070530 +0200
> @@ -3267,6 +3267,16 @@ process_stmt_assume_attribute (tree std_
> for (; attr; attr = lookup_attribute ("gnu", "assume", TREE_CHAIN (attr)))
> {
> tree args = TREE_VALUE (attr);
> + if (args && PACK_EXPANSION_P (args))
> + {
> + auto_diagnostic_group d;
> + error_at (attrs_loc, "pack expansion of %qE attribute",
> + get_attribute_name (attr));
> + if (cxx_dialect >= cxx17)
> + inform (attrs_loc, "use fold expression in the attribute "
> + "argument instead");
> + continue;
> + }
> int nargs = list_length (args);
> if (nargs != 1)
> {
> --- gcc/testsuite/g++.dg/cpp23/attr-assume11.C.jj 2023-05-08 13:19:07.812290213 +0200
> +++ gcc/testsuite/g++.dg/cpp23/attr-assume11.C 2023-05-08 13:22:07.746719746 +0200
> @@ -0,0 +1,22 @@
> +// PR c++/109756
> +// { dg-do compile { target c++11 } }
> +
> +template <int ...args>
> +void
> +foo ()
> +{
> + [[assume (1 > 0)...]]; // { dg-error "expansion pattern '\\\(1 > 0\\\)' contains no parameter packs" }
> + // { dg-warning "attributes at the beginning of statement are ignored" "" { target *-*-* } .-1 }
> + [[assume (args > 0)...]]; // { dg-error "pack expansion of 'assume' attribute" }
> + // { dg-message "use fold expression in the attribute argument instead" "" { target c++17 } .-1 }
> +#if __cpp_fold_expressions >= 201603L
> + [[assume (((args > 0) && ...))]];
> +#endif
> + [[gnu::assume (1 > 0)...]]; // { dg-error "expansion pattern '\\\(1 > 0\\\)' contains no parameter packs" }
> + // { dg-warning "attributes at the beginning of statement are ignored" "" { target *-*-* } .-1 }
> + [[gnu::assume (args > 0)...]]; // { dg-error "pack expansion of 'assume' attribute" }
> + // { dg-message "use fold expression in the attribute argument instead" "" { target c++17 } .-1 }
> +#if __cpp_fold_expressions >= 201603L
> + [[gnu::assume (((args > 0) && ...))]];
> +#endif
> +}
>
> Jakub
>
prev parent reply other threads:[~2023-05-09 13:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-09 8:22 Jakub Jelinek
2023-05-09 13:59 ` Jason Merrill [this message]
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=be5467af-106c-5e5e-5821-121eb6efa6fb@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@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).