diff options
author | Jakub Jelinek <jakub@redhat.com> | 2020-03-19 22:56:20 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2020-03-19 22:56:20 +0100 |
commit | 9def91e9f2a7051c9c146f16c1a10d1b25d33b47 (patch) | |
tree | 53ce53c9c692194b29966258b3d4c0ef7ea4c3d7 /gcc/c/ChangeLog | |
parent | 37482edc3f7f19110da7178d0d4c3003ea5272f3 (diff) | |
download | gcc-9def91e9f2a7051c9c146f16c1a10d1b25d33b47.zip gcc-9def91e9f2a7051c9c146f16c1a10d1b25d33b47.tar.gz gcc-9def91e9f2a7051c9c146f16c1a10d1b25d33b47.tar.bz2 |
c: Fix up cfun->function_end_locus from the C FE [PR94029]
On the following testcase we ICE because while
DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
= c_parser_peek_token (parser)->location;
and similarly DECL_SOURCE_LOCATION (fndecl) is set from some token's
location, the end is set as:
/* Store the end of the function, so that we get good line number
info for the epilogue. */
cfun->function_end_locus = input_location;
and the thing is that input_location is only very rarely set in the C FE
(the primary spot that changes it is the cb_line_change/fe_file_change).
Which means, e.g. for pretty much all C functions that are on a single line,
function_start_locus column is > than function_end_locus column, and the
testcase even has smaller line in function_end_locus because cb_line_change
isn't performed while parsing multi-line arguments of a function-like macro.
Attached are two possible fixes to achieve what the C++ FE does, in
particular that cfun->function_end_locus is the locus of the closing } of
the function. The first one updates input_location when we see a closing }
of a compound statement (though any, not just the function body) and thus
input_location in the finish_function call is what we need.
The second instead propagates the location_t from the parsing of the
outermost compound statement (the function body) to finish_function.
The second one is this version.
2020-03-19 Jakub Jelinek <jakub@redhat.com>
PR gcov-profile/94029
* c-tree.h (finish_function): Add location_t argument defaulted to
input_location.
* c-parser.c (c_parser_compound_statement): Add endlocp argument and
set it to the locus of closing } if non-NULL.
(c_parser_compound_statement_nostart): Return locus of closing }.
(c_parser_parse_rtl_body): Likewise.
(c_parser_declaration_or_fndef): Propagate locus of closing } to
finish_function.
* c-decl.c (finish_function): Add end_loc argument, use it instead of
input_location to set function_end_locus.
* gcc.misc-tests/gcov-pr94029.c: New test.
Diffstat (limited to 'gcc/c/ChangeLog')
-rw-r--r-- | gcc/c/ChangeLog | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 25f8f5b..c0b65a5 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,17 @@ +2020-03-19 Jakub Jelinek <jakub@redhat.com> + + PR gcov-profile/94029 + * c-tree.h (finish_function): Add location_t argument defaulted to + input_location. + * c-parser.c (c_parser_compound_statement): Add endlocp argument and + set it to the locus of closing } if non-NULL. + (c_parser_compound_statement_nostart): Return locus of closing }. + (c_parser_parse_rtl_body): Likewise. + (c_parser_declaration_or_fndef): Propagate locus of closing } to + finish_function. + * c-decl.c (finish_function): Add end_loc argument, use it instead of + input_location to set function_end_locus. + 2020-03-17 Jakub Jelinek <jakub@redhat.com> PR c/94172 |