aboutsummaryrefslogtreecommitdiff
path: root/clang
diff options
context:
space:
mode:
authorAbhina Sree <Abhina.Sreeskantharajan@ibm.com>2024-09-19 14:30:10 -0400
committerGitHub <noreply@github.com>2024-09-19 14:30:10 -0400
commitedf3b277a5f2ebe144827ed47463c22743cac5f9 (patch)
tree99185acc509e869ab34528456e026b06f6594f6b /clang
parentf3f3883f4b9d15770a5ce49956ed4425c71ad69f (diff)
downloadllvm-edf3b277a5f2ebe144827ed47463c22743cac5f9.zip
llvm-edf3b277a5f2ebe144827ed47463c22743cac5f9.tar.gz
llvm-edf3b277a5f2ebe144827ed47463c22743cac5f9.tar.bz2
[SystemZ][z/OS] Propagate IsText parameter to open text files as text (#107906)
This patch adds an IsText parameter to the following functions openFileForRead, getBufferForFile, getBufferForFileImpl and determines whether a file is text by querying the file tag on z/OS. The default is set to OF_Text instead of OF_None, this change in value does not affect any other platforms other than z/OS.
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/Basic/FileManager.h8
-rw-r--r--clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h2
-rw-r--r--clang/lib/Basic/FileManager.cpp12
-rw-r--r--clang/lib/Basic/SourceManager.cpp14
-rw-r--r--clang/lib/Serialization/ASTReader.cpp3
-rw-r--r--clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp5
-rw-r--r--clang/unittests/Driver/DistroTest.cpp4
-rw-r--r--clang/unittests/Driver/ToolChainTest.cpp2
-rw-r--r--clang/unittests/Frontend/PCHPreambleTest.cpp6
-rw-r--r--clang/unittests/Tooling/DependencyScanning/DependencyScannerTest.cpp4
10 files changed, 36 insertions, 24 deletions
diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h
index 527bbef..67a69fb 100644
--- a/clang/include/clang/Basic/FileManager.h
+++ b/clang/include/clang/Basic/FileManager.h
@@ -286,21 +286,21 @@ public:
/// MemoryBuffer if successful, otherwise returning null.
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
getBufferForFile(FileEntryRef Entry, bool isVolatile = false,
- bool RequiresNullTerminator = true,
+ bool RequiresNullTerminator = true, bool IsText = true,
std::optional<int64_t> MaybeLimit = std::nullopt);
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
getBufferForFile(StringRef Filename, bool isVolatile = false,
- bool RequiresNullTerminator = true,
+ bool RequiresNullTerminator = true, bool IsText = true,
std::optional<int64_t> MaybeLimit = std::nullopt) const {
return getBufferForFileImpl(Filename,
/*FileSize=*/(MaybeLimit ? *MaybeLimit : -1),
- isVolatile, RequiresNullTerminator);
+ isVolatile, RequiresNullTerminator, IsText);
}
private:
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
getBufferForFileImpl(StringRef Filename, int64_t FileSize, bool isVolatile,
- bool RequiresNullTerminator) const;
+ bool RequiresNullTerminator, bool IsText) const;
DirectoryEntry *&getRealDirEntry(const llvm::vfs::Status &Status);
diff --git a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
index d12814e..635fdd0e 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -346,7 +346,7 @@ public:
llvm::ErrorOr<llvm::vfs::Status> status(const Twine &Path) override;
llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>
- openFileForRead(const Twine &Path) override;
+ openFileForRead(const Twine &Path, bool IsText = true) override;
std::error_code getRealPath(const Twine &Path,
SmallVectorImpl<char> &Output) override;
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index 6097b85..27075ce 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -530,7 +530,7 @@ void FileManager::fillRealPathName(FileEntry *UFE, llvm::StringRef FileName) {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile,
- bool RequiresNullTerminator,
+ bool RequiresNullTerminator, bool IsText,
std::optional<int64_t> MaybeLimit) {
const FileEntry *Entry = &FE.getFileEntry();
// If the content is living on the file entry, return a reference to it.
@@ -558,21 +558,21 @@ FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile,
// Otherwise, open the file.
return getBufferForFileImpl(Filename, FileSize, isVolatile,
- RequiresNullTerminator);
+ RequiresNullTerminator, IsText);
}
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
FileManager::getBufferForFileImpl(StringRef Filename, int64_t FileSize,
- bool isVolatile,
- bool RequiresNullTerminator) const {
+ bool isVolatile, bool RequiresNullTerminator,
+ bool IsText) const {
if (FileSystemOpts.WorkingDir.empty())
return FS->getBufferForFile(Filename, FileSize, RequiresNullTerminator,
- isVolatile);
+ isVolatile, IsText);
SmallString<128> FilePath(Filename);
FixupRelativePath(FilePath);
return FS->getBufferForFile(FilePath, FileSize, RequiresNullTerminator,
- isVolatile);
+ isVolatile, IsText);
}
/// getStatValue - Get the 'stat' information for the specified path,
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index 65a8a72..fe3aff7 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -121,8 +121,18 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
// Start with the assumption that the buffer is invalid to simplify early
// return paths.
IsBufferInvalid = true;
-
- auto BufferOrError = FM.getBufferForFile(*ContentsEntry, IsFileVolatile);
+ bool IsText = false;
+
+#ifdef __MVS__
+ // If the file is tagged with a text ccsid, it may require autoconversion.
+ llvm::ErrorOr<bool> IsFileText =
+ llvm::iszOSTextFile(ContentsEntry->getName().data());
+ if (IsFileText)
+ IsText = *IsFileText;
+#endif
+
+ auto BufferOrError = FM.getBufferForFile(
+ *ContentsEntry, IsFileVolatile, /*RequiresNullTerminator=*/true, IsText);
// If we were unable to open the file, then we are in an inconsistent
// situation where the content cache referenced a file which no longer
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 7efcc81..ad0551e 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -5317,7 +5317,8 @@ std::string ASTReader::getOriginalSourceFile(
const PCHContainerReader &PCHContainerRdr, DiagnosticsEngine &Diags) {
// Open the AST file.
auto Buffer = FileMgr.getBufferForFile(ASTFileName, /*IsVolatile=*/false,
- /*RequiresNullTerminator=*/false);
+ /*RequiresNullTerminator=*/false,
+ /*IsText=*/true);
if (!Buffer) {
Diags.Report(diag::err_fe_unable_to_read_pch_file)
<< ASTFileName << Buffer.getError().message();
diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
index 4d738e4..7d6239a 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -353,12 +353,13 @@ DepScanFile::create(EntryRef Entry) {
}
llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>
-DependencyScanningWorkerFilesystem::openFileForRead(const Twine &Path) {
+DependencyScanningWorkerFilesystem::openFileForRead(const Twine &Path,
+ bool IsText) {
SmallString<256> OwnedFilename;
StringRef Filename = Path.toStringRef(OwnedFilename);
if (shouldBypass(Filename))
- return getUnderlyingFS().openFileForRead(Path);
+ return getUnderlyingFS().openFileForRead(Path, IsText);
llvm::ErrorOr<EntryRef> Result = getOrCreateFileSystemEntry(Filename);
if (!Result)
diff --git a/clang/unittests/Driver/DistroTest.cpp b/clang/unittests/Driver/DistroTest.cpp
index 43efc0dd..4c13b8b 100644
--- a/clang/unittests/Driver/DistroTest.cpp
+++ b/clang/unittests/Driver/DistroTest.cpp
@@ -352,9 +352,9 @@ TEST(DistroTest, DetectWindowsAndCrossCompile) {
}
llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>
- openFileForRead(const llvm::Twine &Path) override {
+ openFileForRead(const llvm::Twine &Path, bool IsText = true) override {
++Count;
- return llvm::vfs::ProxyFileSystem::openFileForRead(Path);
+ return llvm::vfs::ProxyFileSystem::openFileForRead(Path, IsText);
}
unsigned Count{};
diff --git a/clang/unittests/Driver/ToolChainTest.cpp b/clang/unittests/Driver/ToolChainTest.cpp
index a9b5f3c..6c8b32d 100644
--- a/clang/unittests/Driver/ToolChainTest.cpp
+++ b/clang/unittests/Driver/ToolChainTest.cpp
@@ -662,7 +662,7 @@ struct FileSystemWithError : public llvm::vfs::FileSystem {
return std::make_error_code(std::errc::no_such_file_or_directory);
}
llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>
- openFileForRead(const Twine &Path) override {
+ openFileForRead(const Twine &Path, bool IsText = true) override {
return std::make_error_code(std::errc::permission_denied);
}
llvm::vfs::directory_iterator dir_begin(const Twine &Dir,
diff --git a/clang/unittests/Frontend/PCHPreambleTest.cpp b/clang/unittests/Frontend/PCHPreambleTest.cpp
index 2ce24c9..137dcf2 100644
--- a/clang/unittests/Frontend/PCHPreambleTest.cpp
+++ b/clang/unittests/Frontend/PCHPreambleTest.cpp
@@ -36,10 +36,10 @@ class ReadCountingInMemoryFileSystem : public vfs::InMemoryFileSystem
std::map<std::string, unsigned> ReadCounts;
public:
- ErrorOr<std::unique_ptr<vfs::File>> openFileForRead(const Twine &Path) override
- {
+ ErrorOr<std::unique_ptr<vfs::File>>
+ openFileForRead(const Twine &Path, bool IsText = true) override {
++ReadCounts[Canonicalize(Path)];
- return InMemoryFileSystem::openFileForRead(Path);
+ return InMemoryFileSystem::openFileForRead(Path, IsText);
}
unsigned GetReadCount(const Twine &Path) const
diff --git a/clang/unittests/Tooling/DependencyScanning/DependencyScannerTest.cpp b/clang/unittests/Tooling/DependencyScanning/DependencyScannerTest.cpp
index ec0e143..1012016e 100644
--- a/clang/unittests/Tooling/DependencyScanning/DependencyScannerTest.cpp
+++ b/clang/unittests/Tooling/DependencyScanning/DependencyScannerTest.cpp
@@ -277,9 +277,9 @@ TEST(DependencyScanner, ScanDepsWithModuleLookup) {
}
llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>
- openFileForRead(const Twine &Path) override {
+ openFileForRead(const Twine &Path, bool IsText = true) override {
ReadFiles.push_back(Path.str());
- return ProxyFileSystem::openFileForRead(Path);
+ return ProxyFileSystem::openFileForRead(Path, IsText);
}
};