https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54224
--- Comment #24 from Manuel López-Ibáñez <manu at gcc dot gnu.org> --- (In reply to Dominique d'Humieres from comment #23) > > I'm not a Fortran dev, but I would humbly suggest to add this testcase > > to the regression testsuite before closing the bug. > > OK. REOPENED. > > > Also: > > > > > pr54224_3.f90:6:0: > > > > > > subroutine s2 > > > ^ > > > > You will get a more precise column info (and better location for '^') > > if Fortran gives a more precise DECL_SOURCE_LOCATION() when generating this > > tree. > > Could you please elaborate? I don't know the Fortran FE that well, but at some moment it creates this tree and it sets DECL_SOURCE_LOCATION(). Probably based on some loc->lb->location. However, that only contains line number info because Fortran does not use libcpp/line-map.c for tracking column numbers (it only creates new locations for line changes). Fully using line-map.c in Fortran is likely to be a lot of work, but it could mean getting precise macro locations (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53934#c2) and remove some of the duplication between libcpp and Fortran (tokenizer, file inclusion, etc.) Nonetheless, as a work-around, you could use: unsigned int offset = loc->nextc - loc->lb->line; location = linemap_position_for_loc_and_offset (line_table, loc->lb->location, offset)); to create a new location_t with the correct column number and use that for the tree it creates.