[clang-format] Preserve whitespace in selected macros
authorJake Merdich <Jake.Merdich@amd.com>
Fri, 26 Jun 2020 01:59:33 +0000 (21:59 -0400)
committerJake Merdich <Jake.Merdich@amd.com>
Mon, 29 Jun 2020 13:57:47 +0000 (09:57 -0400)
commit0c332a7784c649038bd237a60fa18b45a3dea90d
treef5b15645d5e39988935c8f3e3768bb1fd91d919e
parent3b95d8346d58396c119e4ac9cc00aeddfb74f00d
[clang-format] Preserve whitespace in selected macros

Summary:
https://bugs.llvm.org/show_bug.cgi?id=46383

When the c preprocessor stringizes tokens, the generated string literals
are affected by the whitespace. This means clang-format can affect
codegen silently, adding spaces and newlines to strings.  Practically
speaking, the vast majority of cases will be harmless, only affecting
single identifiers or debug macros.

In the interest of doing no harm in other cases though, this introduces
a blacklist option 'WhitespaceSensitiveMacros', which contains a list of
names of function-like macros whose contents should not be touched by
clang-format, period. Clang-format can't automatically detect these
without a real compile context, so users will have to specify it
explicitly (it still beats clang-format off'ing at every invocation).

Defaults include "STRINGIZE", "PP_STRINGIZE", and "BOOST_PP_STRINGIZE".

Subscribers: kristof.beyls, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82620
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/lib/Format/FormatToken.h
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp