Keep multiple-include optimization for null directives
authorElliot Goodrich <elliotgoodrich@gmail.com>
Thu, 27 Apr 2023 17:43:18 +0000 (13:43 -0400)
committerAaron Ballman <aaron@aaronballman.com>
Thu, 27 Apr 2023 17:44:11 +0000 (13:44 -0400)
commitd7354fb63471a7a38993280c8264fd8d57432dc7
tree60e47c6220cf8c63c666ebd5e99dfe86b5a19425
parent7417e9d75c9af7dd0d3dad12eebdee84b10b56d7
Keep multiple-include optimization for null directives

The multiple-include optimization allows Clang to avoid opening a
files when they contain #pragma once or a proper include guard.

Both GCC and Microsoft Visual Studio allow null directives outside of
the #ifndef/#endif pair without disabling this multiple-include
optimization. GCC documents this behavior here
https://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html.

> There must be no directives outside the controlling directive pair,
> but the null directive (a line containing nothing other than a
> single '#' and possibly whitespace) is permitted.

However, Clang disables the multiple-include optimization when
encountering the null directive.

In particular, this slows down preprocessing of most projects that
depend on boost as many boost libraries depend on the boost
preprocessor library, which contains null directives outside the
include guard on every header file.

Differential Revision: https://reviews.llvm.org/D147928
clang/docs/ReleaseNotes.rst
clang/include/clang/Lex/MultipleIncludeOpt.h
clang/lib/Lex/PPDirectives.cpp
clang/test/Preprocessor/multiple-inclusion-opt.cpp [new file with mode: 0644]
clang/test/Preprocessor/multiple-inclusion-opt.h [new file with mode: 0644]