diff options
author | Patrick Palka <ppalka@redhat.com> | 2020-09-17 14:27:22 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2020-09-17 14:27:22 -0400 |
commit | 4839de55e2c98619f4919254abb87e2f393aaead (patch) | |
tree | 6b191cd26456d813b29ea6204c1730004879fa5d /libcpp/include/line-map.h | |
parent | 71e3d1970c00a74be16c0f5a3fcaced359077135 (diff) | |
download | gcc-4839de55e2c98619f4919254abb87e2f393aaead.zip gcc-4839de55e2c98619f4919254abb87e2f393aaead.tar.gz gcc-4839de55e2c98619f4919254abb87e2f393aaead.tar.bz2 |
c-family: Macro support in -Wmisleading-indentation [PR80076]
Currently the -Wmisleading-indentation warning doesn't do any analysis
when the guarded statement or the statement after it is produced by a
macro. This means we warn for:
if (flag)
foo ();
bar ();
but not for:
#define BAR bar
if (flag)
foo ();
BAR ();
This patch extends the -Wmisleading-indentation implementation to
support analyzing such statements and their tokens. This is done in the
"natural" way by resolving the location of each of the three tokens to
the token's macro expansion point. (Additionally, if the tokens all
resolve to the same macro expansion point then we instead use their
locations within the macro definition.) When these resolved locations
are all different, then we can proceed with applying the warning
heuristics to them as if no macros were involved.
gcc/c-family/ChangeLog:
PR c/80076
* c-indentation.c (should_warn_for_misleading_indentation): Move
declarations of local variables closer to their first use.
Handle virtual token locations by resolving them to their
respective macro expansion points. If all three tokens are
produced from the same macro expansion, then instead use their
loci within the macro definition.
gcc/objc/ChangeLog:
PR c/80076
* objc-gnu-runtime-abi-01.c
(gnu_runtime_abi_01_get_class_super_ref): Reduce indentation of
misleadingly indented return statements.
* objc-next-runtime-abi-01.c
(next_runtime_abi_01_get_class_super_ref): Likewise.
gcc/ChangeLog:
PR c/80076
* gensupport.c (alter_attrs_for_subst_insn) <case SET_ATTR>:
Reduce indentation of misleadingly indented code fragment.
* lra-constraints.c (multi_block_pseudo_p): Likewise.
* sel-sched-ir.c (merge_fences): Likewise.
libcpp/ChangeLog:
PR c/80076
* include/line-map.h (first_map_in_common): Declare.
* line-map.c (first_map_in_common): Remove static.
gcc/testsuite/ChangeLog:
PR c/80076
* c-c++-common/Wmisleading-indentation-5.c: New test.
Diffstat (limited to 'libcpp/include/line-map.h')
-rw-r--r-- | libcpp/include/line-map.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h index 217f916..44008be 100644 --- a/libcpp/include/line-map.h +++ b/libcpp/include/line-map.h @@ -1225,6 +1225,12 @@ LINEMAP_SYSP (const line_map_ordinary *ord_map) return ord_map->sysp; } +const struct line_map *first_map_in_common (line_maps *set, + location_t loc0, + location_t loc1, + location_t *res_loc0, + location_t *res_loc1); + /* Return a positive value if PRE denotes the location of a token that comes before the token of POST, 0 if PRE denotes the location of the same token as the token for POST, and a negative value |