diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-02-02 18:42:48 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-02-02 18:42:48 +0000 |
commit | 3ec6663be0ed79325d9d865a31f514e2f4e218fe (patch) | |
tree | 0349663331af938bf06aa107523d24ff9f951ed5 /clang/lib/Frontend/FrontendActions.cpp | |
parent | 248bc72737797c34d22f7d0fce34d87339b7c1ea (diff) | |
download | bcm5719-llvm-3ec6663be0ed79325d9d865a31f514e2f4e218fe.tar.gz bcm5719-llvm-3ec6663be0ed79325d9d865a31f514e2f4e218fe.zip |
Back out my heinous hack that tricked the module generation mechanism
into using non-absolute system includes (<foo>)...
... and introduce another hack that is simultaneously more heineous
and more effective. We whitelist Clang-supplied headers that augment
or override system headers (such as float.h, stdarg.h, and
tgmath.h). For these headers, Clang does not provide a module
mapping. Instead, a system-supplied module map can refer to these
headers in a system module, and Clang will look both in its own
include directory and wherever the system-supplied module map
suggests, then adds either or both headers. The end result is that
Clang-supplied headers get merged into the system-supplied module for
the C standard library.
As a drive-by, fix up a few dependencies in the _Builtin_instrinsics
module.
llvm-svn: 149611
Diffstat (limited to 'clang/lib/Frontend/FrontendActions.cpp')
-rw-r--r-- | clang/lib/Frontend/FrontendActions.cpp | 65 |
1 files changed, 26 insertions, 39 deletions
diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index edadf377669..c0302329c1e 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -126,32 +126,6 @@ ASTConsumer *GenerateModuleAction::CreateASTConsumer(CompilerInstance &CI, Sysroot, OS); } -/// \brief Add an appropriate #include/#import for the given header within -/// the current module context. -static void addHeaderInclude(StringRef Header, - bool IsBuiltinModule, - const LangOptions &LangOpts, - llvm::SmallString<256> &Includes) { - if (IsBuiltinModule) { - // Our own builtin headers play some evil tricks that depend both on - // knowing that our headers will be found first and on include_next. To - // Make sure these include_next tricks work, we include with <> and - // just the filename itself rather than using an absolutely path. - // FIXME: Is there some sensible way to generalize this? - Includes += "#include <"; - Includes += llvm::sys::path::filename(Header); - Includes += ">\n"; - return; - } - - if (LangOpts.ObjC1) - Includes += "#import \""; - else - Includes += "#include \""; - Includes += Header; - Includes += "\"\n"; -} - /// \brief Collect the set of header includes needed to construct the given /// module. /// @@ -163,21 +137,31 @@ static void collectModuleHeaderIncludes(const LangOptions &LangOpts, FileManager &FileMgr, ModuleMap &ModMap, clang::Module *Module, - bool IsBuiltinModule, llvm::SmallString<256> &Includes) { // Don't collect any headers for unavailable modules. if (!Module->isAvailable()) return; // Add includes for each of these headers. - for (unsigned I = 0, N = Module->Headers.size(); I != N; ++I) - addHeaderInclude(Module->Headers[I]->getName(), IsBuiltinModule, LangOpts, - Includes); + for (unsigned I = 0, N = Module->Headers.size(); I != N; ++I) { + if (LangOpts.ObjC1) + Includes += "#import \""; + else + Includes += "#include \""; + Includes += Module->Headers[I]->getName(); + Includes += "\"\n"; + } if (const FileEntry *UmbrellaHeader = Module->getUmbrellaHeader()) { - if (Module->Parent) - addHeaderInclude(UmbrellaHeader->getName(), IsBuiltinModule, LangOpts, - Includes); + if (Module->Parent) { + // Include the umbrella header for submodules. + if (LangOpts.ObjC1) + Includes += "#import \""; + else + Includes += "#include \""; + Includes += UmbrellaHeader->getName(); + Includes += "\"\n"; + } } else if (const DirectoryEntry *UmbrellaDir = Module->getUmbrellaDir()) { // Add all of the headers we find in this subdirectory. llvm::error_code EC; @@ -199,8 +183,13 @@ static void collectModuleHeaderIncludes(const LangOptions &LangOpts, if (ModMap.isHeaderInUnavailableModule(Header)) continue; - // Include this header. - addHeaderInclude(Dir->path(), IsBuiltinModule, LangOpts, Includes); + // Include this header umbrella header for submodules. + if (LangOpts.ObjC1) + Includes += "#import \""; + else + Includes += "#include \""; + Includes += Dir->path(); + Includes += "\"\n"; } } @@ -208,8 +197,7 @@ static void collectModuleHeaderIncludes(const LangOptions &LangOpts, for (clang::Module::submodule_iterator Sub = Module->submodule_begin(), SubEnd = Module->submodule_end(); Sub != SubEnd; ++Sub) - collectModuleHeaderIncludes(LangOpts, FileMgr, ModMap, *Sub, - IsBuiltinModule, Includes); + collectModuleHeaderIncludes(LangOpts, FileMgr, ModMap, *Sub, Includes); } bool GenerateModuleAction::BeginSourceFileAction(CompilerInstance &CI, @@ -261,11 +249,10 @@ bool GenerateModuleAction::BeginSourceFileAction(CompilerInstance &CI, const FileEntry *UmbrellaHeader = Module->getUmbrellaHeader(); // Collect the set of #includes we need to build the module. - bool IsBuiltinModule = StringRef(Module->Name).startswith("_Builtin_"); llvm::SmallString<256> HeaderContents; collectModuleHeaderIncludes(CI.getLangOpts(), CI.getFileManager(), CI.getPreprocessor().getHeaderSearchInfo().getModuleMap(), - Module, IsBuiltinModule, HeaderContents); + Module, HeaderContents); if (UmbrellaHeader && HeaderContents.empty()) { // Simple case: we have an umbrella header and there are no additional // includes, we can just parse the umbrella header directly. |