[all-commits] [llvm/llvm-project] d7354f: Keep multiple-include optimization for null direct...

Elliot Goodrich via All-commits all-commits at lists.llvm.org
Thu Apr 27 10:44:29 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: d7354fb63471a7a38993280c8264fd8d57432dc7
      https://github.com/llvm/llvm-project/commit/d7354fb63471a7a38993280c8264fd8d57432dc7
  Author: Elliot Goodrich <elliotgoodrich at gmail.com>
  Date:   2023-04-27 (Thu, 27 Apr 2023)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/Lex/MultipleIncludeOpt.h
    M clang/lib/Lex/PPDirectives.cpp
    A clang/test/Preprocessor/multiple-inclusion-opt.cpp
    A clang/test/Preprocessor/multiple-inclusion-opt.h

  Log Message:
  -----------
  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




More information about the All-commits mailing list