gcc/libcpp
Patrick Palka 4839de55e2 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.
2020-09-17 14:27:22 -04:00
..
include c-family: Macro support in -Wmisleading-indentation [PR80076] 2020-09-17 14:27:22 -04:00
po Daily bump. 2020-07-21 00:16:28 +00:00
ChangeLog Daily bump. 2020-09-08 00:16:32 +00:00
ChangeLog.jit
Makefile.in libcpp, libdecnumber: configure and substitute AR 2020-05-23 21:59:02 +00:00
aclocal.m4 libcpp: Enable Intel CET on Intel CET enabled host for jit 2020-05-12 09:17:45 -07:00
charset.c diagnostics: Support conversion of tabs to spaces [PR49973] [PR86904] 2020-07-14 12:05:56 -04:00
config.in
configure Require CET support only for the final GCC build 2020-07-30 05:36:24 -07:00
configure.ac libcpp, libdecnumber: configure and substitute AR 2020-05-23 21:59:02 +00:00
directives.c preprocessor: Better line info for <builtin> & <command-line> 2020-07-07 11:40:04 -07:00
errors.c Update copyright years. 2020-01-01 12:51:42 +01:00
expr.c preprocessor: Make __has_include a builtin macro [PR93452] 2020-01-28 08:02:17 -08:00
files.c gcc: Make strchr return value pointers const 2020-09-07 13:20:21 +02:00
generated_cpp_wcwidth.h Byte vs column awareness for diagnostic-show-locus.c (PR 49973) 2019-12-09 20:03:47 +00:00
identifiers.c [PR 80005] Fix __has_include 2020-01-20 05:39:59 -08:00
init.c preprocessor: Teach traditional about has_include [PR95889] 2020-07-29 07:47:21 -07:00
internal.h preprocessor: Better line info for <builtin> & <command-line> 2020-07-07 11:40:04 -07:00
lex.c libcpp: Fix up raw string literal parsing error-recovery [PR96323] 2020-07-28 15:40:15 +02:00
line-map.c c-family: Macro support in -Wmisleading-indentation [PR80076] 2020-09-17 14:27:22 -04:00
location-example.txt PR preprocessor/83173: Enhance -fdump-internal-locations output 2018-11-27 16:04:31 +00:00
macro.c preprocessor: Fix ICE with EOF in macro args [pr95182] 2020-05-19 06:19:31 -07:00
makeucnid.c Update copyright years. 2020-01-01 12:51:42 +01:00
mkdeps.c Work around array out of bounds warning in mkdeps 2020-01-16 11:09:24 +01:00
pch.c preprocessor: Make __has_include a builtin macro [PR93452] 2020-01-28 08:02:17 -08:00
symtab.c Update copyright years. 2020-01-01 12:51:42 +01:00
system.h preprocessor: Random cleanups 2020-05-19 13:23:47 -07:00
traditional.c preprocessor: Teach traditional about has_include [PR95889] 2020-07-29 07:47:21 -07:00
ucnid.h Update copyright years. 2020-01-01 12:51:42 +01:00
ucnid.tab Update copyright years. 2020-01-01 12:51:42 +01:00