• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- CanonicalIncludes.h - remap #include headers-------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "CanonicalIncludes.h"
10 #include "Headers.h"
11 #include "clang/Driver/Types.h"
12 #include "llvm/ADT/StringRef.h"
13 #include "llvm/Support/Path.h"
14 #include <algorithm>
15 
16 namespace clang {
17 namespace clangd {
18 namespace {
19 const char IWYUPragma[] = "// IWYU pragma: private, include ";
20 } // namespace
21 
addMapping(llvm::StringRef Path,llvm::StringRef CanonicalPath)22 void CanonicalIncludes::addMapping(llvm::StringRef Path,
23                                    llvm::StringRef CanonicalPath) {
24   FullPathMapping[Path] = std::string(CanonicalPath);
25 }
26 
27 /// The maximum number of path components in a key from StdSuffixHeaderMapping.
28 /// Used to minimize the number of lookups in suffix path mappings.
29 constexpr int MaxSuffixComponents = 3;
30 
31 llvm::StringRef
mapHeader(llvm::StringRef Header,llvm::StringRef QualifiedName) const32 CanonicalIncludes::mapHeader(llvm::StringRef Header,
33                              llvm::StringRef QualifiedName) const {
34   assert(!Header.empty());
35   if (StdSymbolMapping) {
36     auto SE = StdSymbolMapping->find(QualifiedName);
37     if (SE != StdSymbolMapping->end())
38       return SE->second;
39   }
40 
41   auto MapIt = FullPathMapping.find(Header);
42   if (MapIt != FullPathMapping.end())
43     return MapIt->second;
44 
45   if (!StdSuffixHeaderMapping)
46     return Header;
47 
48   int Components = 1;
49 
50   // FIXME: check that this works on Windows and add tests.
51   for (auto It = llvm::sys::path::rbegin(Header),
52             End = llvm::sys::path::rend(Header);
53        It != End && Components <= MaxSuffixComponents; ++It, ++Components) {
54     auto SubPath = Header.substr(It->data() - Header.begin());
55     auto MappingIt = StdSuffixHeaderMapping->find(SubPath);
56     if (MappingIt != StdSuffixHeaderMapping->end())
57       return MappingIt->second;
58   }
59   return Header;
60 }
61 
62 std::unique_ptr<CommentHandler>
collectIWYUHeaderMaps(CanonicalIncludes * Includes)63 collectIWYUHeaderMaps(CanonicalIncludes *Includes) {
64   class PragmaCommentHandler : public clang::CommentHandler {
65   public:
66     PragmaCommentHandler(CanonicalIncludes *Includes) : Includes(Includes) {}
67 
68     bool HandleComment(Preprocessor &PP, SourceRange Range) override {
69       llvm::StringRef Text =
70           Lexer::getSourceText(CharSourceRange::getCharRange(Range),
71                                PP.getSourceManager(), PP.getLangOpts());
72       if (!Text.consume_front(IWYUPragma))
73         return false;
74       // FIXME(ioeric): resolve the header and store actual file path. For now,
75       // we simply assume the written header is suitable to be #included.
76       Includes->addMapping(PP.getSourceManager().getFilename(Range.getBegin()),
77                            isLiteralInclude(Text) ? Text.str()
78                                                   : ("\"" + Text + "\"").str());
79       return false;
80     }
81 
82   private:
83     CanonicalIncludes *const Includes;
84   };
85   return std::make_unique<PragmaCommentHandler>(Includes);
86 }
87 
addSystemHeadersMapping(const LangOptions & Language)88 void CanonicalIncludes::addSystemHeadersMapping(const LangOptions &Language) {
89   if (Language.CPlusPlus) {
90     static const auto *Symbols = new llvm::StringMap<llvm::StringRef>({
91 #define SYMBOL(Name, NameSpace, Header) {#NameSpace #Name, #Header},
92 #include "StdSymbolMap.inc"
93         // There are two std::move()s, this is by far the most common.
94         SYMBOL(move, std::, <utility>)
95 #undef SYMBOL
96     });
97     StdSymbolMapping = Symbols;
98   } else if (Language.C11) {
99     static const auto *CSymbols = new llvm::StringMap<llvm::StringRef>({
100 #define SYMBOL(Name, NameSpace, Header) {#Name, #Header},
101 #include "CSymbolMap.inc"
102 #undef SYMBOL
103     });
104     StdSymbolMapping = CSymbols;
105   }
106 
107   // FIXME: remove the std header mapping once we support ambiguous symbols, now
108   // it serves as a fallback to disambiguate:
109   //   - symbols with multiple headers (e.g. std::move)
110   static const auto *SystemHeaderMap = new llvm::StringMap<llvm::StringRef>({
111       {"include/__stddef_max_align_t.h", "<cstddef>"},
112       {"include/__wmmintrin_aes.h", "<wmmintrin.h>"},
113       {"include/__wmmintrin_pclmul.h", "<wmmintrin.h>"},
114       {"include/adxintrin.h", "<immintrin.h>"},
115       {"include/ammintrin.h", "<ammintrin.h>"},
116       {"include/avx2intrin.h", "<immintrin.h>"},
117       {"include/avx512bwintrin.h", "<immintrin.h>"},
118       {"include/avx512cdintrin.h", "<immintrin.h>"},
119       {"include/avx512dqintrin.h", "<immintrin.h>"},
120       {"include/avx512erintrin.h", "<immintrin.h>"},
121       {"include/avx512fintrin.h", "<immintrin.h>"},
122       {"include/avx512ifmaintrin.h", "<immintrin.h>"},
123       {"include/avx512ifmavlintrin.h", "<immintrin.h>"},
124       {"include/avx512pfintrin.h", "<immintrin.h>"},
125       {"include/avx512vbmiintrin.h", "<immintrin.h>"},
126       {"include/avx512vbmivlintrin.h", "<immintrin.h>"},
127       {"include/avx512vlbwintrin.h", "<immintrin.h>"},
128       {"include/avx512vlcdintrin.h", "<immintrin.h>"},
129       {"include/avx512vldqintrin.h", "<immintrin.h>"},
130       {"include/avx512vlintrin.h", "<immintrin.h>"},
131       {"include/avxintrin.h", "<immintrin.h>"},
132       {"include/bmi2intrin.h", "<x86intrin.h>"},
133       {"include/bmiintrin.h", "<x86intrin.h>"},
134       {"include/emmintrin.h", "<emmintrin.h>"},
135       {"include/f16cintrin.h", "<emmintrin.h>"},
136       {"include/float.h", "<cfloat>"},
137       {"include/fma4intrin.h", "<x86intrin.h>"},
138       {"include/fmaintrin.h", "<immintrin.h>"},
139       {"include/fxsrintrin.h", "<immintrin.h>"},
140       {"include/ia32intrin.h", "<x86intrin.h>"},
141       {"include/immintrin.h", "<immintrin.h>"},
142       {"include/inttypes.h", "<cinttypes>"},
143       {"include/limits.h", "<climits>"},
144       {"include/lzcntintrin.h", "<x86intrin.h>"},
145       {"include/mm3dnow.h", "<mm3dnow.h>"},
146       {"include/mm_malloc.h", "<mm_malloc.h>"},
147       {"include/mmintrin.h", "<mmintrin>"},
148       {"include/mwaitxintrin.h", "<x86intrin.h>"},
149       {"include/pkuintrin.h", "<immintrin.h>"},
150       {"include/pmmintrin.h", "<pmmintrin.h>"},
151       {"include/popcntintrin.h", "<popcntintrin.h>"},
152       {"include/prfchwintrin.h", "<x86intrin.h>"},
153       {"include/rdseedintrin.h", "<x86intrin.h>"},
154       {"include/rtmintrin.h", "<immintrin.h>"},
155       {"include/shaintrin.h", "<immintrin.h>"},
156       {"include/smmintrin.h", "<smmintrin.h>"},
157       {"include/stdalign.h", "<cstdalign>"},
158       {"include/stdarg.h", "<cstdarg>"},
159       {"include/stdbool.h", "<cstdbool>"},
160       {"include/stddef.h", "<cstddef>"},
161       {"include/stdint.h", "<cstdint>"},
162       {"include/tbmintrin.h", "<x86intrin.h>"},
163       {"include/tmmintrin.h", "<tmmintrin.h>"},
164       {"include/wmmintrin.h", "<wmmintrin.h>"},
165       {"include/x86intrin.h", "<x86intrin.h>"},
166       {"include/xmmintrin.h", "<xmmintrin.h>"},
167       {"include/xopintrin.h", "<x86intrin.h>"},
168       {"include/xsavecintrin.h", "<immintrin.h>"},
169       {"include/xsaveintrin.h", "<immintrin.h>"},
170       {"include/xsaveoptintrin.h", "<immintrin.h>"},
171       {"include/xsavesintrin.h", "<immintrin.h>"},
172       {"include/xtestintrin.h", "<immintrin.h>"},
173       {"include/_G_config.h", "<cstdio>"},
174       {"include/assert.h", "<cassert>"},
175       {"algorithm", "<algorithm>"},
176       {"valarray", "<valarray>"},
177       {"array", "<array>"},
178       {"atomic", "<atomic>"},
179       {"backward/auto_ptr.h", "<memory>"},
180       {"backward/binders.h", "<string>"},
181       {"bits/algorithmfwd.h", "<algorithm>"},
182       {"bits/alloc_traits.h", "<memory>"},
183       {"bits/allocated_ptr.h", "<memory>"},
184       {"bits/allocator.h", "<allocator>"},
185       {"bits/atomic_base.h", "<atomic>"},
186       {"bits/atomic_lockfree_defines.h", "<exception>"},
187       {"bits/atomic_futex.h", "<atomic>"},
188       {"bits/basic_ios.h", "<ios>"},
189       {"bits/basic_ios.tcc", "<ios>"},
190       {"bits/basic_string.h", "<string>"},
191       {"bits/basic_string.tcc", "<string>"},
192       {"bits/char_traits.h", "<string>"},
193       {"bits/codecvt.h", "<locale>"},
194       {"bits/concept_check.h", "<numeric>"},
195       {"bits/cpp_type_traits.h", "<cmath>"},
196       {"bits/cxxabi_forced.h", "<cxxabi.h>"},
197       {"bits/deque.tcc", "<deque>"},
198       {"bits/exception.h", "<exception>"},
199       {"bits/exception_defines.h", "<exception>"},
200       {"bits/exception_ptr.h", "<exception>"},
201       {"bits/forward_list.h", "<forward_list>"},
202       {"bits/forward_list.tcc", "<forward_list>"},
203       {"bits/fstream.tcc", "<fstream>"},
204       {"bits/functexcept.h", "<list>"},
205       {"bits/functional_hash.h", "<functional>"},
206       {"bits/gslice.h", "<valarray>"},
207       {"bits/gslice_array.h", "<valarray>"},
208       {"bits/hash_bytes.h", "<typeinfo>"},
209       {"bits/hashtable.h", "<unordered_set>"},
210       {"bits/hashtable_policy.h", "<unordered_set>"},
211       {"bits/indirect_array.h", "<valarray>"},
212       {"bits/invoke.h", "<functional>"},
213       {"bits/ios_base.h", "<ios>"},
214       {"bits/istream.tcc", "<istream>"},
215       {"bits/list.tcc", "<list>"},
216       {"bits/locale_classes.h", "<locale>"},
217       {"bits/locale_classes.tcc", "<locale>"},
218       {"bits/locale_conv.h", "<locale>"},
219       {"bits/locale_facets.h", "<locale>"},
220       {"bits/locale_facets.tcc", "<locale>"},
221       {"bits/locale_facets_nonio.h", "<locale>"},
222       {"bits/locale_facets_nonio.tcc", "<locale>"},
223       {"bits/localefwd.h", "<locale>"},
224       {"bits/mask_array.h", "<valarray>"},
225       {"bits/memoryfwd.h", "<memory>"},
226       {"bits/move.h", "<utility>"},
227       {"bits/nested_exception.h", "<exception>"},
228       {"bits/ostream.tcc", "<ostream>"},
229       {"bits/ostream_insert.h", "<ostream>"},
230       {"bits/parse_numbers.h", "<chrono>"},
231       {"bits/postypes.h", "<ios>"},
232       {"bits/predefined_ops.h", "<algorithm>"},
233       {"bits/ptr_traits.h", "<memory>"},
234       {"bits/quoted_string.h", "<iomanip>"},
235       {"bits/random.h", "<random>"},
236       {"bits/random.tcc", "<random>"},
237       {"bits/range_access.h", "<iterator>"},
238       {"bits/refwrap.h", "<functional>"},
239       {"bits/regex.h", "<regex>"},
240       {"bits/regex_automaton.h", "<regex>"},
241       {"bits/regex_compiler.h", "<regex>"},
242       {"bits/regex_constants.h", "<regex>"},
243       {"bits/regex_cursor.h", "<regex>"},
244       {"bits/regex_error.h", "<regex>"},
245       {"bits/regex_executor.h", "<regex>"},
246       {"bits/regex_grep_matcher.h", "<regex>"},
247       {"bits/regex_grep_matcher.tcc", "<regex>"},
248       {"bits/regex_nfa.h", "<regex>"},
249       {"bits/regex_scanner.h", "<regex>"},
250       {"bits/shared_ptr.h", "<memory>"},
251       {"bits/shared_ptr_base.h", "<memory>"},
252       {"bits/shared_ptr_atomic.h", "<atomic>"},
253       {"bits/slice_array.h", "<valarray>"},
254       {"bits/sstream.tcc", "<sstream>"},
255       {"bits/std_abs.h", "<cmath>"},
256       {"bits/std_function.h", "<functional>"},
257       {"bits/std_mutex.h", "<mutex>"},
258       {"bits/stl_algo.h", "<algorithm>"},
259       {"bits/stl_algobase.h", "<algorithm>"},
260       {"bits/stl_bvector.h", "<vector>"},
261       {"bits/stl_construct.h", "<deque>"},
262       {"bits/stl_deque.h", "<deque>"},
263       {"bits/stl_function.h", "<functional>"},
264       {"bits/stl_heap.h", "<heap>"},
265       {"bits/stl_iterator.h", "<iterator>"},
266       {"bits/stl_iterator_base_funcs.h", "<iterator>"},
267       {"bits/stl_iterator_base_types.h", "<iterator>"},
268       {"bits/stl_list.h", "<list>"},
269       {"bits/stl_map.h", "<map>"},
270       {"bits/stl_multimap.h", "<map>"},
271       {"bits/stl_multiset.h", "<set>"},
272       {"bits/stl_numeric.h", "<numeric>"},
273       {"bits/stl_pair.h", "<utility>"},
274       {"bits/stl_queue.h", "<queue>"},
275       {"bits/stl_raw_storage_iter.h", "<memory>"},
276       {"bits/stl_relops.h", "<utility>"},
277       {"bits/stl_set.h", "<set>"},
278       {"bits/stl_stack.h", "<stack>"},
279       {"bits/stl_tempbuf.h", "<memory>"},
280       {"bits/stl_tree.h", "<map>"},
281       {"bits/stl_uninitialized.h", "<memory>"},
282       {"bits/stl_vector.h", "<vector>"},
283       {"bits/stream_iterator.h", "<iterator>"},
284       {"bits/streambuf.tcc", "<streambuf>"},
285       {"bits/streambuf_iterator.h", "<iterator>"},
286       {"bits/stringfwd.h", "<string>"},
287       {"bits/uniform_int_dist.h", "<random>"},
288       {"bits/unique_ptr.h", "<memory>"},
289       {"bits/unordered_map.h", "<unordered_map>"},
290       {"bits/unordered_set.h", "<unordered_set>"},
291       {"bits/uses_allocator.h", "<memory>"},
292       {"bits/valarray_after.h", "<valarray>"},
293       {"bits/valarray_array.h", "<valarray>"},
294       {"bits/valarray_array.tcc", "<valarray>"},
295       {"bits/valarray_before.h", "<valarray>"},
296       {"bits/vector.tcc", "<vector>"},
297       {"bitset", "<bitset>"},
298       {"ccomplex", "<ccomplex>"},
299       {"cctype", "<cctype>"},
300       {"cerrno", "<cerrno>"},
301       {"cfenv", "<cfenv>"},
302       {"cfloat", "<cfloat>"},
303       {"chrono", "<chrono>"},
304       {"cinttypes", "<cinttypes>"},
305       {"climits", "<climits>"},
306       {"clocale", "<clocale>"},
307       {"cmath", "<cmath>"},
308       {"complex", "<complex>"},
309       {"complex.h", "<complex.h>"},
310       {"condition_variable", "<condition_variable>"},
311       {"csetjmp", "<csetjmp>"},
312       {"csignal", "<csignal>"},
313       {"cstdalign", "<cstdalign>"},
314       {"cstdarg", "<cstdarg>"},
315       {"cstdbool", "<cstdbool>"},
316       {"cstdint", "<cstdint>"},
317       {"cstdio", "<cstdio>"},
318       {"cstdlib", "<cstdlib>"},
319       {"cstring", "<cstring>"},
320       {"ctgmath", "<ctgmath>"},
321       {"ctime", "<ctime>"},
322       {"cwchar", "<cwchar>"},
323       {"cwctype", "<cwctype>"},
324       {"cxxabi.h", "<cxxabi.h>"},
325       {"debug/debug.h", "<numeric>"},
326       {"debug/map.h", "<map>"},
327       {"debug/multimap.h", "<multimap>"},
328       {"debug/multiset.h", "<multiset>"},
329       {"debug/set.h", "<set>"},
330       {"deque", "<deque>"},
331       {"exception", "<exception>"},
332       {"ext/alloc_traits.h", "<deque>"},
333       {"ext/atomicity.h", "<memory>"},
334       {"ext/concurrence.h", "<memory>"},
335       {"ext/new_allocator.h", "<string>"},
336       {"ext/numeric_traits.h", "<list>"},
337       {"ext/string_conversions.h", "<string>"},
338       {"ext/type_traits.h", "<cmath>"},
339       {"fenv.h", "<fenv.h>"},
340       {"forward_list", "<forward_list>"},
341       {"fstream", "<fstream>"},
342       {"functional", "<functional>"},
343       {"future", "<future>"},
344       {"initializer_list", "<initializer_list>"},
345       {"iomanip", "<iomanip>"},
346       {"ios", "<ios>"},
347       {"iosfwd", "<iosfwd>"},
348       {"iostream", "<iostream>"},
349       {"istream", "<istream>"},
350       {"iterator", "<iterator>"},
351       {"limits", "<limits>"},
352       {"list", "<list>"},
353       {"locale", "<locale>"},
354       {"map", "<map>"},
355       {"memory", "<memory>"},
356       {"shared_mutex", "<shared_mutex>"},
357       {"mutex", "<mutex>"},
358       {"new", "<new>"},
359       {"numeric", "<numeric>"},
360       {"ostream", "<ostream>"},
361       {"queue", "<queue>"},
362       {"random", "<random>"},
363       {"ratio", "<ratio>"},
364       {"regex", "<regex>"},
365       {"scoped_allocator", "<scoped_allocator>"},
366       {"set", "<set>"},
367       {"sstream", "<sstream>"},
368       {"stack", "<stack>"},
369       {"stdexcept", "<stdexcept>"},
370       {"streambuf", "<streambuf>"},
371       {"string", "<string>"},
372       {"system_error", "<system_error>"},
373       {"tgmath.h", "<tgmath.h>"},
374       {"thread", "<thread>"},
375       {"tuple", "<tuple>"},
376       {"type_traits", "<type_traits>"},
377       {"typeindex", "<typeindex>"},
378       {"typeinfo", "<typeinfo>"},
379       {"unordered_map", "<unordered_map>"},
380       {"unordered_set", "<unordered_set>"},
381       {"utility", "<utility>"},
382       {"valarray", "<valarray>"},
383       {"vector", "<vector>"},
384       {"include/complex.h", "<complex.h>"},
385       {"include/ctype.h", "<cctype>"},
386       {"include/errno.h", "<cerrno>"},
387       {"include/fenv.h", "<fenv.h>"},
388       {"include/inttypes.h", "<cinttypes>"},
389       {"include/libio.h", "<cstdio>"},
390       {"include/limits.h", "<climits>"},
391       {"include/locale.h", "<clocale>"},
392       {"include/math.h", "<cmath>"},
393       {"include/setjmp.h", "<csetjmp>"},
394       {"include/signal.h", "<csignal>"},
395       {"include/stdint.h", "<cstdint>"},
396       {"include/stdio.h", "<cstdio>"},
397       {"include/stdlib.h", "<cstdlib>"},
398       {"include/string.h", "<cstring>"},
399       {"include/time.h", "<ctime>"},
400       {"include/wchar.h", "<cwchar>"},
401       {"include/wctype.h", "<cwctype>"},
402       {"bits/cmathcalls.h", "<complex.h>"},
403       {"bits/errno.h", "<cerrno>"},
404       {"bits/fenv.h", "<fenv.h>"},
405       {"bits/huge_val.h", "<cmath>"},
406       {"bits/huge_valf.h", "<cmath>"},
407       {"bits/huge_vall.h", "<cmath>"},
408       {"bits/inf.h", "<cmath>"},
409       {"bits/local_lim.h", "<climits>"},
410       {"bits/locale.h", "<clocale>"},
411       {"bits/mathcalls.h", "<math.h>"},
412       {"bits/mathdef.h", "<cmath>"},
413       {"bits/nan.h", "<cmath>"},
414       {"bits/posix1_lim.h", "<climits>"},
415       {"bits/posix2_lim.h", "<climits>"},
416       {"bits/setjmp.h", "<csetjmp>"},
417       {"bits/sigaction.h", "<csignal>"},
418       {"bits/sigcontext.h", "<csignal>"},
419       {"bits/siginfo.h", "<csignal>"},
420       {"bits/signum.h", "<csignal>"},
421       {"bits/sigset.h", "<csignal>"},
422       {"bits/sigstack.h", "<csignal>"},
423       {"bits/stdint-intn.h", "<cstdint>"},
424       {"bits/stdint-uintn.h", "<cstdint>"},
425       {"bits/stdio_lim.h", "<cstdio>"},
426       {"bits/sys_errlist.h", "<cstdio>"},
427       {"bits/time.h", "<ctime>"},
428       {"bits/timex.h", "<ctime>"},
429       {"bits/typesizes.h", "<cstdio>"},
430       {"bits/wchar.h", "<cwchar>"},
431       {"bits/wordsize.h", "<csetjmp>"},
432       {"bits/xopen_lim.h", "<climits>"},
433       {"include/xlocale.h", "<cstring>"},
434       {"bits/atomic_word.h", "<memory>"},
435       {"bits/basic_file.h", "<fstream>"},
436       {"bits/c\\+\\+allocator.h", "<string>"},
437       {"bits/c\\+\\+config.h", "<cstddef>"},
438       {"bits/c\\+\\+io.h", "<ios>"},
439       {"bits/c\\+\\+locale.h", "<locale>"},
440       {"bits/cpu_defines.h", "<iosfwd>"},
441       {"bits/ctype_base.h", "<locale>"},
442       {"bits/cxxabi_tweaks.h", "<cxxabi.h>"},
443       {"bits/error_constants.h", "<system_error>"},
444       {"bits/gthr-default.h", "<memory>"},
445       {"bits/gthr.h", "<memory>"},
446       {"bits/opt_random.h", "<random>"},
447       {"bits/os_defines.h", "<iosfwd>"},
448       // GNU C headers
449       {"include/aio.h", "<aio.h>"},
450       {"include/aliases.h", "<aliases.h>"},
451       {"include/alloca.h", "<alloca.h>"},
452       {"include/ar.h", "<ar.h>"},
453       {"include/argp.h", "<argp.h>"},
454       {"include/argz.h", "<argz.h>"},
455       {"include/arpa/nameser.h", "<resolv.h>"},
456       {"include/arpa/nameser_compat.h", "<resolv.h>"},
457       {"include/byteswap.h", "<byteswap.h>"},
458       {"include/cpio.h", "<cpio.h>"},
459       {"include/crypt.h", "<crypt.h>"},
460       {"include/dirent.h", "<dirent.h>"},
461       {"include/dlfcn.h", "<dlfcn.h>"},
462       {"include/elf.h", "<elf.h>"},
463       {"include/endian.h", "<endian.h>"},
464       {"include/envz.h", "<envz.h>"},
465       {"include/err.h", "<err.h>"},
466       {"include/error.h", "<error.h>"},
467       {"include/execinfo.h", "<execinfo.h>"},
468       {"include/fcntl.h", "<fcntl.h>"},
469       {"include/features.h", "<features.h>"},
470       {"include/fenv.h", "<fenv.h>"},
471       {"include/fmtmsg.h", "<fmtmsg.h>"},
472       {"include/fnmatch.h", "<fnmatch.h>"},
473       {"include/fstab.h", "<fstab.h>"},
474       {"include/fts.h", "<fts.h>"},
475       {"include/ftw.h", "<ftw.h>"},
476       {"include/gconv.h", "<gconv.h>"},
477       {"include/getopt.h", "<getopt.h>"},
478       {"include/glob.h", "<glob.h>"},
479       {"include/grp.h", "<grp.h>"},
480       {"include/gshadow.h", "<gshadow.h>"},
481       {"include/iconv.h", "<iconv.h>"},
482       {"include/ifaddrs.h", "<ifaddrs.h>"},
483       {"include/kdb.h", "<kdb.h>"},
484       {"include/langinfo.h", "<langinfo.h>"},
485       {"include/libgen.h", "<libgen.h>"},
486       {"include/libintl.h", "<libintl.h>"},
487       {"include/link.h", "<link.h>"},
488       {"include/malloc.h", "<malloc.h>"},
489       {"include/mcheck.h", "<mcheck.h>"},
490       {"include/memory.h", "<memory.h>"},
491       {"include/mntent.h", "<mntent.h>"},
492       {"include/monetary.h", "<monetary.h>"},
493       {"include/mqueue.h", "<mqueue.h>"},
494       {"include/netdb.h", "<netdb.h>"},
495       {"include/netinet/in.h", "<netinet/in.h>"},
496       {"include/nl_types.h", "<nl_types.h>"},
497       {"include/nss.h", "<nss.h>"},
498       {"include/obstack.h", "<obstack.h>"},
499       {"include/panel.h", "<panel.h>"},
500       {"include/paths.h", "<paths.h>"},
501       {"include/printf.h", "<printf.h>"},
502       {"include/profile.h", "<profile.h>"},
503       {"include/pthread.h", "<pthread.h>"},
504       {"include/pty.h", "<pty.h>"},
505       {"include/pwd.h", "<pwd.h>"},
506       {"include/re_comp.h", "<re_comp.h>"},
507       {"include/regex.h", "<regex.h>"},
508       {"include/regexp.h", "<regexp.h>"},
509       {"include/resolv.h", "<resolv.h>"},
510       {"include/rpc/netdb.h", "<netdb.h>"},
511       {"include/sched.h", "<sched.h>"},
512       {"include/search.h", "<search.h>"},
513       {"include/semaphore.h", "<semaphore.h>"},
514       {"include/sgtty.h", "<sgtty.h>"},
515       {"include/shadow.h", "<shadow.h>"},
516       {"include/spawn.h", "<spawn.h>"},
517       {"include/stab.h", "<stab.h>"},
518       {"include/stdc-predef.h", "<stdc-predef.h>"},
519       {"include/stdio_ext.h", "<stdio_ext.h>"},
520       {"include/strings.h", "<strings.h>"},
521       {"include/stropts.h", "<stropts.h>"},
522       {"include/sudo_plugin.h", "<sudo_plugin.h>"},
523       {"include/sysexits.h", "<sysexits.h>"},
524       {"include/tar.h", "<tar.h>"},
525       {"include/tcpd.h", "<tcpd.h>"},
526       {"include/term.h", "<term.h>"},
527       {"include/term_entry.h", "<term_entry.h>"},
528       {"include/termcap.h", "<termcap.h>"},
529       {"include/termios.h", "<termios.h>"},
530       {"include/thread_db.h", "<thread_db.h>"},
531       {"include/tic.h", "<tic.h>"},
532       {"include/ttyent.h", "<ttyent.h>"},
533       {"include/uchar.h", "<uchar.h>"},
534       {"include/ucontext.h", "<ucontext.h>"},
535       {"include/ulimit.h", "<ulimit.h>"},
536       {"include/unctrl.h", "<unctrl.h>"},
537       {"include/unistd.h", "<unistd.h>"},
538       {"include/utime.h", "<utime.h>"},
539       {"include/utmp.h", "<utmp.h>"},
540       {"include/utmpx.h", "<utmpx.h>"},
541       {"include/values.h", "<values.h>"},
542       {"include/wordexp.h", "<wordexp.h>"},
543       {"fpu_control.h", "<fpu_control.h>"},
544       {"ieee754.h", "<ieee754.h>"},
545       {"include/xlocale.h", "<xlocale.h>"},
546       {"gnu/lib-names.h", "<gnu/lib-names.h>"},
547       {"gnu/libc-version.h", "<gnu/libc-version.h>"},
548       {"gnu/option-groups.h", "<gnu/option-groups.h>"},
549       {"gnu/stubs-32.h", "<gnu/stubs-32.h>"},
550       {"gnu/stubs-64.h", "<gnu/stubs-64.h>"},
551       {"gnu/stubs-x32.h", "<gnu/stubs-x32.h>"},
552       {"include/rpc/auth_des.h", "<rpc/auth_des.h>"},
553       {"include/rpc/rpc_msg.h", "<rpc/rpc_msg.h>"},
554       {"include/rpc/pmap_clnt.h", "<rpc/pmap_clnt.h>"},
555       {"include/rpc/rpc.h", "<rpc/rpc.h>"},
556       {"include/rpc/types.h", "<rpc/types.h>"},
557       {"include/rpc/auth_unix.h", "<rpc/auth_unix.h>"},
558       {"include/rpc/key_prot.h", "<rpc/key_prot.h>"},
559       {"include/rpc/pmap_prot.h", "<rpc/pmap_prot.h>"},
560       {"include/rpc/auth.h", "<rpc/auth.h>"},
561       {"include/rpc/svc_auth.h", "<rpc/svc_auth.h>"},
562       {"include/rpc/xdr.h", "<rpc/xdr.h>"},
563       {"include/rpc/pmap_rmt.h", "<rpc/pmap_rmt.h>"},
564       {"include/rpc/des_crypt.h", "<rpc/des_crypt.h>"},
565       {"include/rpc/svc.h", "<rpc/svc.h>"},
566       {"include/rpc/rpc_des.h", "<rpc/rpc_des.h>"},
567       {"include/rpc/clnt.h", "<rpc/clnt.h>"},
568       {"include/scsi/scsi.h", "<scsi/scsi.h>"},
569       {"include/scsi/sg.h", "<scsi/sg.h>"},
570       {"include/scsi/scsi_ioctl.h", "<scsi/scsi_ioctl>"},
571       {"include/netrose/rose.h", "<netrose/rose.h>"},
572       {"include/nfs/nfs.h", "<nfs/nfs.h>"},
573       {"include/netatalk/at.h", "<netatalk/at.h>"},
574       {"include/netinet/ether.h", "<netinet/ether.h>"},
575       {"include/netinet/icmp6.h", "<netinet/icmp6.h>"},
576       {"include/netinet/if_ether.h", "<netinet/if_ether.h>"},
577       {"include/netinet/if_fddi.h", "<netinet/if_fddi.h>"},
578       {"include/netinet/if_tr.h", "<netinet/if_tr.h>"},
579       {"include/netinet/igmp.h", "<netinet/igmp.h>"},
580       {"include/netinet/in.h", "<netinet/in.h>"},
581       {"include/netinet/in_systm.h", "<netinet/in_systm.h>"},
582       {"include/netinet/ip.h", "<netinet/ip.h>"},
583       {"include/netinet/ip6.h", "<netinet/ip6.h>"},
584       {"include/netinet/ip_icmp.h", "<netinet/ip_icmp.h>"},
585       {"include/netinet/tcp.h", "<netinet/tcp.h>"},
586       {"include/netinet/udp.h", "<netinet/udp.h>"},
587       {"include/netrom/netrom.h", "<netrom/netrom.h>"},
588       {"include/protocols/routed.h", "<protocols/routed.h>"},
589       {"include/protocols/rwhod.h", "<protocols/rwhod.h>"},
590       {"include/protocols/talkd.h", "<protocols/talkd.h>"},
591       {"include/protocols/timed.h", "<protocols/timed.h>"},
592       {"include/rpcsvc/klm_prot.x", "<rpcsvc/klm_prot.x>"},
593       {"include/rpcsvc/rstat.h", "<rpcsvc/rstat.h>"},
594       {"include/rpcsvc/spray.x", "<rpcsvc/spray.x>"},
595       {"include/rpcsvc/nlm_prot.x", "<rpcsvc/nlm_prot.x>"},
596       {"include/rpcsvc/nis_callback.x", "<rpcsvc/nis_callback.x>"},
597       {"include/rpcsvc/yp.h", "<rpcsvc/yp.h>"},
598       {"include/rpcsvc/yp.x", "<rpcsvc/yp.x>"},
599       {"include/rpcsvc/nfs_prot.h", "<rpcsvc/nfs_prot.h>"},
600       {"include/rpcsvc/rex.h", "<rpcsvc/rex.h>"},
601       {"include/rpcsvc/yppasswd.h", "<rpcsvc/yppasswd.h>"},
602       {"include/rpcsvc/rex.x", "<rpcsvc/rex.x>"},
603       {"include/rpcsvc/nis_tags.h", "<rpcsvc/nis_tags.h>"},
604       {"include/rpcsvc/nis_callback.h", "<rpcsvc/nis_callback.h>"},
605       {"include/rpcsvc/nfs_prot.x", "<rpcsvc/nfs_prot.x>"},
606       {"include/rpcsvc/bootparam_prot.x", "<rpcsvc/bootparam_prot.x>"},
607       {"include/rpcsvc/rusers.x", "<rpcsvc/rusers.x>"},
608       {"include/rpcsvc/rquota.x", "<rpcsvc/rquota.x>"},
609       {"include/rpcsvc/nis.h", "<rpcsvc/nis.h>"},
610       {"include/rpcsvc/nislib.h", "<rpcsvc/nislib.h>"},
611       {"include/rpcsvc/ypupd.h", "<rpcsvc/ypupd.h>"},
612       {"include/rpcsvc/bootparam.h", "<rpcsvc/bootparam.h>"},
613       {"include/rpcsvc/spray.h", "<rpcsvc/spray.h>"},
614       {"include/rpcsvc/key_prot.h", "<rpcsvc/key_prot.h>"},
615       {"include/rpcsvc/klm_prot.h", "<rpcsvc/klm_prot.h>"},
616       {"include/rpcsvc/sm_inter.h", "<rpcsvc/sm_inter.h>"},
617       {"include/rpcsvc/nlm_prot.h", "<rpcsvc/nlm_prot.h>"},
618       {"include/rpcsvc/yp_prot.h", "<rpcsvc/yp_prot.h>"},
619       {"include/rpcsvc/ypclnt.h", "<rpcsvc/ypclnt.h>"},
620       {"include/rpcsvc/rstat.x", "<rpcsvc/rstat.x>"},
621       {"include/rpcsvc/rusers.h", "<rpcsvc/rusers.h>"},
622       {"include/rpcsvc/key_prot.x", "<rpcsvc/key_prot.x>"},
623       {"include/rpcsvc/sm_inter.x", "<rpcsvc/sm_inter.x>"},
624       {"include/rpcsvc/rquota.h", "<rpcsvc/rquota.h>"},
625       {"include/rpcsvc/nis.x", "<rpcsvc/nis.x>"},
626       {"include/rpcsvc/bootparam_prot.h", "<rpcsvc/bootparam_prot.h>"},
627       {"include/rpcsvc/mount.h", "<rpcsvc/mount.h>"},
628       {"include/rpcsvc/mount.x", "<rpcsvc/mount.x>"},
629       {"include/rpcsvc/nis_object.x", "<rpcsvc/nis_object.x>"},
630       {"include/rpcsvc/yppasswd.x", "<rpcsvc/yppasswd.x>"},
631       {"sys/acct.h", "<sys/acct.h>"},
632       {"sys/auxv.h", "<sys/auxv.h>"},
633       {"sys/cdefs.h", "<sys/cdefs.h>"},
634       {"sys/debugreg.h", "<sys/debugreg.h>"},
635       {"sys/dir.h", "<sys/dir.h>"},
636       {"sys/elf.h", "<sys/elf.h>"},
637       {"sys/epoll.h", "<sys/epoll.h>"},
638       {"sys/eventfd.h", "<sys/eventfd.h>"},
639       {"sys/fanotify.h", "<sys/fanotify.h>"},
640       {"sys/file.h", "<sys/file.h>"},
641       {"sys/fsuid.h", "<sys/fsuid.h>"},
642       {"sys/gmon.h", "<sys/gmon.h>"},
643       {"sys/gmon_out.h", "<sys/gmon_out.h>"},
644       {"sys/inotify.h", "<sys/inotify.h>"},
645       {"sys/io.h", "<sys/io.h>"},
646       {"sys/ioctl.h", "<sys/ioctl.h>"},
647       {"sys/ipc.h", "<sys/ipc.h>"},
648       {"sys/kd.h", "<sys/kd.h>"},
649       {"sys/kdaemon.h", "<sys/kdaemon.h>"},
650       {"sys/klog.h", "<sys/klog.h>"},
651       {"sys/mman.h", "<sys/mman.h>"},
652       {"sys/mount.h", "<sys/mount.h>"},
653       {"sys/msg.h", "<sys/msg.h>"},
654       {"sys/mtio.h", "<sys/mtio.h>"},
655       {"sys/param.h", "<sys/param.h>"},
656       {"sys/pci.h", "<sys/pci.h>"},
657       {"sys/perm.h", "<sys/perm.h>"},
658       {"sys/personality.h", "<sys/personality.h>"},
659       {"sys/poll.h", "<sys/poll.h>"},
660       {"sys/prctl.h", "<sys/prctl.h>"},
661       {"sys/procfs.h", "<sys/procfs.h>"},
662       {"sys/profil.h", "<sys/profil.h>"},
663       {"sys/ptrace.h", "<sys/ptrace.h>"},
664       {"sys/queue.h", "<sys/queue.h>"},
665       {"sys/quota.h", "<sys/quota.h>"},
666       {"sys/raw.h", "<sys/raw.h>"},
667       {"sys/reboot.h", "<sys/reboot.h>"},
668       {"sys/reg.h", "<sys/reg.h>"},
669       {"sys/resource.h", "<sys/resource.h>"},
670       {"sys/select.h", "<sys/select.h>"},
671       {"sys/sem.h", "<sys/sem.h>"},
672       {"sys/sendfile.h", "<sys/sendfile.h>"},
673       {"sys/shm.h", "<sys/shm.h>"},
674       {"sys/signalfd.h", "<sys/signalfd.h>"},
675       {"sys/socket.h", "<sys/socket.h>"},
676       {"sys/stat.h", "<sys/stat.h>"},
677       {"sys/statfs.h", "<sys/statfs.h>"},
678       {"sys/statvfs.h", "<sys/statvfs.h>"},
679       {"sys/swap.h", "<sys/swap.h>"},
680       {"sys/syscall.h", "<sys/syscall.h>"},
681       {"sys/sysctl.h", "<sys/sysctl.h>"},
682       {"sys/sysinfo.h", "<sys/sysinfo.h>"},
683       {"sys/syslog.h", "<sys/syslog.h>"},
684       {"sys/sysmacros.h", "<sys/sysmacros.h>"},
685       {"sys/termios.h", "<sys/termios.h>"},
686       {"sys/time.h", "<sys/select.h>"},
687       {"sys/timeb.h", "<sys/timeb.h>"},
688       {"sys/timerfd.h", "<sys/timerfd.h>"},
689       {"sys/times.h", "<sys/times.h>"},
690       {"sys/timex.h", "<sys/timex.h>"},
691       {"sys/ttychars.h", "<sys/ttychars.h>"},
692       {"sys/ttydefaults.h", "<sys/ttydefaults.h>"},
693       {"sys/types.h", "<sys/types.h>"},
694       {"sys/ucontext.h", "<sys/ucontext.h>"},
695       {"sys/uio.h", "<sys/uio.h>"},
696       {"sys/un.h", "<sys/un.h>"},
697       {"sys/user.h", "<sys/user.h>"},
698       {"sys/ustat.h", "<sys/ustat.h>"},
699       {"sys/utsname.h", "<sys/utsname.h>"},
700       {"sys/vlimit.h", "<sys/vlimit.h>"},
701       {"sys/vm86.h", "<sys/vm86.h>"},
702       {"sys/vtimes.h", "<sys/vtimes.h>"},
703       {"sys/wait.h", "<sys/wait.h>"},
704       {"sys/xattr.h", "<sys/xattr.h>"},
705       {"bits/epoll.h", "<sys/epoll.h>"},
706       {"bits/eventfd.h", "<sys/eventfd.h>"},
707       {"bits/inotify.h", "<sys/inotify.h>"},
708       {"bits/ipc.h", "<sys/ipc.h>"},
709       {"bits/ipctypes.h", "<sys/ipc.h>"},
710       {"bits/mman-linux.h", "<sys/mman.h>"},
711       {"bits/mman.h", "<sys/mman.h>"},
712       {"bits/msq.h", "<sys/msg.h>"},
713       {"bits/resource.h", "<sys/resource.h>"},
714       {"bits/sem.h", "<sys/sem.h>"},
715       {"bits/shm.h", "<sys/shm.h>"},
716       {"bits/signalfd.h", "<sys/signalfd.h>"},
717       {"bits/statfs.h", "<sys/statfs.h>"},
718       {"bits/statvfs.h", "<sys/statvfs.h>"},
719       {"bits/timerfd.h", "<sys/timerfd.h>"},
720       {"bits/utsname.h", "<sys/utsname.h>"},
721       {"bits/auxv.h", "<sys/auxv.h>"},
722       {"bits/byteswap-16.h", "<byteswap.h>"},
723       {"bits/byteswap.h", "<byteswap.h>"},
724       {"bits/confname.h", "<unistd.h>"},
725       {"bits/dirent.h", "<dirent.h>"},
726       {"bits/dlfcn.h", "<dlfcn.h>"},
727       {"bits/elfclass.h", "<link.h>"},
728       {"bits/endian.h", "<endian.h>"},
729       {"bits/environments.h", "<unistd.h>"},
730       {"bits/fcntl-linux.h", "<fcntl.h>"},
731       {"bits/fcntl.h", "<fcntl.h>"},
732       {"bits/in.h", "<netinet/in.h>"},
733       {"bits/ioctl-types.h", "<sys/ioctl.h>"},
734       {"bits/ioctls.h", "<sys/ioctl.h>"},
735       {"bits/link.h", "<link.h>"},
736       {"bits/mqueue.h", "<mqueue.h>"},
737       {"bits/netdb.h", "<netdb.h>"},
738       {"bits/param.h", "<sys/param.h>"},
739       {"bits/poll.h", "<sys/poll.h>"},
740       {"bits/posix_opt.h", "<bits/posix_opt.h>"},
741       {"bits/pthreadtypes.h", "<pthread.h>"},
742       {"bits/sched.h", "<sched.h>"},
743       {"bits/select.h", "<sys/select.h>"},
744       {"bits/semaphore.h", "<semaphore.h>"},
745       {"bits/sigthread.h", "<pthread.h>"},
746       {"bits/sockaddr.h", "<sys/socket.h>"},
747       {"bits/socket.h", "<sys/socket.h>"},
748       {"bits/socket_type.h", "<sys/socket.h>"},
749       {"bits/stab.def", "<stab.h>"},
750       {"bits/stat.h", "<sys/stat.h>"},
751       {"bits/stropts.h", "<stropts.h>"},
752       {"bits/syscall.h", "<sys/syscall.h>"},
753       {"bits/syslog-path.h", "<sys/syslog.h>"},
754       {"bits/termios.h", "<termios.h>"},
755       {"bits/types.h", "<sys/types.h>"},
756       {"bits/typesizes.h", "<sys/types.h>"},
757       {"bits/uio.h", "<sys/uio.h>"},
758       {"bits/ustat.h", "<sys/ustat.h>"},
759       {"bits/utmp.h", "<utmp.h>"},
760       {"bits/utmpx.h", "<utmpx.h>"},
761       {"bits/waitflags.h", "<sys/wait.h>"},
762       {"bits/waitstatus.h", "<sys/wait.h>"},
763       {"bits/xtitypes.h", "<stropts.h>"},
764   });
765   // Check MaxSuffixComponents constant is correct.
766   assert(llvm::all_of(SystemHeaderMap->keys(), [](llvm::StringRef Path) {
767     return std::distance(
768                llvm::sys::path::begin(Path, llvm::sys::path::Style::posix),
769                llvm::sys::path::end(Path)) <= MaxSuffixComponents;
770   }));
771   // ... and precise.
772   assert(llvm::find_if(SystemHeaderMap->keys(), [](llvm::StringRef Path) {
773            return std::distance(llvm::sys::path::begin(
774                                     Path, llvm::sys::path::Style::posix),
775                                 llvm::sys::path::end(Path)) ==
776                   MaxSuffixComponents;
777          }) != SystemHeaderMap->keys().end());
778 
779   // FIXME: Suffix mapping contains invalid entries for C, so only enable it for
780   // CPP.
781   if (Language.CPlusPlus)
782     StdSuffixHeaderMapping = SystemHeaderMap;
783 }
784 
785 } // namespace clangd
786 } // namespace clang
787