[flang-commits] [flang] cbad576 - [flang][msvc] Fix external-io unittest.
Michael Kruse via flang-commits
flang-commits at lists.llvm.org
Mon Jul 26 13:34:40 PDT 2021
Author: Michael Kruse
Date: 2021-07-26T15:34:35-05:00
New Revision: cbad57613e769d0653e13cf877d80eae421b2314
URL: https://github.com/llvm/llvm-project/commit/cbad57613e769d0653e13cf877d80eae421b2314
DIFF: https://github.com/llvm/llvm-project/commit/cbad57613e769d0653e13cf877d80eae421b2314.diff
LOG: [flang][msvc] Fix external-io unittest.
Fix the external-io unittest under Windows.
In particular, fixes the following issues:
1. When creating a temporary file, open it with read+write permissions
using the _O_RDWR flag. _S_IREAD and _S_IWRITE are for the file
permissions of the created file.
2. _chsize returns 0 on success (just like ftruncate).
3. To set a std::optional, use its assign-operator overload instead of
getting a reference to its value and overwrite that. The latter is
invalid if the std::optional has no value, and is caught by
msvc's debug STL.
The non-GTest unittest is currently not executed under Windows because
of the added .exe extension to the output file: external-io.text.exe.
llvm-lit skips the file because .exe is not in the lists of test
suffixes (.test is). D105315 is going to change that by converting it
to a GTest-test.
Reviewed By: awarzynski
Differential Revision: https://reviews.llvm.org/D106726
Added:
Modified:
flang/runtime/file.cpp
flang/runtime/unit.cpp
Removed:
################################################################################
diff --git a/flang/runtime/file.cpp b/flang/runtime/file.cpp
index 35d305d295da8..98844a5bf3e8c 100644
--- a/flang/runtime/file.cpp
+++ b/flang/runtime/file.cpp
@@ -45,7 +45,8 @@ static int openfile_mkstemp(IoErrorHandler &handler) {
if (::GetTempFileNameA(tempDirName, "Fortran", uUnique, tempFileName) == 0) {
return -1;
}
- int fd{::_open(tempFileName, _O_CREAT | _O_TEMPORARY, _S_IREAD | _S_IWRITE)};
+ int fd{::_open(
+ tempFileName, _O_CREAT | _O_TEMPORARY | _O_RDWR, _S_IREAD | _S_IWRITE)};
#else
char path[]{"/tmp/Fortran-Scratch-XXXXXX"};
int fd{::mkstemp(path)};
@@ -245,7 +246,7 @@ std::size_t OpenFile::Write(FileOffset at, const char *buffer,
inline static int openfile_ftruncate(int fd, OpenFile::FileOffset at) {
#ifdef _WIN32
- return !::_chsize(fd, at);
+ return ::_chsize(fd, at);
#else
return ::ftruncate(fd, at);
#endif
diff --git a/flang/runtime/unit.cpp b/flang/runtime/unit.cpp
index ab48ff218dff3..b36acf42f6fb3 100644
--- a/flang/runtime/unit.cpp
+++ b/flang/runtime/unit.cpp
@@ -687,13 +687,13 @@ void ExternalFileUnit::BackspaceVariableFormattedRecord(
if (const char *p{
FindLastNewline(Frame(), prevNL - 1 - frameOffsetInFile_)}) {
recordOffsetInFrame_ = p - Frame() + 1;
- *recordLength = prevNL - (frameOffsetInFile_ + recordOffsetInFrame_);
+ recordLength = prevNL - (frameOffsetInFile_ + recordOffsetInFrame_);
break;
}
}
if (frameOffsetInFile_ == 0) {
recordOffsetInFrame_ = 0;
- *recordLength = prevNL;
+ recordLength = prevNL;
break;
}
frameOffsetInFile_ -= std::min<std::int64_t>(frameOffsetInFile_, 1024);
More information about the flang-commits
mailing list