InitHeaderSearch.cpp revision 870278bbbab94d3bc38fdd9487aae3829df314be
1//===--- InitHeaderSearch.cpp - Initialize header search paths ----------*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the InitHeaderSearch class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Frontend/InitHeaderSearch.h"
15#include "clang/Basic/FileManager.h"
16#include "clang/Basic/LangOptions.h"
17#include "clang/Frontend/HeaderSearchOptions.h"
18#include "clang/Lex/HeaderSearch.h"
19#include "llvm/ADT/SmallString.h"
20#include "llvm/ADT/SmallPtrSet.h"
21#include "llvm/Support/raw_ostream.h"
22#include "llvm/System/Path.h"
23#include "llvm/Config/config.h"
24#include <cstdio>
25#ifdef _MSC_VER
26  #define WIN32_LEAN_AND_MEAN 1
27  #include <windows.h>
28#endif
29using namespace clang;
30
31void InitHeaderSearch::AddPath(const llvm::StringRef &Path,
32                               IncludeDirGroup Group, bool isCXXAware,
33                               bool isUserSupplied, bool isFramework,
34                               bool IgnoreSysRoot) {
35  assert(!Path.empty() && "can't handle empty path here");
36  FileManager &FM = Headers.getFileMgr();
37
38  // Compute the actual path, taking into consideration -isysroot.
39  llvm::SmallString<256> MappedPath;
40
41  // Handle isysroot.
42  if (Group == System && !IgnoreSysRoot) {
43    // FIXME: Portability.  This should be a sys::Path interface, this doesn't
44    // handle things like C:\ right, nor win32 \\network\device\blah.
45    if (isysroot.size() != 1 || isysroot[0] != '/') // Add isysroot if present.
46      MappedPath.append(isysroot.begin(), isysroot.end());
47  }
48
49  MappedPath.append(Path.begin(), Path.end());
50
51  // Compute the DirectoryLookup type.
52  SrcMgr::CharacteristicKind Type;
53  if (Group == Quoted || Group == Angled)
54    Type = SrcMgr::C_User;
55  else if (isCXXAware)
56    Type = SrcMgr::C_System;
57  else
58    Type = SrcMgr::C_ExternCSystem;
59
60
61  // If the directory exists, add it.
62  if (const DirectoryEntry *DE = FM.getDirectory(MappedPath.str())) {
63    IncludeGroup[Group].push_back(DirectoryLookup(DE, Type, isUserSupplied,
64                                                  isFramework));
65    return;
66  }
67
68  // Check to see if this is an apple-style headermap (which are not allowed to
69  // be frameworks).
70  if (!isFramework) {
71    if (const FileEntry *FE = FM.getFile(MappedPath.str())) {
72      if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) {
73        // It is a headermap, add it to the search path.
74        IncludeGroup[Group].push_back(DirectoryLookup(HM, Type,isUserSupplied));
75        return;
76      }
77    }
78  }
79
80  if (Verbose)
81    llvm::errs() << "ignoring nonexistent directory \""
82                 << MappedPath.str() << "\"\n";
83}
84
85
86void InitHeaderSearch::AddDelimitedPaths(const char *at) {
87  if (*at == 0) // Empty string should not add '.' path.
88    return;
89
90  const char* delim = strchr(at, llvm::sys::PathSeparator);
91  while (delim != 0) {
92    if (delim-at == 0)
93      AddPath(".", Angled, false, true, false);
94    else
95      AddPath(llvm::StringRef(at, delim-at), Angled, false, true, false);
96    at = delim + 1;
97    delim = strchr(at, llvm::sys::PathSeparator);
98  }
99  if (*at == 0)
100    AddPath(".", Angled, false, true, false);
101  else
102    AddPath(at, Angled, false, true, false);
103}
104
105void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(const std::string &Base,
106                                                   const char *Dir32,
107                                                   const char *Dir64,
108                                                   const llvm::Triple &triple) {
109  llvm::Triple::ArchType arch = triple.getArch();
110  bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64;
111
112  AddPath(Base, System, true, false, false);
113  if (is64bit)
114    AddPath(Base + "/" + Dir64, System, true, false, false);
115  else
116    AddPath(Base + "/" + Dir32, System, true, false, false);
117  AddPath(Base + "/backward", System, true, false, false);
118}
119
120void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(const std::string &Base,
121                                                     const char *Arch,
122                                                     const char *Version) {
123  std::string localBase = Base + "/" + Arch + "/" + Version + "/include";
124  AddPath(localBase, System, true, false, false);
125  AddPath(localBase + "/c++", System, true, false, false);
126  AddPath(localBase + "/c++/backward", System, true, false, false);
127}
128
129  // FIXME: This probably should goto to some platform utils place.
130#ifdef _MSC_VER
131  // Read registry string.
132bool getSystemRegistryString(const char *keyPath, const char *valueName,
133                       char *value, size_t maxLength) {
134  HKEY hRootKey = NULL;
135  HKEY hKey = NULL;
136  const char* subKey = NULL;
137  DWORD valueType;
138  DWORD valueSize = maxLength - 1;
139  bool returnValue = false;
140  if (strncmp(keyPath, "HKEY_CLASSES_ROOT\\", 18) == 0) {
141    hRootKey = HKEY_CLASSES_ROOT;
142    subKey = keyPath + 18;
143  }
144  else if (strncmp(keyPath, "HKEY_USERS\\", 11) == 0) {
145    hRootKey = HKEY_USERS;
146    subKey = keyPath + 11;
147  }
148  else if (strncmp(keyPath, "HKEY_LOCAL_MACHINE\\", 19) == 0) {
149    hRootKey = HKEY_LOCAL_MACHINE;
150    subKey = keyPath + 19;
151  }
152  else if (strncmp(keyPath, "HKEY_CURRENT_USER\\", 18) == 0) {
153    hRootKey = HKEY_CURRENT_USER;
154    subKey = keyPath + 18;
155  }
156  else
157    return(false);
158  long lResult = RegOpenKeyEx(hRootKey, subKey, 0, KEY_READ, &hKey);
159  if (lResult == ERROR_SUCCESS) {
160    lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType,
161      (LPBYTE)value, &valueSize);
162    if (lResult == ERROR_SUCCESS)
163      returnValue = true;
164    RegCloseKey(hKey);
165  }
166  return(returnValue);
167}
168#else // _MSC_VER
169  // Read registry string.
170bool getSystemRegistryString(const char *, const char *, char *, size_t) {
171  return(false);
172}
173#endif // _MSC_VER
174
175  // Get Visual Studio installation directory.
176bool getVisualStudioDir(std::string &path) {
177  // Try the Windows registry first.
178  char vs80IDEInstallDir[256];
179  char vs90IDEInstallDir[256];
180  const char* vsIDEInstallDir = NULL;
181  bool has80 = getSystemRegistryString(
182    "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0",
183    "InstallDir", vs80IDEInstallDir, sizeof(vs80IDEInstallDir) - 1);
184  bool has90 = getSystemRegistryString(
185    "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\9.0",
186    "InstallDir", vs90IDEInstallDir, sizeof(vs90IDEInstallDir) - 1);
187    // If we have both vc80 and vc90, pick version we were compiled with.
188  if (has80 && has90) {
189    #ifdef _MSC_VER
190      #if (_MSC_VER >= 1500)  // VC90
191          vsIDEInstallDir = vs90IDEInstallDir;
192      #elif (_MSC_VER == 1400) // VC80
193          vsIDEInstallDir = vs80IDEInstallDir;
194      #else
195          vsIDEInstallDir = vs90IDEInstallDir;
196      #endif
197    #else
198      vsIDEInstallDir = vs90IDEInstallDir;
199    #endif
200  }
201  else if (has90)
202    vsIDEInstallDir = vs90IDEInstallDir;
203  else if (has80)
204    vsIDEInstallDir = vs80IDEInstallDir;
205  if (vsIDEInstallDir && *vsIDEInstallDir) {
206    char *p = (char*)strstr(vsIDEInstallDir, "\\Common7\\IDE");
207    if (p)
208      *p = '\0';
209    path = vsIDEInstallDir;
210    return(true);
211  }
212  else {
213    // Try the environment.
214    const char* vs90comntools = getenv("VS90COMNTOOLS");
215    const char* vs80comntools = getenv("VS80COMNTOOLS");
216    const char* vscomntools = NULL;
217      // If we have both vc80 and vc90, pick version we were compiled with.
218    if (vs90comntools && vs80comntools) {
219      #if (_MSC_VER >= 1500)  // VC90
220          vscomntools = vs90comntools;
221      #elif (_MSC_VER == 1400) // VC80
222          vscomntools = vs80comntools;
223      #else
224          vscomntools = vs90comntools;
225      #endif
226    }
227    else if (vs90comntools)
228      vscomntools = vs90comntools;
229    else if (vs80comntools)
230      vscomntools = vs80comntools;
231    if (vscomntools && *vscomntools) {
232      char *p = (char*)strstr(vscomntools, "\\Common7\\Tools");
233      if (p)
234        *p = '\0';
235      path = vscomntools;
236      return(true);
237    }
238    else
239      return(false);
240  }
241  return(false);
242}
243
244void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple) {
245  // FIXME: temporary hack: hard-coded paths.
246  llvm::Triple::OSType os = triple.getOS();
247  switch (os) {
248  case llvm::Triple::Win32:
249    {
250      std::string VSDir;
251      if (getVisualStudioDir(VSDir)) {
252        AddPath(VSDir + "\\VC\\include", System, false, false, false);
253        AddPath(VSDir + "\\VC\\PlatformSDK\\Include",
254          System, false, false, false);
255      }
256      else {
257          // Default install paths.
258        AddPath("C:/Program Files/Microsoft Visual Studio 9.0/VC/include",
259          System, false, false, false);
260        AddPath(
261        "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include",
262          System, false, false, false);
263        AddPath("C:/Program Files/Microsoft Visual Studio 8/VC/include",
264          System, false, false, false);
265        AddPath(
266        "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include",
267          System, false, false, false);
268          // For some clang developers.
269        AddPath("G:/Program Files/Microsoft Visual Studio 9.0/VC/include",
270          System, false, false, false);
271        AddPath(
272        "G:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include",
273          System, false, false, false);
274      }
275    }
276    break;
277  case llvm::Triple::MinGW64:
278  case llvm::Triple::MinGW32:
279    AddPath("c:/mingw/include", System, true, false, false);
280    break;
281  default:
282    break;
283  }
284
285  AddPath("/usr/local/include", System, false, false, false);
286  AddPath("/usr/include", System, false, false, false);
287}
288
289void InitHeaderSearch::AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) {
290  llvm::Triple::OSType os = triple.getOS();
291  // FIXME: temporary hack: hard-coded paths.
292  switch (os) {
293  case llvm::Triple::Cygwin:
294    AddPath("/lib/gcc/i686-pc-cygwin/3.4.4/include",
295        System, true, false, false);
296    AddPath("/lib/gcc/i686-pc-cygwin/3.4.4/include/c++",
297        System, true, false, false);
298    break;
299  case llvm::Triple::MinGW64:
300    // Try gcc 4.4.0
301    AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw64", "4.4.0");
302    // Try gcc 4.3.0
303    AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw64", "4.3.0");
304    // Fall through.
305  case llvm::Triple::MinGW32:
306    // Try gcc 4.4.0
307    AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0");
308    // Try gcc 4.3.0
309    AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0");
310    break;
311  case llvm::Triple::Darwin:
312    AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
313        "i686-apple-darwin10",
314        "i686-apple-darwin10/x86_64",
315        triple);
316    AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
317        "i686-apple-darwin8",
318        "i686-apple-darwin8",
319        triple);
320    break;
321  case llvm::Triple::Linux:
322    // Ubuntu 7.10 - Gutsy Gibbon
323    AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.3",
324        "i486-linux-gnu",
325        "i486-linux-gnu",
326        triple);
327    // Ubuntu 9.04
328    AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.3",
329        "x86_64-linux-gnu/32",
330        "x86_64-linux-gnu",
331        triple);
332    // Ubuntu 9.10
333    AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.1",
334        "x86_64-linux-gnu/32",
335        "x86_64-linux-gnu",
336        triple);
337    // Fedora 8
338    AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.2",
339        "i386-redhat-linux",
340        "i386-redhat-linux",
341        triple);
342    // Fedora 9
343    AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.0",
344        "i386-redhat-linux",
345        "i386-redhat-linux",
346        triple);
347    // Fedora 10
348    AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.2",
349        "i386-redhat-linux",
350        "i386-redhat-linux",
351        triple);
352    // openSUSE 11.1 32 bit
353    AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3",
354        "i586-suse-linux",
355        "i586-suse-linux",
356        triple);
357    // openSUSE 11.1 64 bit
358    AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3",
359        "x86_64-suse-linux/32",
360        "x86_64-suse-linux",
361        triple);
362    // openSUSE 11.2
363    AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4",
364        "i586-suse-linux",
365        "i586-suse-linux",
366        triple);
367    AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4",
368        "x86_64-suse-linux",
369        "x86_64-suse-linux",
370        triple);
371    // Arch Linux 2008-06-24
372    AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1",
373        "i686-pc-linux-gnu",
374        "i686-pc-linux-gnu",
375        triple);
376    AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1",
377        "x86_64-unknown-linux-gnu",
378        "x86_64-unknown-linux-gnu",
379        triple);
380    // Gentoo x86 2009.1 stable
381    AddGnuCPlusPlusIncludePaths(
382      "/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4",
383      "i686-pc-linux-gnu",
384      "i686-pc-linux-gnu",
385      triple);
386    // Gentoo x86 2009.0 stable
387    AddGnuCPlusPlusIncludePaths(
388      "/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4",
389      "i686-pc-linux-gnu",
390      "i686-pc-linux-gnu",
391      triple);
392    // Gentoo x86 2008.0 stable
393    AddGnuCPlusPlusIncludePaths(
394      "/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4",
395      "i686-pc-linux-gnu",
396      "i686-pc-linux-gnu",
397      triple);
398    // Ubuntu 8.10
399    AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3",
400        "i486-pc-linux-gnu",
401        "i486-pc-linux-gnu",
402        triple);
403    // Ubuntu 9.04
404    AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3",
405        "i486-linux-gnu",
406        "i486-linux-gnu",
407        triple);
408    // Gentoo amd64 stable
409    AddGnuCPlusPlusIncludePaths(
410        "/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4",
411        "i686-pc-linux-gnu",
412        "i686-pc-linux-gnu",
413        triple);
414    // Exherbo (2009-10-26)
415    AddGnuCPlusPlusIncludePaths(
416        "/usr/include/c++/4.4.2",
417        "x86_64-pc-linux-gnu/32",
418        "x86_64-pc-linux-gnu",
419        triple);
420    AddGnuCPlusPlusIncludePaths(
421        "/usr/include/c++/4.4.2",
422        "i686-pc-linux-gnu",
423        "i686-pc-linux-gnu",
424        triple);
425    break;
426  case llvm::Triple::FreeBSD:
427    // DragonFly
428    AddPath("/usr/include/c++/4.1", System, true, false, false);
429    // FreeBSD
430    AddPath("/usr/include/c++/4.2", System, true, false, false);
431    break;
432  case llvm::Triple::Solaris:
433    // Solaris - Fall though..
434  case llvm::Triple::AuroraUX:
435    // AuroraUX
436    AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4",
437                                "i386-pc-solaris2.11",
438                                "i386-pc-solaris2.11",
439                                triple);
440    break;
441  default:
442    break;
443  }
444}
445
446void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang,
447                                                    const llvm::Triple &triple) {
448  AddDefaultCIncludePaths(triple);
449
450  // Add the default framework include paths on Darwin.
451  if (triple.getOS() == llvm::Triple::Darwin) {
452    AddPath("/System/Library/Frameworks", System, true, false, true);
453    AddPath("/Library/Frameworks", System, true, false, true);
454  }
455
456  if (Lang.CPlusPlus)
457    AddDefaultCPlusPlusIncludePaths(triple);
458}
459
460/// RemoveDuplicates - If there are duplicate directory entries in the specified
461/// search list, remove the later (dead) ones.
462static void RemoveDuplicates(std::vector<DirectoryLookup> &SearchList,
463                             bool Verbose) {
464  llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs;
465  llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs;
466  llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps;
467  for (unsigned i = 0; i != SearchList.size(); ++i) {
468    unsigned DirToRemove = i;
469
470    const DirectoryLookup &CurEntry = SearchList[i];
471
472    if (CurEntry.isNormalDir()) {
473      // If this isn't the first time we've seen this dir, remove it.
474      if (SeenDirs.insert(CurEntry.getDir()))
475        continue;
476    } else if (CurEntry.isFramework()) {
477      // If this isn't the first time we've seen this framework dir, remove it.
478      if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir()))
479        continue;
480    } else {
481      assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
482      // If this isn't the first time we've seen this headermap, remove it.
483      if (SeenHeaderMaps.insert(CurEntry.getHeaderMap()))
484        continue;
485    }
486
487    // If we have a normal #include dir/framework/headermap that is shadowed
488    // later in the chain by a system include location, we actually want to
489    // ignore the user's request and drop the user dir... keeping the system
490    // dir.  This is weird, but required to emulate GCC's search path correctly.
491    //
492    // Since dupes of system dirs are rare, just rescan to find the original
493    // that we're nuking instead of using a DenseMap.
494    if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) {
495      // Find the dir that this is the same of.
496      unsigned FirstDir;
497      for (FirstDir = 0; ; ++FirstDir) {
498        assert(FirstDir != i && "Didn't find dupe?");
499
500        const DirectoryLookup &SearchEntry = SearchList[FirstDir];
501
502        // If these are different lookup types, then they can't be the dupe.
503        if (SearchEntry.getLookupType() != CurEntry.getLookupType())
504          continue;
505
506        bool isSame;
507        if (CurEntry.isNormalDir())
508          isSame = SearchEntry.getDir() == CurEntry.getDir();
509        else if (CurEntry.isFramework())
510          isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir();
511        else {
512          assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
513          isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap();
514        }
515
516        if (isSame)
517          break;
518      }
519
520      // If the first dir in the search path is a non-system dir, zap it
521      // instead of the system one.
522      if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User)
523        DirToRemove = FirstDir;
524    }
525
526    if (Verbose) {
527      fprintf(stderr, "ignoring duplicate directory \"%s\"\n",
528              CurEntry.getName());
529      if (DirToRemove != i)
530        fprintf(stderr, "  as it is a non-system directory that duplicates"
531                " a system directory\n");
532    }
533
534    // This is reached if the current entry is a duplicate.  Remove the
535    // DirToRemove (usually the current dir).
536    SearchList.erase(SearchList.begin()+DirToRemove);
537    --i;
538  }
539}
540
541
542void InitHeaderSearch::Realize() {
543  // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList.
544  std::vector<DirectoryLookup> SearchList;
545  SearchList = IncludeGroup[Angled];
546  SearchList.insert(SearchList.end(), IncludeGroup[System].begin(),
547                    IncludeGroup[System].end());
548  SearchList.insert(SearchList.end(), IncludeGroup[After].begin(),
549                    IncludeGroup[After].end());
550  RemoveDuplicates(SearchList, Verbose);
551  RemoveDuplicates(IncludeGroup[Quoted], Verbose);
552
553  // Prepend QUOTED list on the search list.
554  SearchList.insert(SearchList.begin(), IncludeGroup[Quoted].begin(),
555                    IncludeGroup[Quoted].end());
556
557
558  bool DontSearchCurDir = false;  // TODO: set to true if -I- is set?
559  Headers.SetSearchPaths(SearchList, IncludeGroup[Quoted].size(),
560                         DontSearchCurDir);
561
562  // If verbose, print the list of directories that will be searched.
563  if (Verbose) {
564    fprintf(stderr, "#include \"...\" search starts here:\n");
565    unsigned QuotedIdx = IncludeGroup[Quoted].size();
566    for (unsigned i = 0, e = SearchList.size(); i != e; ++i) {
567      if (i == QuotedIdx)
568        fprintf(stderr, "#include <...> search starts here:\n");
569      const char *Name = SearchList[i].getName();
570      const char *Suffix;
571      if (SearchList[i].isNormalDir())
572        Suffix = "";
573      else if (SearchList[i].isFramework())
574        Suffix = " (framework directory)";
575      else {
576        assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup");
577        Suffix = " (headermap)";
578      }
579      fprintf(stderr, " %s%s\n", Name, Suffix);
580    }
581    fprintf(stderr, "End of search list.\n");
582  }
583}
584
585void clang::ApplyHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
586                                     HeaderSearch &HS, const LangOptions &Lang,
587                                     const llvm::Triple &Triple) {
588  InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot);
589
590  // Add the user defined entries.
591  for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) {
592    const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i];
593    Init.AddPath(E.Path, E.Group, E.IsCXXAware, E.IsUserSupplied, E.IsFramework,
594                 E.IgnoreSysRoot);
595  }
596
597  // Add entries from CPATH and friends.
598  Init.AddDelimitedPaths(HSOpts.EnvIncPath.c_str());
599  Init.AddDelimitedPaths(HSOpts.LangEnvIncPath.c_str());
600
601  if (!HSOpts.BuiltinIncludePath.empty()) {
602    // Ignore the sys root, we *always* look for clang headers relative to
603    // supplied path.
604    Init.AddPath(HSOpts.BuiltinIncludePath, InitHeaderSearch::System,
605                 false, false, false, /*IgnoreSysRoot=*/ true);
606  }
607
608  if (!HSOpts.UseStandardIncludes)
609    Init.AddDefaultSystemIncludePaths(Lang, Triple);
610
611  Init.Realize();
612}
613