|
24 | 24 | #include "clang/Lex/ModuleLoader.h"
|
25 | 25 | #include "clang/Lex/Pragma.h"
|
26 | 26 | #include "llvm/ADT/APInt.h"
|
27 |
| -#include "llvm/ADT/STLExtras.h" |
28 |
| -#include "llvm/ADT/StringExtras.h" |
29 |
| -#include "llvm/ADT/StringSwitch.h" |
30 |
| -#include "llvm/ADT/iterator_range.h" |
31 | 27 | #include "llvm/Support/ErrorHandling.h"
|
32 | 28 | #include "llvm/Support/Path.h"
|
33 | 29 | #include "llvm/Support/SaveAndRestore.h"
|
@@ -141,84 +137,6 @@ static MacroDiag shouldWarnOnMacroUndef(Preprocessor &PP, IdentifierInfo *II) {
|
141 | 137 | return MD_NoWarn;
|
142 | 138 | }
|
143 | 139 |
|
144 |
| -// Return true if we want to issue a diagnostic by default if we |
145 |
| -// encounter this name in a #include with the wrong case. For now, |
146 |
| -// this includes the standard C and C++ headers, Posix headers, |
147 |
| -// and Boost headers. Improper case for these #includes is a |
148 |
| -// potential portability issue. |
149 |
| -static bool warnByDefaultOnWrongCase(StringRef Include) { |
150 |
| - // If the first component of the path is "boost", treat this like a standard header |
151 |
| - // for the purposes of diagnostics. |
152 |
| - if (::llvm::sys::path::begin(Include)->equals_lower("boost")) |
153 |
| - return true; |
154 |
| - |
155 |
| - // "condition_variable" is the longest standard header name at 18 characters. |
156 |
| - // If the include file name is longer than that, it can't be a standard header. |
157 |
| - static constexpr std::size_t MaxStdHeaderNameLen = 18u; |
158 |
| - if (Include.size() > MaxStdHeaderNameLen) |
159 |
| - return false; |
160 |
| - |
161 |
| - // Lowercase and normalize the search string. |
162 |
| - SmallString<32> LowerInclude{Include}; |
163 |
| - for (char &Ch : LowerInclude) { |
164 |
| - // In the ASCII range? |
165 |
| - if (Ch < 0 || Ch > 0x7f) |
166 |
| - return false; // Can't be a standard header |
167 |
| - // ASCII lowercase: |
168 |
| - if (Ch >= 'A' && Ch <= 'Z') |
169 |
| - Ch += 'a' - 'A'; |
170 |
| - // Normalize path separators for comparison purposes. |
171 |
| - else if (::llvm::sys::path::is_separator(Ch)) |
172 |
| - Ch = '/'; |
173 |
| - } |
174 |
| - |
175 |
| - // The standard C/C++ and Posix headers |
176 |
| - return llvm::StringSwitch<bool>(LowerInclude) |
177 |
| - // C library headers |
178 |
| - .Cases("assert.h", "complex.h", "ctype.h", "errno.h", "fenv.h", true) |
179 |
| - .Cases("float.h", "inttypes.h", "iso646.h", "limits.h", "locale.h", true) |
180 |
| - .Cases("math.h", "setjmp.h", "signal.h", "stdalign.h", "stdarg.h", true) |
181 |
| - .Cases("stdatomic.h", "stdbool.h", "stddef.h", "stdint.h", "stdio.h", true) |
182 |
| - .Cases("stdlib.h", "stdnoreturn.h", "string.h", "tgmath.h", "threads.h", true) |
183 |
| - .Cases("time.h", "uchar.h", "wchar.h", "wctype.h", true) |
184 |
| - |
185 |
| - // C++ headers for C library facilities |
186 |
| - .Cases("cassert", "ccomplex", "cctype", "cerrno", "cfenv", true) |
187 |
| - .Cases("cfloat", "cinttypes", "ciso646", "climits", "clocale", true) |
188 |
| - .Cases("cmath", "csetjmp", "csignal", "cstdalign", "cstdarg", true) |
189 |
| - .Cases("cstdbool", "cstddef", "cstdint", "cstdio", "cstdlib", true) |
190 |
| - .Cases("cstring", "ctgmath", "ctime", "cuchar", "cwchar", true) |
191 |
| - .Case("cwctype", true) |
192 |
| - |
193 |
| - // C++ library headers |
194 |
| - .Cases("algorithm", "fstream", "list", "regex", "thread", true) |
195 |
| - .Cases("array", "functional", "locale", "scoped_allocator", "tuple", true) |
196 |
| - .Cases("atomic", "future", "map", "set", "type_traits", true) |
197 |
| - .Cases("bitset", "initializer_list", "memory", "shared_mutex", "typeindex", true) |
198 |
| - .Cases("chrono", "iomanip", "mutex", "sstream", "typeinfo", true) |
199 |
| - .Cases("codecvt", "ios", "new", "stack", "unordered_map", true) |
200 |
| - .Cases("complex", "iosfwd", "numeric", "stdexcept", "unordered_set", true) |
201 |
| - .Cases("condition_variable", "iostream", "ostream", "streambuf", "utility", true) |
202 |
| - .Cases("deque", "istream", "queue", "string", "valarray", true) |
203 |
| - .Cases("exception", "iterator", "random", "strstream", "vector", true) |
204 |
| - .Cases("forward_list", "limits", "ratio", "system_error", true) |
205 |
| - |
206 |
| - // POSIX headers (which aren't also C headers) |
207 |
| - .Cases("aio.h", "arpa/inet.h", "cpio.h", "dirent.h", "dlfcn.h", true) |
208 |
| - .Cases("fcntl.h", "fmtmsg.h", "fnmatch.h", "ftw.h", "glob.h", true) |
209 |
| - .Cases("grp.h", "iconv.h", "langinfo.h", "libgen.h", "monetary.h", true) |
210 |
| - .Cases("mqueue.h", "ndbm.h", "net/if.h", "netdb.h", "netinet/in.h", true) |
211 |
| - .Cases("netinet/tcp.h", "nl_types.h", "poll.h", "pthread.h", "pwd.h", true) |
212 |
| - .Cases("regex.h", "sched.h", "search.h", "semaphore.h", "spawn.h", true) |
213 |
| - .Cases("strings.h", "stropts.h", "sys/ipc.h", "sys/mman.h", "sys/msg.h", true) |
214 |
| - .Cases("sys/resource.h", "sys/select.h", "sys/sem.h", "sys/shm.h", "sys/socket.h", true) |
215 |
| - .Cases("sys/stat.h", "sys/statvfs.h", "sys/time.h", "sys/times.h", "sys/types.h", true) |
216 |
| - .Cases("sys/uio.h", "sys/un.h", "sys/utsname.h", "sys/wait.h", "syslog.h", true) |
217 |
| - .Cases("tar.h", "termios.h", "trace.h", "ulimit.h", true) |
218 |
| - .Cases("unistd.h", "utime.h", "utmpx.h", "wordexp.h", true) |
219 |
| - .Default(false); |
220 |
| -} |
221 |
| - |
222 | 140 | bool Preprocessor::CheckMacroName(Token &MacroNameTok, MacroUse isDefineUndef,
|
223 | 141 | bool *ShadowFlag) {
|
224 | 142 | // Missing macro name?
|
@@ -1638,39 +1556,6 @@ static void diagnoseAutoModuleImport(
|
1638 | 1556 | ("@import " + PathString + ";").str());
|
1639 | 1557 | }
|
1640 | 1558 |
|
1641 |
| -// Given a vector of path components and a string containing the real |
1642 |
| -// path to the file, build a properly-cased replacement in the vector, |
1643 |
| -// and return true if the replacement should be suggested. |
1644 |
| -static bool trySimplifyPath(SmallVectorImpl<StringRef> &Components, |
1645 |
| - StringRef RealPathName) { |
1646 |
| - auto RealPathComponentIter = llvm::sys::path::rbegin(RealPathName); |
1647 |
| - auto RealPathComponentEnd = llvm::sys::path::rend(RealPathName); |
1648 |
| - int Cnt = 0; |
1649 |
| - bool SuggestReplacement = false; |
1650 |
| - // Below is a best-effort to handle ".." in paths. It is admittedly |
1651 |
| - // not 100% correct in the presence of symlinks. |
1652 |
| - for (auto &Component : llvm::reverse(Components)) { |
1653 |
| - if ("." == Component) { |
1654 |
| - } else if (".." == Component) { |
1655 |
| - ++Cnt; |
1656 |
| - } else if (Cnt) { |
1657 |
| - --Cnt; |
1658 |
| - } else if (RealPathComponentIter != RealPathComponentEnd) { |
1659 |
| - if (Component != *RealPathComponentIter) { |
1660 |
| - // If these path components differ by more than just case, then we |
1661 |
| - // may be looking at symlinked paths. Bail on this diagnostic to avoid |
1662 |
| - // noisy false positives. |
1663 |
| - SuggestReplacement = RealPathComponentIter->equals_lower(Component); |
1664 |
| - if (!SuggestReplacement) |
1665 |
| - break; |
1666 |
| - Component = *RealPathComponentIter; |
1667 |
| - } |
1668 |
| - ++RealPathComponentIter; |
1669 |
| - } |
1670 |
| - } |
1671 |
| - return SuggestReplacement; |
1672 |
| -} |
1673 |
| - |
1674 | 1559 | /// HandleIncludeDirective - The "\#include" tokens have just been read, read
|
1675 | 1560 | /// the file to be included from the lexer, then include it! This is a common
|
1676 | 1561 | /// routine with functionality shared between \#include, \#include_next and
|
@@ -1946,39 +1831,6 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
|
1946 | 1831 | // FIXME: If we have a suggested module, and we've already visited this file,
|
1947 | 1832 | // don't bother entering it again. We know it has no further effect.
|
1948 | 1833 |
|
1949 |
| - // Issue a diagnostic if the name of the file on disk has a different case |
1950 |
| - // than the one we're about to open. |
1951 |
| - const bool CheckIncludePathPortability = |
1952 |
| - File && !File->tryGetRealPathName().empty(); |
1953 |
| - |
1954 |
| - if (CheckIncludePathPortability) { |
1955 |
| - StringRef Name = LangOpts.MSVCCompat ? NormalizedPath.str() : Filename; |
1956 |
| - StringRef RealPathName = File->tryGetRealPathName(); |
1957 |
| - SmallVector<StringRef, 16> Components(llvm::sys::path::begin(Name), |
1958 |
| - llvm::sys::path::end(Name)); |
1959 |
| - |
1960 |
| - if (trySimplifyPath(Components, RealPathName)) { |
1961 |
| - SmallString<128> Path; |
1962 |
| - Path.reserve(Name.size()+2); |
1963 |
| - Path.push_back(isAngled ? '<' : '"'); |
1964 |
| - for (auto Component : Components) { |
1965 |
| - Path.append(Component); |
1966 |
| - // Append the separator the user used, or the close quote |
1967 |
| - Path.push_back( |
1968 |
| - Path.size() <= Filename.size() ? Filename[Path.size()-1] : |
1969 |
| - (isAngled ? '>' : '"')); |
1970 |
| - } |
1971 |
| - auto Replacement = Path.str().str(); |
1972 |
| - // For user files and known standard headers, by default we issue a diagnostic. |
1973 |
| - // For other system headers, we don't. They can be controlled separately. |
1974 |
| - auto DiagId = (FileCharacter == SrcMgr::C_User || warnByDefaultOnWrongCase(Name)) ? |
1975 |
| - diag::pp_nonportable_path : diag::pp_nonportable_system_path; |
1976 |
| - SourceRange Range(FilenameTok.getLocation(), CharEnd); |
1977 |
| - Diag(FilenameTok, DiagId) << Replacement << |
1978 |
| - FixItHint::CreateReplacement(Range, Replacement); |
1979 |
| - } |
1980 |
| - } |
1981 |
| - |
1982 | 1834 | // Ask HeaderInfo if we should enter this #include file. If not, #including
|
1983 | 1835 | // this file will have no effect.
|
1984 | 1836 | if (ShouldEnter &&
|
|
0 commit comments