Skip to content

Conversation

@mjklemm
Copy link
Contributor

@mjklemm mjklemm commented Dec 9, 2025

This PR addresses an issue of incorrect code where an unallocated array is passed to a routine as a zero-length array. When compiling such a code with -O3, the assignment is ignored, but -O0 chokes in flang-rt due to an allocation check condition in the original code. Adding the extra condition makes the behavior consistent with -O3.

This PR addresses an issue of incorrect code where an unallocated array
is passed to a routine as a zero-length array.  When compiling such a
code with -O3, the assignment is ignored, but -O0 chokes in flang-rt due
to the above condition in the original code. Adding the extra condition
makes the behavior consistent with -O3.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a runtime crash in flang-rt when handling unallocated arrays passed as zero-length arrays. The change ensures that -O0 behavior matches -O3 by allowing assignments to unallocated zero-length arrays without triggering a runtime error.

Key Changes:

  • Modified the runtime check in assign.cpp to skip the crash condition when an unallocated array has zero elements

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mjklemm mjklemm changed the title [Flang-rt] Implement same beahvior as -O3 for zero-length arrays [Flang-rt] Implement same behavior as -O3 for zero-length arrays Dec 9, 2025
Copy link
Contributor

@klausler klausler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, and please ignore Copilot's request to make the error message confusing.

@mjklemm mjklemm merged commit 5489010 into llvm:main Dec 10, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants