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/c-tree.h | |
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/c-tree.h')
-rw-r--r-- | gcc/c/c-tree.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h index 364d7e0..2015827 100644 --- a/gcc/c/c-tree.h +++ b/gcc/c/c-tree.h @@ -580,7 +580,7 @@ extern bool c_check_switch_jump_warnings (struct c_spot_bindings *, location_t, location_t); extern void finish_decl (tree, location_t, tree, tree, tree); extern tree finish_enum (tree, tree, tree); -extern void finish_function (void); +extern void finish_function (location_t = input_location); extern tree finish_struct (location_t, tree, tree, tree, class c_struct_parse_info *); extern tree c_simulate_enum_decl (location_t, const char *, |