https://gcc.gnu.org/g:ba97ec1805bb15097d5956e4f176039fa43a502f
commit ba97ec1805bb15097d5956e4f176039fa43a502f Author: Thomas Schwinge <tschwi...@baylibre.com> Date: Thu Jan 16 15:32:56 2025 +0100 Honor dump options for C/C++ '-fdump-tree-original' In addition to upcoming use of '-fdump-tree-original-lineno', this patch actually resolves XFAILs for 'c-c++-common/goacc/pr92793-1.c', which had gotten added as part of commit fa410314ec94c9df2ad270c1917adc51f9147c2c "[OpenACC] Elaborate testcases that verify column location information [PR92793]". gcc/c-family/ * c-gimplify.cc (c_genericize): Pass 'local_dump_flags' to 'print_c_tree'. * c-pretty-print.cc (c_pretty_printer::statement): Pass 'dump_flags' to 'dump_generic_node'. (c_pretty_printer::c_pretty_printer): Initialize 'dump_flags'. (print_c_tree): Add 'dump_flags_t' formal parameter. (debug_c_tree): Adjust. * c-pretty-print.h (c_pretty_printer): Add 'dump_flags_t dump_flags'. (c_pretty_printer::c_pretty_printer): Add 'dump_flags_t' formal parameter. (print_c_tree): Adjust. gcc/testsuite/ * c-c++-common/goacc/pr92793-1.c: Remove '-fdump-tree-original-lineno' XFAILs. (cherry picked from commit 5fdcbe487df139dca2f8e6af5599edb470de8ad9) Diff: --- gcc/ChangeLog.omp | 16 ++++++++++++++++ gcc/c-family/c-gimplify.cc | 2 +- gcc/c-family/c-pretty-print.cc | 26 +++++++++++++++++++++----- gcc/c-family/c-pretty-print.h | 6 ++++-- gcc/testsuite/ChangeLog.omp | 6 ++++++ gcc/testsuite/c-c++-common/goacc/pr92793-1.c | 21 ++++++++++----------- 6 files changed, 58 insertions(+), 19 deletions(-) diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp index 80c97bd63aa5..b6d1f4c58877 100644 --- a/gcc/ChangeLog.omp +++ b/gcc/ChangeLog.omp @@ -1,5 +1,21 @@ 2025-02-18 Thomas Schwinge <tschwi...@baylibre.com> + Backported from trunk: + 2025-02-07 Thomas Schwinge <tschwi...@baylibre.com> + + * c-gimplify.cc (c_genericize): Pass 'local_dump_flags' to + 'print_c_tree'. + * c-pretty-print.cc (c_pretty_printer::statement): Pass + 'dump_flags' to 'dump_generic_node'. + (c_pretty_printer::c_pretty_printer): Initialize 'dump_flags'. + (print_c_tree): Add 'dump_flags_t' formal parameter. + (debug_c_tree): Adjust. + * c-pretty-print.h (c_pretty_printer): Add 'dump_flags_t + dump_flags'. + (c_pretty_printer::c_pretty_printer): Add 'dump_flags_t' formal + parameter. + (print_c_tree): Adjust. + Backported from trunk: 2025-01-28 Thomas Schwinge <tschwi...@baylibre.com> diff --git a/gcc/c-family/c-gimplify.cc b/gcc/c-family/c-gimplify.cc index 897c3328f8e8..ef35f7f2392d 100644 --- a/gcc/c-family/c-gimplify.cc +++ b/gcc/c-family/c-gimplify.cc @@ -668,7 +668,7 @@ c_genericize (tree fndecl) dump_node (DECL_SAVED_TREE (fndecl), TDF_SLIM | local_dump_flags, dump_orig); else - print_c_tree (dump_orig, DECL_SAVED_TREE (fndecl)); + print_c_tree (dump_orig, DECL_SAVED_TREE (fndecl), local_dump_flags); fprintf (dump_orig, "\n"); } diff --git a/gcc/c-family/c-pretty-print.cc b/gcc/c-family/c-pretty-print.cc index 54c88d0b3522..f86554a19ddf 100644 --- a/gcc/c-family/c-pretty-print.cc +++ b/gcc/c-family/c-pretty-print.cc @@ -2877,6 +2877,9 @@ c_pretty_printer::statement (tree t) { case SWITCH_STMT: + if (dump_flags != TDF_NONE) + internal_error ("dump flags not handled here"); + pp_c_ws_string (this, "switch"); pp_space (this); pp_c_left_paren (this); @@ -2894,6 +2897,9 @@ c_pretty_printer::statement (tree t) for ( expression(opt) ; expression(opt) ; expression(opt) ) statement for ( declaration expression(opt) ; expression(opt) ) statement */ case WHILE_STMT: + if (dump_flags != TDF_NONE) + internal_error ("dump flags not handled here"); + pp_c_ws_string (this, "while"); pp_space (this); pp_c_left_paren (this); @@ -2906,6 +2912,9 @@ c_pretty_printer::statement (tree t) break; case DO_STMT: + if (dump_flags != TDF_NONE) + internal_error ("dump flags not handled here"); + pp_c_ws_string (this, "do"); pp_newline_and_indent (this, 3); statement (DO_BODY (t)); @@ -2920,6 +2929,9 @@ c_pretty_printer::statement (tree t) break; case FOR_STMT: + if (dump_flags != TDF_NONE) + internal_error ("dump flags not handled here"); + pp_c_ws_string (this, "for"); pp_space (this); pp_c_left_paren (this); @@ -2949,6 +2961,9 @@ c_pretty_printer::statement (tree t) return expression(opt) ; */ case BREAK_STMT: case CONTINUE_STMT: + if (dump_flags != TDF_NONE) + internal_error ("dump flags not handled here"); + pp_string (this, TREE_CODE (t) == BREAK_STMT ? "break" : "continue"); pp_c_semicolon (this); pp_needs_newline (this) = true; @@ -2957,15 +2972,16 @@ c_pretty_printer::statement (tree t) default: if (pp_needs_newline (this)) pp_newline_and_indent (this, 0); - dump_generic_node (this, t, pp_indentation (this), TDF_NONE, true); + dump_generic_node (this, t, pp_indentation (this), dump_flags, true); } } /* Initialize the PRETTY-PRINTER for handling C codes. */ -c_pretty_printer::c_pretty_printer () +c_pretty_printer::c_pretty_printer (dump_flags_t dump_flags) : pretty_printer (), + dump_flags (dump_flags), offset_list (), flags () { @@ -2985,9 +3001,9 @@ c_pretty_printer::clone () const /* Print the tree T in full, on file FILE. */ void -print_c_tree (FILE *file, tree t) +print_c_tree (FILE *file, tree t, dump_flags_t dump_flags) { - c_pretty_printer pp; + c_pretty_printer pp (dump_flags); pp_needs_newline (&pp) = true; pp.buffer->stream = file; @@ -3000,7 +3016,7 @@ print_c_tree (FILE *file, tree t) DEBUG_FUNCTION void debug_c_tree (tree t) { - print_c_tree (stderr, t); + print_c_tree (stderr, t, TDF_NONE); fputc ('\n', stderr); } diff --git a/gcc/c-family/c-pretty-print.h b/gcc/c-family/c-pretty-print.h index 550e4cb68820..cc54b89c3950 100644 --- a/gcc/c-family/c-pretty-print.h +++ b/gcc/c-family/c-pretty-print.h @@ -49,8 +49,10 @@ typedef void (*c_pretty_print_fn) (c_pretty_printer *, tree); and cp/cxx-pretty-print.cc for an example of derivation. */ class c_pretty_printer : public pretty_printer { + dump_flags_t dump_flags; + public: - c_pretty_printer (); + c_pretty_printer (dump_flags_t = TDF_NONE); pretty_printer *clone () const override; // Format string, possibly translated. @@ -137,6 +139,6 @@ void pp_c_identifier (c_pretty_printer *, const char *); void pp_c_string_literal (c_pretty_printer *, tree); void pp_c_integer_constant (c_pretty_printer *, tree); -void print_c_tree (FILE *file, tree t); +void print_c_tree (FILE *file, tree t, dump_flags_t); #endif /* GCC_C_PRETTY_PRINTER */ diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp index a8f2d3a97715..d2418d2ce762 100644 --- a/gcc/testsuite/ChangeLog.omp +++ b/gcc/testsuite/ChangeLog.omp @@ -1,5 +1,11 @@ 2025-02-18 Thomas Schwinge <tho...@codesourcery.com> + Backported from trunk: + 2025-02-07 Thomas Schwinge <tschwi...@baylibre.com> + + * c-c++-common/goacc/pr92793-1.c: Remove + '-fdump-tree-original-lineno' XFAILs. + * c-c++-common/goacc/combined-reduction.c: Adjust. * c-c++-common/goacc/reduction-1.c: Likewise. * c-c++-common/goacc/reduction-10.c: Likewise. diff --git a/gcc/testsuite/c-c++-common/goacc/pr92793-1.c b/gcc/testsuite/c-c++-common/goacc/pr92793-1.c index 71a556e27513..3504cb343532 100644 --- a/gcc/testsuite/c-c++-common/goacc/pr92793-1.c +++ b/gcc/testsuite/c-c++-common/goacc/pr92793-1.c @@ -2,9 +2,8 @@ /* See also 'gfortran.dg/goacc/pr92793-1.f90'. */ -/* { dg-additional-options "-fdump-tree-original-lineno" }, and also - { dg-additional-options "-fdump-tree-gimple-lineno" } as the former doesn't - actually contain location information. */ +/* { dg-additional-options "-fdump-tree-original-lineno" } + { dg-additional-options "-fdump-tree-gimple-lineno" } */ /* No tabs. Funny indentation/spacing for a reason. */ @@ -16,13 +15,13 @@ check () #pragma acc parallel \ /* C, C++ location information points to the 'a' in '#pragma acc parallel'. */ \ - /* { dg-final { scan-tree-dump-times "pr92793-1\\\.c:17:12\\\] #pragma acc parallel" 1 "original" { xfail *-*-* } } } */ \ - /* { dg-final { scan-tree-dump-times "pr92793-1\\\.c:17:12\\\] #pragma omp target oacc_parallel" 1 "gimple" } } */ + /* { dg-final { scan-tree-dump-times "pr92793-1\\\.c:16:12\\\] #pragma acc parallel" 1 "original" } } */ \ + /* { dg-final { scan-tree-dump-times "pr92793-1\\\.c:16:12\\\] #pragma omp target oacc_parallel" 1 "gimple" } } */ { #pragma acc loop \ /* C, C++ location information points to the 'a' in '#pragma acc loop'. */ \ - /* { dg-final { scan-tree-dump-times "pr92793-1\\\.c:22:13\\\] #pragma acc loop" 1 "original" { xfail *-*-* } } } */ \ - /* { dg-final { scan-tree-dump-times "pr92793-1\\\.c:22:13\\\] #pragma acc loop" 1 "gimple" } } */ \ + /* { dg-final { scan-tree-dump-times "pr92793-1\\\.c:21:13\\\] #pragma acc loop" 1 "original" } } */ \ + /* { dg-final { scan-tree-dump-times "pr92793-1\\\.c:21:13\\\] #pragma acc loop" 1 "gimple" } } */ \ reduction ( + : sum) /* { dg-line sum1 } */ \ /* C location information points to the '(' in 'reduction(+:sum)'. */ \ /* { dg-message "19: location of the previous reduction for 'sum'" "" { target c } sum1 } */ \ @@ -33,8 +32,8 @@ check () { #pragma acc loop \ /* C, C++ location information points to the 'a' in '#pragma acc loop'. */ \ - /* { dg-final { scan-tree-dump-times "pr92793-1\\\.c:34:19\\\] #pragma acc loop" 1 "original" { xfail *-*-* } } } */ \ - /* { dg-final { scan-tree-dump-times "pr92793-1\\\.c:34:19\\\] #pragma acc loop" 1 "gimple" } } */ \ + /* { dg-final { scan-tree-dump-times "pr92793-1\\\.c:33:19\\\] #pragma acc loop" 1 "original" } } */ \ + /* { dg-final { scan-tree-dump-times "pr92793-1\\\.c:33:19\\\] #pragma acc loop" 1 "gimple" } } */ \ reduction ( - : diff ) \ reduction(-:sum ) /* { dg-line sum2 } */ \ /* C location information points to the '(' in 'reduction(-:sum)'. */ \ @@ -48,8 +47,8 @@ reduction(-:sum ) /* { dg-line sum2 } */ \ = 1 ; /* C, C++ location information points to the '=' in 'sum = 1'. */ \ - /* { dg-final { scan-tree-dump-times "pr92793-1\\\.c:48:19\\\] sum = 1" 1 "original" { xfail *-*-* } } } */ \ - /* { dg-final { scan-tree-dump-times "pr92793-1\\\.c:48:19\\\] sum = 1" 1 "gimple" } } */ + /* { dg-final { scan-tree-dump-times "pr92793-1\\\.c:47:19\\\] sum = 1" 1 "original" } } */ \ + /* { dg-final { scan-tree-dump-times "pr92793-1\\\.c:47:19\\\] sum = 1" 1 "gimple" } } */ } } }