Hi!
The following new testcase FAILs with C (and succeeds with C++).
c_parser_handle_musttail is used in c_parser_compound_statement_nostart
where it is directly passed to c_parser_statement_after_labels, and in
c_parser_all_labels where it is returned. Now, out of the 3
c_parser_all_labels callers, c_parser_statement passes it down to
c_parser_statement_after_labels, but c_parser_if_body and c_parser_else_body
don't, so if there are return statements with [[gnu::musttail]] or
[[clang::musttail]] directly in if or else bodies rather than wrapped with
{}s, we throw that information away.
FIxed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?
2025-03-18 Jakub Jelinek <[email protected]>
PR c/119311
* c-parser.cc (c_parser_if_body): Pass result of c_parser_all_labels
as last argument to c_parser_statement_after_labels.
(c_parser_else_body): Likewise.
* c-c++-common/musttail14.c: Use * instead of \* in the regexps.
* c-c++-common/musttail25.c: New test.
--- gcc/c/c-parser.cc.jj 2025-03-14 15:29:02.043289494 +0100
+++ gcc/c/c-parser.cc 2025-03-17 09:05:08.567471772 +0100
@@ -8499,8 +8499,8 @@ c_parser_if_body (c_parser *parser, bool
token_indent_info body_tinfo
= get_token_indent_info (c_parser_peek_token (parser));
tree before_labels = get_before_labels ();
+ attr_state a = c_parser_all_labels (parser);
- c_parser_all_labels (parser);
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
{
location_t loc = c_parser_peek_token (parser)->location;
@@ -8515,7 +8515,7 @@ c_parser_if_body (c_parser *parser, bool
else
{
body_loc_after_labels = c_parser_peek_token (parser)->location;
- c_parser_statement_after_labels (parser, if_p, before_labels);
+ c_parser_statement_after_labels (parser, if_p, before_labels, NULL, a);
}
token_indent_info next_tinfo
@@ -8544,8 +8544,8 @@ c_parser_else_body (c_parser *parser, co
= get_token_indent_info (c_parser_peek_token (parser));
location_t body_loc_after_labels = UNKNOWN_LOCATION;
tree before_labels = get_before_labels ();
+ attr_state a = c_parser_all_labels (parser);
- c_parser_all_labels (parser);
if (c_parser_next_token_is (parser, CPP_SEMICOLON))
{
location_t loc = c_parser_peek_token (parser)->location;
@@ -8559,7 +8559,7 @@ c_parser_else_body (c_parser *parser, co
{
if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE))
body_loc_after_labels = c_parser_peek_token (parser)->location;
- c_parser_statement_after_labels (parser, NULL, before_labels, chain);
+ c_parser_statement_after_labels (parser, NULL, before_labels, chain, a);
}
token_indent_info next_tinfo
--- gcc/testsuite/c-c++-common/musttail14.c.jj 2025-01-16 09:27:54.130902245
+0100
+++ gcc/testsuite/c-c++-common/musttail14.c 2025-03-17 09:15:52.862440988
+0100
@@ -1,9 +1,9 @@
/* PR tree-optimization/118430 */
/* { dg-do compile { target musttail } } */
/* { dg-options "-O2 -fdump-tree-optimized" } */
-/* { dg-final { scan-tree-dump-times " \[^\n\r]* = bar \\\(\[^\n\r]\*\\\);
\\\[tail call\\\] \\\[must tail call\\\]" 1 "optimized" } } */
-/* { dg-final { scan-tree-dump-times " \[^\n\r]* = freddy \\\(\[^\n\r]\*\\\);
\\\[tail call\\\] \\\[must tail call\\\]" 1 "optimized" } } */
-/* { dg-final { scan-tree-dump-not " (?:bar|freddy) \\\(\[^\n\r]\*\\\);
\\\[tail call\\\]" "optimized" } } */
+/* { dg-final { scan-tree-dump-times " \[^\n\r]* = bar \\\(\[^\n\r]*\\\);
\\\[tail call\\\] \\\[must tail call\\\]" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times " \[^\n\r]* = freddy \\\(\[^\n\r]*\\\);
\\\[tail call\\\] \\\[must tail call\\\]" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-not " (?:bar|freddy) \\\(\[^\n\r]*\\\);
\\\[tail call\\\]" "optimized" } } */
__attribute__ ((noipa)) void
foo (int x)
--- gcc/testsuite/c-c++-common/musttail25.c.jj 2025-03-17 09:11:19.222277551
+0100
+++ gcc/testsuite/c-c++-common/musttail25.c 2025-03-17 09:15:20.235899468
+0100
@@ -0,0 +1,28 @@
+/* PR c/119311 */
+/* { dg-do compile { target musttail } } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump-times " \[^\n\r]* = bar \\\(\[^\n\r]*\\\);
\\\[tail call\\\] \\\[must tail call\\\]" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times " \[^\n\r]* = baz \\\(\[^\n\r]*\\\);
\\\[tail call\\\] \\\[must tail call\\\]" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-not " (?:bar|baz) \\\(\[^\n\r]*\\\); \\\[tail
call\\\]" "optimized" } } */
+
+
+[[gnu::noipa]] int
+bar (int x, int y)
+{
+ return x + y;
+}
+
+[[gnu::noipa]] int
+baz (int x, int y)
+{
+ return x * y;
+}
+
+int
+foo (int a, int b)
+{
+ if (a > b)
+ [[gnu::musttail]] return bar (a - b, b);
+ else
+ [[gnu::musttail]] return baz (a, b - a);
+}
Jakub