mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-22 15:31:00 +00:00
Fix bugs when an included file name is typo corrected.
D52774 fixed a bug with typo correction of includes, but didn't add a test. D65907 then broke recovery of typo correction of includes again, because it extracted the code that writes to Filename to a separate function that took the parameter not by reference. Fix that, and also don't repeat the slash normalization computation and fix both lookup and regular file name after recovery. Differential Revision: https://reviews.llvm.org/D79595
This commit is contained in:
parent
eaea9ed835
commit
51d938bc94
@ -2242,11 +2242,11 @@ private:
|
||||
};
|
||||
|
||||
Optional<FileEntryRef> LookupHeaderIncludeOrImport(
|
||||
const DirectoryLookup *&CurDir, StringRef Filename,
|
||||
const DirectoryLookup *&CurDir, StringRef &Filename,
|
||||
SourceLocation FilenameLoc, CharSourceRange FilenameRange,
|
||||
const Token &FilenameTok, bool &IsFrameworkFound, bool IsImportDecl,
|
||||
bool &IsMapped, const DirectoryLookup *LookupFrom,
|
||||
const FileEntry *LookupFromFile, StringRef LookupFilename,
|
||||
const FileEntry *LookupFromFile, StringRef &LookupFilename,
|
||||
SmallVectorImpl<char> &RelativePath, SmallVectorImpl<char> &SearchPath,
|
||||
ModuleMap::KnownHeader &SuggestedModule, bool isAngled);
|
||||
|
||||
|
@ -1716,11 +1716,11 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
|
||||
}
|
||||
|
||||
Optional<FileEntryRef> Preprocessor::LookupHeaderIncludeOrImport(
|
||||
const DirectoryLookup *&CurDir, StringRef Filename,
|
||||
const DirectoryLookup *&CurDir, StringRef& Filename,
|
||||
SourceLocation FilenameLoc, CharSourceRange FilenameRange,
|
||||
const Token &FilenameTok, bool &IsFrameworkFound, bool IsImportDecl,
|
||||
bool &IsMapped, const DirectoryLookup *LookupFrom,
|
||||
const FileEntry *LookupFromFile, StringRef LookupFilename,
|
||||
const FileEntry *LookupFromFile, StringRef& LookupFilename,
|
||||
SmallVectorImpl<char> &RelativePath, SmallVectorImpl<char> &SearchPath,
|
||||
ModuleMap::KnownHeader &SuggestedModule, bool isAngled) {
|
||||
Optional<FileEntryRef> File = LookupFile(
|
||||
@ -1789,21 +1789,10 @@ Optional<FileEntryRef> Preprocessor::LookupHeaderIncludeOrImport(
|
||||
return Filename;
|
||||
};
|
||||
StringRef TypoCorrectionName = CorrectTypoFilename(Filename);
|
||||
|
||||
#ifndef _WIN32
|
||||
// Normalize slashes when compiling with -fms-extensions on non-Windows.
|
||||
// This is unnecessary on Windows since the filesystem there handles
|
||||
// backslashes.
|
||||
SmallString<128> NormalizedTypoCorrectionPath;
|
||||
if (LangOpts.MicrosoftExt) {
|
||||
NormalizedTypoCorrectionPath = TypoCorrectionName;
|
||||
llvm::sys::path::native(NormalizedTypoCorrectionPath);
|
||||
TypoCorrectionName = NormalizedTypoCorrectionPath;
|
||||
}
|
||||
#endif
|
||||
StringRef TypoCorrectionLookupName = CorrectTypoFilename(LookupFilename);
|
||||
|
||||
Optional<FileEntryRef> File = LookupFile(
|
||||
FilenameLoc, TypoCorrectionName, isAngled, LookupFrom, LookupFromFile,
|
||||
FilenameLoc, TypoCorrectionLookupName, isAngled, LookupFrom, LookupFromFile,
|
||||
CurDir, Callbacks ? &SearchPath : nullptr,
|
||||
Callbacks ? &RelativePath : nullptr, &SuggestedModule, &IsMapped,
|
||||
/*IsFrameworkFound=*/nullptr);
|
||||
@ -1818,6 +1807,7 @@ Optional<FileEntryRef> Preprocessor::LookupHeaderIncludeOrImport(
|
||||
// We found the file, so set the Filename to the name after typo
|
||||
// correction.
|
||||
Filename = TypoCorrectionName;
|
||||
LookupFilename = TypoCorrectionLookupName;
|
||||
return File;
|
||||
}
|
||||
}
|
||||
@ -2074,8 +2064,6 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport(
|
||||
if (Callbacks && !IsImportDecl) {
|
||||
// Notify the callback object that we've seen an inclusion directive.
|
||||
// FIXME: Use a different callback for a pp-import?
|
||||
// FIXME: Passes wrong filename if LookupHeaderIncludeOrImport() did
|
||||
// typo correction.
|
||||
Callbacks->InclusionDirective(
|
||||
HashLoc, IncludeTok, LookupFilename, isAngled, FilenameRange,
|
||||
File ? &File->getFileEntry() : nullptr, SearchPath, RelativePath,
|
||||
@ -2102,7 +2090,6 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport(
|
||||
!IsMapped && !File->getFileEntry().tryGetRealPathName().empty();
|
||||
|
||||
if (CheckIncludePathPortability) {
|
||||
// FIXME: Looks at the wrong filename if we did typo correction.
|
||||
StringRef Name = LookupFilename;
|
||||
StringRef NameWithoriginalSlashes = Filename;
|
||||
#if defined(_WIN32)
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
// RUN: mkdir -p %t
|
||||
// RUN: touch %t/case-insensitive-include-pr31836.h
|
||||
// RUN: echo "#include \"%t/Case-Insensitive-Include-Pr31836.h\"" | %clang_cc1 -E - 2>&1 | FileCheck %s
|
||||
// RUN: echo "#include \"\\\\\\\\?\\\\%t/Case-Insensitive-Include-Pr31836.h\"" | not %clang_cc1 -E - 2>&1 | FileCheck %s
|
||||
|
||||
// CHECK: error: {{.*}}file not found, did you mean
|
||||
// CHECK: warning: non-portable path to file
|
||||
// CHECK-SAME: /case-insensitive-include-pr31836.h
|
||||
|
@ -5,6 +5,6 @@
|
||||
// REQUIRES: system-windows
|
||||
// RUN: mkdir -p %t.dir
|
||||
// RUN: touch %t.dir/foo.h
|
||||
// RUN: not %clang_cl /FI\\?\%t.dir\FOO.h /WX -Xclang -verify -fsyntax-only %s 2>&1 | FileCheck %s
|
||||
// RUN: not %clang_cl /FI\\?\%t.dir\FOO.h /WX -fsyntax-only %s 2>&1 | FileCheck %s
|
||||
|
||||
// CHECK: non-portable path to file '"\\?\
|
||||
|
Loading…
Reference in New Issue
Block a user