Bug 92793 - Fortran Location Data for Diagnostic lacks the column number – when passing on to ME
Summary: Fortran Location Data for Diagnostic lacks the column number – when passing o...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2019-12-04 11:42 UTC by Tobias Burnus
Modified: 2020-11-03 08:15 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2019-12-04 11:42:11 UTC
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
Comment 1 Tobias Burnus 2019-12-06 12:25:15 UTC
Patch: https://gcc.gnu.org/ml/gcc-patches/2019-12/msg00207.html
Comment 2 Tobias Burnus 2019-12-07 11:07:39 UTC
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
Comment 3 Tobias Burnus 2019-12-07 11:12:38 UTC
FIXED on GCC 10/trunk
Comment 4 Frederik Harwath 2019-12-10 16:13:30 UTC
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
Comment 5 GCC Commits 2020-10-30 10:28:37 UTC
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.
Comment 6 GCC Commits 2020-10-30 10:29:07 UTC
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)
Comment 7 GCC Commits 2020-11-02 13:26:28 UTC
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.
Comment 8 GCC Commits 2020-11-02 13:28:42 UTC
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)
Comment 9 GCC Commits 2020-11-03 08:14:52 UTC
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.
Comment 10 GCC Commits 2020-11-03 08:15:29 UTC
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)