Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang][runtime] Don't write implied ENDFILE for REC=/POS= #79637

Merged
merged 1 commit into from
Feb 20, 2024

Conversation

klausler
Copy link
Contributor

An implied ENDFILE record, which truncates an external file, should be written to a sequential unit whenever the file is repositioned for a BACKSPACE or REWIND statement if a WRITE statement has executed since the last OPEN/BACKSPACE/REWIND.

But the REC= and POS= positioning specifiers don't apply to sequential units (they're for direct and stream units, resp.), so don't truncate the file when they're used.

@llvmbot llvmbot added flang:runtime flang Flang issues not falling into any other category labels Jan 26, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 26, 2024

@llvm/pr-subscribers-flang-runtime

Author: Peter Klausler (klausler)

Changes

An implied ENDFILE record, which truncates an external file, should be written to a sequential unit whenever the file is repositioned for a BACKSPACE or REWIND statement if a WRITE statement has executed since the last OPEN/BACKSPACE/REWIND.

But the REC= and POS= positioning specifiers don't apply to sequential units (they're for direct and stream units, resp.), so don't truncate the file when they're used.


Full diff: https://github.com/llvm/llvm-project/pull/79637.diff

1 Files Affected:

  • (modified) flang/runtime/unit.cpp (+1-1)
diff --git a/flang/runtime/unit.cpp b/flang/runtime/unit.cpp
index 18590567c65eb0a..d927d012225672d 100644
--- a/flang/runtime/unit.cpp
+++ b/flang/runtime/unit.cpp
@@ -679,6 +679,7 @@ void ExternalFileUnit::Rewind(IoErrorHandler &handler) {
     handler.SignalError(IostatRewindNonSequential,
         "REWIND(UNIT=%d) on non-sequential file", unitNumber());
   } else {
+    DoImpliedEndfile(handler);
     SetPosition(0, handler);
     currentRecordNumber = 1;
     leftTabLimit.reset();
@@ -687,7 +688,6 @@ void ExternalFileUnit::Rewind(IoErrorHandler &handler) {
 }
 
 void ExternalFileUnit::SetPosition(std::int64_t pos, IoErrorHandler &handler) {
-  DoImpliedEndfile(handler);
   frameOffsetInFile_ = pos;
   recordOffsetInFrame_ = 0;
   if (access == Access::Direct) {

@klausler klausler force-pushed the no-trunc-pos branch 2 times, most recently from 6a9b751 to 3e9d9db Compare January 30, 2024 17:53
An implied ENDFILE record, which truncates an external file,
should be written to a sequential unit whenever the file is
repositioned for a BACKSPACE or REWIND statement if a WRITE
statement has executed since the last OPEN/BACKSPACE/REWIND.

But the REC= and POS= positioning specifiers don't apply to
sequential units (they're for direct and stream units, resp.),
so don't truncate the file when they're used.
@klausler klausler merged commit 96b1704 into llvm:main Feb 20, 2024
4 checks passed
@klausler klausler deleted the no-trunc-pos branch February 20, 2024 21:41
qiaojbao pushed a commit to GPUOpen-Drivers/llvm-project that referenced this pull request Mar 21, 2024
…dcbc628f2

Local branch amd-gfx d4bdcbc Merged main:9eb399b8548b835547947884b75c5fa79f977394 into amd-gfx:0ad536a6314e
Remote branch main 96b1704 [flang][runtime] Dont write implied ENDFILE for REC=/POS= (llvm#79637)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:runtime flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants