[llvm] [Flang-rt] Implement same beahvior as -O3 for zero-length arrays (PR #171480)
Michael Klemm via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 9 09:47:32 PST 2025
https://github.com/mjklemm created https://github.com/llvm/llvm-project/pull/171480
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.
>From b1fd7cfbbe960c552dee77d896ee05a211c48fad Mon Sep 17 00:00:00 2001
From: Michael Klemm <michael.klemm at amd.com>
Date: Tue, 9 Dec 2025 18:43:53 +0100
Subject: [PATCH] [Flang-rt] Implement same beahvior as -O3 for zero-length
arrays
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.
---
flang-rt/lib/runtime/assign.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/flang-rt/lib/runtime/assign.cpp b/flang-rt/lib/runtime/assign.cpp
index b70182ccb3178..dd5d4b945881e 100644
--- a/flang-rt/lib/runtime/assign.cpp
+++ b/flang-rt/lib/runtime/assign.cpp
@@ -366,7 +366,7 @@ RT_API_ATTRS int AssignTicket::Begin(WorkQueue &workQueue) {
"assignment to unallocated allocatable",
to_.rank(), from_->rank());
}
- } else if (!to_.IsAllocated()) {
+ } else if (!to_.IsAllocated() && to_.Elements()) {
workQueue.terminator().Crash(
"Assign: left-hand side variable is neither allocated nor allocatable");
}
More information about the llvm-commits
mailing list