10#include "clang/AST/ASTContext.h"
11#include "clang/Lex/HeaderSearch.h"
12#include "clang/Lex/HeaderSearchOptions.h"
13#include "clang/Lex/Preprocessor.h"
22class RestrictedIncludesPPCallbacks
23 :
public portability::RestrictedIncludesPPCallbacks {
25 explicit RestrictedIncludesPPCallbacks(
26 RestrictSystemLibcHeadersCheck &Check,
const SourceManager &SM,
27 const SmallString<128> CompilerIncudeDir)
28 : portability::RestrictedIncludesPPCallbacks(Check, SM),
29 CompilerIncudeDir(CompilerIncudeDir) {}
31 void InclusionDirective(SourceLocation HashLoc,
const Token &IncludeTok,
32 StringRef FileName,
bool IsAngled,
33 CharSourceRange FilenameRange,
34 OptionalFileEntryRef File, StringRef SearchPath,
35 StringRef RelativePath,
const Module *SuggestedModule,
37 SrcMgr::CharacteristicKind FileType)
override;
40 const SmallString<128> CompilerIncudeDir;
46 SourceLocation HashLoc,
const Token &IncludeTok, StringRef FileName,
47 bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
48 StringRef SearchPath, StringRef RelativePath,
const Module *SuggestedModule,
49 bool ModuleImported, SrcMgr::CharacteristicKind FileType) {
51 if (SrcMgr::isSystem(FileType) && SearchPath == CompilerIncudeDir)
54 HashLoc, IncludeTok, FileName, IsAngled, FilenameRange, File, SearchPath,
55 RelativePath, SuggestedModule, ModuleImported, FileType);
59 const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
60 SmallString<128> CompilerIncudeDir =
61 StringRef(PP->getHeaderSearchInfo().getHeaderSearchOpts().ResourceDir);
62 llvm::sys::path::append(CompilerIncudeDir,
"include");
63 PP->addPPCallbacks(std::make_unique<RestrictedIncludesPPCallbacks>(
64 *
this, SM, CompilerIncudeDir));
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *SuggestedModule, bool ModuleImported, SrcMgr::CharacteristicKind FileType) override