[flang-commits] [PATCH] D106726: [flang][msvc] Fix external-io unittest.

Michael Kruse via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Jul 23 16:43:34 PDT 2021


Meinersbur created this revision.
Meinersbur added reviewers: awarzynski, ashermancinelli, sscalpone, klausler, ChinouneMehdi, kiranchandramohan.
Meinersbur added a project: Flang.
Herald added a subscriber: jdoerfert.
Meinersbur requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.
2. _chsize <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/chsize?view=msvc-160> returns 0 on success (just like `ftruncate`).
3. To set a std::optional, use its assign-operator overload instead of getting a reference of its value an 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 <https://reviews.llvm.org/D105315> is going to change that by converting it to a gtest-test.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106726

Files:
  flang/runtime/file.cpp
  flang/runtime/unit.cpp


Index: flang/runtime/unit.cpp
===================================================================
--- flang/runtime/unit.cpp
+++ flang/runtime/unit.cpp
@@ -674,13 +674,13 @@
       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);
Index: flang/runtime/file.cpp
===================================================================
--- flang/runtime/file.cpp
+++ flang/runtime/file.cpp
@@ -45,7 +45,8 @@
   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)};
@@ -246,7 +247,7 @@
 
 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106726.361378.patch
Type: text/x-patch
Size: 1492 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20210723/379a2dc9/attachment.bin>


More information about the flang-commits mailing list