[PATCH] D106394: [clang][pp] adds '#pragma include_instead'

Christopher Di Bella via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 20 13:14:47 PDT 2021


cjdb created this revision.
cjdb added reviewers: aaron.ballman, rsmith, gbiv, dblaikie, cor3ntin.
Herald added a reviewer: george.burgess.iv.
Herald added subscribers: usaxena95, kadircet.
cjdb requested review of this revision.
Herald added subscribers: cfe-commits, ilya-biryukov.
Herald added a project: clang.

`#pragma clang include_instead(<header>)` is a pragma that can be used
by system headers (and only system headers) to indicate to a tool that
the file containing said pragma is an implementation-detail header and
should not be directly included by user code.

The library alternative is very messy code that can be seen in the first
diff of D106124 <https://reviews.llvm.org/D106124>, and we'd rather avoid that with something more
universal.

This patch takes the first step by warning a user when they include a
detail header in their code, and suggests alternative headers that the
user should include instead. Future work will involve adding a fixit to
automate the process, as well as cleaning up modules diagnostics to not
suggest said detail headers. Other tools, such as clangd can also take
advantage of this pragma to add the correct user headers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106394

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Lex/PreprocessorLexer.h
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Lex/Pragma.cpp
  clang/test/Preprocessor/Inputs/include_instead/include_instead-bad-syntax.h
  clang/test/Preprocessor/Inputs/include_instead/include_instead-non-system-header.h
  clang/test/Preprocessor/Inputs/include_instead/include_instead-nowarn.h
  clang/test/Preprocessor/Inputs/include_instead/include_instead-warns-three-alternatives.h
  clang/test/Preprocessor/Inputs/include_instead/include_instead-warns-two-alternatives.h
  clang/test/Preprocessor/Inputs/include_instead/include_instead-warns.h
  clang/test/Preprocessor/Inputs/include_instead/malloc.h
  clang/test/Preprocessor/include_instead.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106394.360252.patch
Type: text/x-patch
Size: 19023 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210720/0f8c4f50/attachment-0001.bin>


More information about the cfe-commits mailing list