diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2011-09-22 21:41:16 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2011-09-22 21:41:16 +0000 |
commit | 8404eb0badf2911f5afe5039c3887919875dcad5 (patch) | |
tree | b76a16c33c3383324aca2fb7ca2bf6e13a4db595 /clang/lib/Frontend | |
parent | e92e5ee81fe87c036fa41f85a31d4ded35732834 (diff) | |
download | bcm5719-llvm-8404eb0badf2911f5afe5039c3887919875dcad5.tar.gz bcm5719-llvm-8404eb0badf2911f5afe5039c3887919875dcad5.zip |
Add support for CPATH and friends.
This moves the existing code for CPATH into the driver and adds the environment lookup and path splitting there.
The paths are then passed down to cc1 with -I options (CPATH), added after the normal user-specified include dirs.
Language specific paths are passed via -LANG-isystem and the actual filtering is performed in the frontend.
I tried to match GCC's behavior as close as possible
Fixes PR8971.
llvm-svn: 140341
Diffstat (limited to 'clang/lib/Frontend')
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 57 | ||||
-rw-r--r-- | clang/lib/Frontend/InitHeaderSearch.cpp | 41 |
2 files changed, 35 insertions, 63 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 7cb707b9661..e6992613791 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -534,9 +534,21 @@ static void HeaderSearchOptsToArgs(const HeaderSearchOptions &Opts, Res.push_back(E.IsFramework? "-F" : "-I"); break; + case frontend::CSystem: + Res.push_back("-c-isystem"); + break; + case frontend::CXXSystem: Res.push_back("-cxx-isystem"); break; + + case frontend::ObjCSystem: + Res.push_back("-objc-isystem"); + break; + + case frontend::ObjCXXSystem: + Res.push_back("-objcxx-isystem"); + break; case frontend::Angled: Res.push_back(E.IsFramework ? "-F" : "-I"); @@ -551,26 +563,6 @@ static void HeaderSearchOptsToArgs(const HeaderSearchOptions &Opts, Res.push_back(E.Path); } - if (!Opts.EnvIncPath.empty()) { - // FIXME: Provide an option for this, and move env detection to driver. - llvm::report_fatal_error("Not yet implemented!"); - } - if (!Opts.CEnvIncPath.empty()) { - // FIXME: Provide an option for this, and move env detection to driver. - llvm::report_fatal_error("Not yet implemented!"); - } - if (!Opts.ObjCEnvIncPath.empty()) { - // FIXME: Provide an option for this, and move env detection to driver. - llvm::report_fatal_error("Not yet implemented!"); - } - if (!Opts.CXXEnvIncPath.empty()) { - // FIXME: Provide an option for this, and move env detection to driver. - llvm::report_fatal_error("Not yet implemented!"); - } - if (!Opts.ObjCXXEnvIncPath.empty()) { - // FIXME: Provide an option for this, and move env detection to driver. - llvm::report_fatal_error("Not yet implemented!"); - } if (!Opts.ResourceDir.empty()) { Res.push_back("-resource-dir"); Res.push_back(Opts.ResourceDir); @@ -1424,14 +1416,25 @@ static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) { for (arg_iterator it = Args.filtered_begin(OPT_iquote), ie = Args.filtered_end(); it != ie; ++it) Opts.AddPath((*it)->getValue(Args), frontend::Quoted, true, false, false); - for (arg_iterator it = Args.filtered_begin(OPT_cxx_isystem, OPT_isystem, + for (arg_iterator it = Args.filtered_begin(OPT_isystem, OPT_iwithsysroot), ie = Args.filtered_end(); it != ie; ++it) - Opts.AddPath((*it)->getValue(Args), - ((*it)->getOption().matches(OPT_cxx_isystem) ? - frontend::CXXSystem : frontend::System), - true, false, !(*it)->getOption().matches(OPT_iwithsysroot)); - - // FIXME: Need options for the various environment variables! + Opts.AddPath((*it)->getValue(Args), frontend::System, true, false, + !(*it)->getOption().matches(OPT_iwithsysroot)); + + // Add the paths for the various language specific isystem flags. + for (arg_iterator it = Args.filtered_begin(OPT_c_isystem), + ie = Args.filtered_end(); it != ie; ++it) + Opts.AddPath((*it)->getValue(Args), frontend::CSystem, true, false, true); + for (arg_iterator it = Args.filtered_begin(OPT_cxx_isystem), + ie = Args.filtered_end(); it != ie; ++it) + Opts.AddPath((*it)->getValue(Args), frontend::CXXSystem, true, false, true); + for (arg_iterator it = Args.filtered_begin(OPT_objc_isystem), + ie = Args.filtered_end(); it != ie; ++it) + Opts.AddPath((*it)->getValue(Args), frontend::ObjCSystem, true, false,true); + for (arg_iterator it = Args.filtered_begin(OPT_objcxx_isystem), + ie = Args.filtered_end(); it != ie; ++it) + Opts.AddPath((*it)->getValue(Args), frontend::ObjCXXSystem, true, false, + true); } void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK, diff --git a/clang/lib/Frontend/InitHeaderSearch.cpp b/clang/lib/Frontend/InitHeaderSearch.cpp index 08af5322675..089ded19cef 100644 --- a/clang/lib/Frontend/InitHeaderSearch.cpp +++ b/clang/lib/Frontend/InitHeaderSearch.cpp @@ -81,10 +81,6 @@ public: void AddMinGW64CXXPaths(StringRef Base, StringRef Version); - /// AddDelimitedPaths - Add a list of paths delimited by the system PATH - /// separator. The processing follows that of the CPATH variable for gcc. - void AddDelimitedPaths(StringRef String); - // AddDefaultCIncludePaths - Add paths that should always be searched. void AddDefaultCIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts); @@ -167,26 +163,6 @@ void InitHeaderSearch::AddPath(const Twine &Path, << MappedPathStr << "\"\n"; } - -void InitHeaderSearch::AddDelimitedPaths(StringRef at) { - if (at.empty()) // Empty string should not add '.' path. - return; - - StringRef::size_type delim; - while ((delim = at.find(llvm::sys::PathSeparator)) != StringRef::npos) { - if (delim == 0) - AddPath(".", Angled, false, true, false); - else - AddPath(at.substr(0, delim), Angled, false, true, false); - at = at.substr(delim + 1); - } - - if (at.empty()) - AddPath(".", Angled, false, true, false); - else - AddPath(at, Angled, false, true, false); -} - void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(StringRef Base, StringRef ArchDir, StringRef Dir32, @@ -1094,7 +1070,11 @@ void InitHeaderSearch::Realize(const LangOptions &Lang) { for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); it != ie; ++it) { - if (it->first == System || (Lang.CPlusPlus && it->first == CXXSystem)) + if (it->first == System || + (!Lang.ObjC1 && !Lang.CPlusPlus && it->first == CSystem) || + (!Lang.ObjC1 && Lang.CPlusPlus && it->first == CXXSystem) || + (Lang.ObjC1 && !Lang.CPlusPlus && it->first == ObjCSystem) || + (Lang.ObjC1 && Lang.CPlusPlus && it->first == ObjCXXSystem)) SearchList.push_back(it->second); } @@ -1147,17 +1127,6 @@ void clang::ApplyHeaderSearchOptions(HeaderSearch &HS, E.IgnoreSysRoot); } - // Add entries from CPATH and friends. - Init.AddDelimitedPaths(HSOpts.EnvIncPath); - if (Lang.CPlusPlus && Lang.ObjC1) - Init.AddDelimitedPaths(HSOpts.ObjCXXEnvIncPath); - else if (Lang.CPlusPlus) - Init.AddDelimitedPaths(HSOpts.CXXEnvIncPath); - else if (Lang.ObjC1) - Init.AddDelimitedPaths(HSOpts.ObjCEnvIncPath); - else - Init.AddDelimitedPaths(HSOpts.CEnvIncPath); - if (HSOpts.UseStandardIncludes) Init.AddDefaultSystemIncludePaths(Lang, Triple, HSOpts); |