* [pushed] c++: unroll pragma in templates [PR111529]
@ 2023-09-22 13:00 Jason Merrill
2023-09-22 17:15 ` Andrew Pinski
0 siblings, 1 reply; 2+ messages in thread
From: Jason Merrill @ 2023-09-22 13:00 UTC (permalink / raw)
To: gcc-patches
Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
We were failing to handle ANNOTATE_EXPR in tsubst_copy_and_build, leading to
problems with substitution of any wrapped expressions.
Let's also not tell users that lambda templates are available in C++14.
PR c++/111529
gcc/cp/ChangeLog:
* parser.cc (cp_parser_lambda_declarator_opt): Don't suggest
-std=c++14 for lambda templates.
* pt.cc (tsubst_expr): Move ANNOTATE_EXPR handling...
(tsubst_copy_and_build): ...here.
gcc/testsuite/ChangeLog:
* g++.dg/ext/unroll-4.C: New test.
---
gcc/cp/parser.cc | 7 ++-----
gcc/cp/pt.cc | 14 +++++++-------
gcc/testsuite/g++.dg/ext/unroll-4.C | 16 ++++++++++++++++
3 files changed, 25 insertions(+), 12 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/ext/unroll-4.C
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 0e1cbbfe051..f3abae716fe 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -11695,11 +11695,8 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
an opening angle if present. */
if (cp_lexer_next_token_is (parser->lexer, CPP_LESS))
{
- if (cxx_dialect < cxx14)
- pedwarn (parser->lexer->next_token->location, OPT_Wc__14_extensions,
- "lambda templates are only available with "
- "%<-std=c++14%> or %<-std=gnu++14%>");
- else if (pedantic && cxx_dialect < cxx20)
+ if (cxx_dialect < cxx20
+ && (pedantic || cxx_dialect < cxx14))
pedwarn (parser->lexer->next_token->location, OPT_Wc__20_extensions,
"lambda templates are only available with "
"%<-std=c++20%> or %<-std=gnu++20%>");
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 9b100e12a23..ea5379098a5 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -19913,13 +19913,6 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
templated_operator_saved_lookups (t),
complain));
- case ANNOTATE_EXPR:
- tmp = RECUR (TREE_OPERAND (t, 0));
- RETURN (build3_loc (EXPR_LOCATION (t), ANNOTATE_EXPR,
- TREE_TYPE (tmp), tmp,
- RECUR (TREE_OPERAND (t, 1)),
- RECUR (TREE_OPERAND (t, 2))));
-
case PREDICT_EXPR:
RETURN (add_stmt (copy_node (t)));
@@ -21868,6 +21861,13 @@ tsubst_copy_and_build (tree t,
RETURN (op);
}
+ case ANNOTATE_EXPR:
+ op1 = RECUR (TREE_OPERAND (t, 0));
+ RETURN (build3_loc (EXPR_LOCATION (t), ANNOTATE_EXPR,
+ TREE_TYPE (op1), op1,
+ RECUR (TREE_OPERAND (t, 1)),
+ RECUR (TREE_OPERAND (t, 2))));
+
default:
/* Handle Objective-C++ constructs, if appropriate. */
{
diff --git a/gcc/testsuite/g++.dg/ext/unroll-4.C b/gcc/testsuite/g++.dg/ext/unroll-4.C
new file mode 100644
index 00000000000..d488aca974e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/unroll-4.C
@@ -0,0 +1,16 @@
+// PR c++/111529
+// { dg-do compile { target c++11 } }
+// { dg-additional-options -Wno-c++20-extensions }
+
+template <int>
+void f() {
+ []<int>() {
+ #pragma GCC unroll 9
+ for (int i = 1; i; --i) {
+ }
+ };
+}
+
+int main() {
+ f<0>();
+}
base-commit: 4c496020764057453415f1ae599950724ec0e871
--
2.39.3
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [pushed] c++: unroll pragma in templates [PR111529]
2023-09-22 13:00 [pushed] c++: unroll pragma in templates [PR111529] Jason Merrill
@ 2023-09-22 17:15 ` Andrew Pinski
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Pinski @ 2023-09-22 17:15 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
On Fri, Sep 22, 2023 at 6:01 AM Jason Merrill <jason@redhat.com> wrote:
>
> Tested x86_64-pc-linux-gnu, applying to trunk.
>
> -- 8< --
>
> We were failing to handle ANNOTATE_EXPR in tsubst_copy_and_build, leading to
> problems with substitution of any wrapped expressions.
>
> Let's also not tell users that lambda templates are available in C++14.
This part of the patch fixes
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108026 .
>
> PR c++/111529
>
> gcc/cp/ChangeLog:
>
> * parser.cc (cp_parser_lambda_declarator_opt): Don't suggest
> -std=c++14 for lambda templates.
> * pt.cc (tsubst_expr): Move ANNOTATE_EXPR handling...
> (tsubst_copy_and_build): ...here.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/ext/unroll-4.C: New test.
> ---
> gcc/cp/parser.cc | 7 ++-----
> gcc/cp/pt.cc | 14 +++++++-------
> gcc/testsuite/g++.dg/ext/unroll-4.C | 16 ++++++++++++++++
> 3 files changed, 25 insertions(+), 12 deletions(-)
> create mode 100644 gcc/testsuite/g++.dg/ext/unroll-4.C
>
> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
> index 0e1cbbfe051..f3abae716fe 100644
> --- a/gcc/cp/parser.cc
> +++ b/gcc/cp/parser.cc
> @@ -11695,11 +11695,8 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
> an opening angle if present. */
> if (cp_lexer_next_token_is (parser->lexer, CPP_LESS))
> {
> - if (cxx_dialect < cxx14)
> - pedwarn (parser->lexer->next_token->location, OPT_Wc__14_extensions,
> - "lambda templates are only available with "
> - "%<-std=c++14%> or %<-std=gnu++14%>");
> - else if (pedantic && cxx_dialect < cxx20)
> + if (cxx_dialect < cxx20
> + && (pedantic || cxx_dialect < cxx14))
> pedwarn (parser->lexer->next_token->location, OPT_Wc__20_extensions,
> "lambda templates are only available with "
> "%<-std=c++20%> or %<-std=gnu++20%>");
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index 9b100e12a23..ea5379098a5 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -19913,13 +19913,6 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
> templated_operator_saved_lookups (t),
> complain));
>
> - case ANNOTATE_EXPR:
> - tmp = RECUR (TREE_OPERAND (t, 0));
> - RETURN (build3_loc (EXPR_LOCATION (t), ANNOTATE_EXPR,
> - TREE_TYPE (tmp), tmp,
> - RECUR (TREE_OPERAND (t, 1)),
> - RECUR (TREE_OPERAND (t, 2))));
> -
> case PREDICT_EXPR:
> RETURN (add_stmt (copy_node (t)));
>
> @@ -21868,6 +21861,13 @@ tsubst_copy_and_build (tree t,
> RETURN (op);
> }
>
> + case ANNOTATE_EXPR:
> + op1 = RECUR (TREE_OPERAND (t, 0));
> + RETURN (build3_loc (EXPR_LOCATION (t), ANNOTATE_EXPR,
> + TREE_TYPE (op1), op1,
> + RECUR (TREE_OPERAND (t, 1)),
> + RECUR (TREE_OPERAND (t, 2))));
> +
> default:
> /* Handle Objective-C++ constructs, if appropriate. */
> {
> diff --git a/gcc/testsuite/g++.dg/ext/unroll-4.C b/gcc/testsuite/g++.dg/ext/unroll-4.C
> new file mode 100644
> index 00000000000..d488aca974e
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/ext/unroll-4.C
> @@ -0,0 +1,16 @@
> +// PR c++/111529
> +// { dg-do compile { target c++11 } }
> +// { dg-additional-options -Wno-c++20-extensions }
> +
> +template <int>
> +void f() {
> + []<int>() {
> + #pragma GCC unroll 9
> + for (int i = 1; i; --i) {
> + }
> + };
> +}
> +
> +int main() {
> + f<0>();
> +}
>
> base-commit: 4c496020764057453415f1ae599950724ec0e871
> --
> 2.39.3
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-09-22 17:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-22 13:00 [pushed] c++: unroll pragma in templates [PR111529] Jason Merrill
2023-09-22 17:15 ` Andrew Pinski
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).