Currently, all location_t locations (such as gfc_current_locus->lb->location) always point to the beginning of the line, i.e. LOCATION_COLUMN(...) == 0. For front-end diagnostic, this is corrected in gcc/fortran/error.c's gfc_format_decoder using: unsigned int offset = loc->nextc - loc->lb->line; int loc_num = text->get_location (0) == UNKNOWN_LOCATION ? 0 : 1; location_t src_loc = linemap_position_for_loc_and_offset (line_table, loc->lb->location, offset); But this correction does not happen when setting the location for 'tree', e.g.: build_decl (ns->proc_name->declared_at.lb->location or tmp = fold_build1_loc (code->expr1->where.lb->location, LOOP_EXPR or … The question is how to fix this best. My feeling is that it should already be fixed in the scanner such that loc->lb->location is always correct and we can get rid off the offset calculation in error.c
Patch: https://gcc.gnu.org/ml/gcc-patches/2019-12/msg00207.html
Author: burnus Date: Sat Dec 7 11:07:07 2019 New Revision: 279075 URL: https://gcc.gnu.org/viewcvs?rev=279075&root=gcc&view=rev Log: Fortran] PR 92793 - fix column used for error diagnostic PR fortran/92793 * trans.c (gfc_get_location): Declare. * trans.c (gfc_get_location): Define; returns column-corrected location. (trans_runtime_error_vararg, gfc_trans_runtime_check, gfc_generate_module_code): Use new function. * trans-array.c (gfc_trans_auto_array_allocation): Likewise. * trans-common.c (build_field, get_init_field, create_common): Likewise. * trans-decl.c (gfc_build_label_decl, gfc_get_symbol_decl): Likewise. * trans-openmp.c (gfc_trans_omp_reduction_list, gfc_trans_omp_clauses): Likewise. * trans-stmt.c (gfc_trans_if_1): Likewise. Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/trans-array.c trunk/gcc/fortran/trans-common.c trunk/gcc/fortran/trans-decl.c trunk/gcc/fortran/trans-openmp.c trunk/gcc/fortran/trans-stmt.c trunk/gcc/fortran/trans.c trunk/gcc/fortran/trans.h
FIXED on GCC 10/trunk
Author: frederik Date: Tue Dec 10 16:12:58 2019 New Revision: 279169 URL: https://gcc.gnu.org/viewcvs?rev=279169&root=gcc&view=rev Log: Add tests to verify OpenACC clause locations Check that the column information for OpenACC clauses is communicated correctly to the middle-end, in particular by the Fortran front-end (cf. PR 92793). 2019-12-10 Frederik Harwath <frederik@codesourcery.com> gcc/testsuite/ * c-c++-common/goacc/clause-locations.c: New test. * gfortran.dg/goacc/clause-locations.f90: New test. Added: trunk/gcc/testsuite/c-c++-common/goacc/clause-locations.c trunk/gcc/testsuite/gfortran.dg/goacc/clause-locations.f90 Modified: trunk/gcc/testsuite/ChangeLog
The master branch has been updated by Thomas Schwinge <tschwinge@gcc.gnu.org>: https://gcc.gnu.org/g:fa410314ec94c9df2ad270c1917adc51f9147c2c commit r11-4567-gfa410314ec94c9df2ad270c1917adc51f9147c2c Author: Thomas Schwinge <thomas@codesourcery.com> Date: Thu Oct 29 16:12:38 2020 +0100 [OpenACC] Elaborate testcases that verify column location information [PR92793] After PR92793 commit 9c81750c5bedd7883182ee2684a012c6210ebe1d "Fortran] PR 92793 - fix column used for error diagnostic", commit d0d0ba20f2345023e9cec2419c9fb9e6cc7098c6 did "Add tests to verify OpenACC clause locations", later fixed up in PR92901 commit e6c90dba73291435c244decb9a89c47019cc5a45 to "Fix PR92901: Change test expectation for C++ in OpenACC test clause-locations.c". Now, add some more testing to verify/document the status quo. gcc/testsuite/ PR fortran/92793 * c-c++-common/goacc/clause-locations.c: Rewrite into... * c-c++-common/goacc/pr92793-1.c: ... this. * gfortran.dg/goacc/clause-locations.f90: Rewrite into... * gfortran.dg/goacc/pr92793-1.f90: ... this.
The releases/gcc-10 branch has been updated by Thomas Schwinge <tschwinge@gcc.gnu.org>: https://gcc.gnu.org/g:fc423b4e5b16dc02cc9f91fdfc800d00a5103dea commit r10-8956-gfc423b4e5b16dc02cc9f91fdfc800d00a5103dea Author: Thomas Schwinge <thomas@codesourcery.com> Date: Thu Oct 29 16:12:38 2020 +0100 [OpenACC] Elaborate testcases that verify column location information [PR92793] After PR92793 commit 9c81750c5bedd7883182ee2684a012c6210ebe1d "Fortran] PR 92793 - fix column used for error diagnostic", commit d0d0ba20f2345023e9cec2419c9fb9e6cc7098c6 did "Add tests to verify OpenACC clause locations", later fixed up in PR92901 commit e6c90dba73291435c244decb9a89c47019cc5a45 to "Fix PR92901: Change test expectation for C++ in OpenACC test clause-locations.c". Now, add some more testing to verify/document the status quo. gcc/testsuite/ PR fortran/92793 * c-c++-common/goacc/clause-locations.c: Rewrite into... * c-c++-common/goacc/pr92793-1.c: ... this. * gfortran.dg/goacc/clause-locations.f90: Rewrite into... * gfortran.dg/goacc/pr92793-1.f90: ... this. (cherry picked from commit fa410314ec94c9df2ad270c1917adc51f9147c2c)
The master branch has been updated by Thomas Schwinge <tschwinge@gcc.gnu.org>: https://gcc.gnu.org/g:5677444f7e7ca15557030902c3d09dab4852fa90 commit r11-4608-g5677444f7e7ca15557030902c3d09dab4852fa90 Author: Thomas Schwinge <thomas@codesourcery.com> Date: Fri Oct 30 13:13:51 2020 +0100 Further improve Fortran column location information [PR92793] Building on top of commit 9c81750c5bedd7883182ee2684a012c6210ebe1d "Fortran] PR 92793 - fix column used for error diagnostic", there is another place where we have to use 'gfc_get_location' returning column-corrected locations. For example, this improves column location information for OMP constructs. gcc/fortran/ PR fortran/92793 * trans.c (gfc_set_backend_locus): Use 'gfc_get_location'. (gfc_restore_backend_locus): Adjust. gcc/testsuite/ PR fortran/92793 * gfortran.dg/goacc/pr92793-1.f90: Adjust.
The releases/gcc-10 branch has been updated by Thomas Schwinge <tschwinge@gcc.gnu.org>: https://gcc.gnu.org/g:a5c5f9e181c1f7548930f1cab91002b9d460cc92 commit r10-8960-ga5c5f9e181c1f7548930f1cab91002b9d460cc92 Author: Thomas Schwinge <thomas@codesourcery.com> Date: Fri Oct 30 13:13:51 2020 +0100 Further improve Fortran column location information [PR92793] Building on top of commit 9c81750c5bedd7883182ee2684a012c6210ebe1d "Fortran] PR 92793 - fix column used for error diagnostic", there is another place where we have to use 'gfc_get_location' returning column-corrected locations. For example, this improves column location information for OMP constructs. gcc/fortran/ PR fortran/92793 * trans.c (gfc_set_backend_locus): Use 'gfc_get_location'. (gfc_restore_backend_locus): Adjust. gcc/testsuite/ PR fortran/92793 * gfortran.dg/goacc/pr92793-1.f90: Adjust. (cherry picked from commit 5677444f7e7ca15557030902c3d09dab4852fa90)
The master branch has been updated by Thomas Schwinge <tschwinge@gcc.gnu.org>: https://gcc.gnu.org/g:41f7f6178e2d35288273656dc55dae8fcf3edeb5 commit r11-4639-g41f7f6178e2d35288273656dc55dae8fcf3edeb5 Author: Thomas Schwinge <thomas@codesourcery.com> Date: Tue Oct 27 17:14:10 2020 +0100 [Fortran] More precise location information for OpenACC 'gang', 'worker', 'vector' clauses with argument [PR92793] gcc/fortran/ PR fortran/92793 * trans-openmp.c (gfc_trans_omp_clauses): More precise location information for OpenACC 'gang', 'worker', 'vector' clauses with argument. gcc/testsuite/ PR fortran/92793 * gfortran.dg/goacc/pr92793-1.f90: Adjust.
The releases/gcc-10 branch has been updated by Thomas Schwinge <tschwinge@gcc.gnu.org>: https://gcc.gnu.org/g:5ceaf8a54abb3f9bd3c268fe420999a7962b2a15 commit r10-8965-g5ceaf8a54abb3f9bd3c268fe420999a7962b2a15 Author: Thomas Schwinge <thomas@codesourcery.com> Date: Tue Oct 27 17:14:10 2020 +0100 [Fortran] More precise location information for OpenACC 'gang', 'worker', 'vector' clauses with argument [PR92793] gcc/fortran/ PR fortran/92793 * trans-openmp.c (gfc_trans_omp_clauses): More precise location information for OpenACC 'gang', 'worker', 'vector' clauses with argument. gcc/testsuite/ PR fortran/92793 * gfortran.dg/goacc/pr92793-1.f90: Adjust. (cherry picked from commit 41f7f6178e2d35288273656dc55dae8fcf3edeb5)