-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[flang] Fix character length checking in ALLOCATE #163657
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
Conversation
The known character length compatibility check for ALLOCATE statements needs to allow for negative lengths, which are effectively zero. Fixes llvm#163242.
|
@llvm/pr-subscribers-flang-semantics Author: Peter Klausler (klausler) ChangesThe known character length compatibility check for ALLOCATE statements needs to allow for negative lengths, which are effectively zero. Fixes #163242. Full diff: https://github.com/llvm/llvm-project/pull/163657.diff 2 Files Affected:
diff --git a/flang/lib/Semantics/check-allocate.cpp b/flang/lib/Semantics/check-allocate.cpp
index 823aa4e795e35..d7772da210917 100644
--- a/flang/lib/Semantics/check-allocate.cpp
+++ b/flang/lib/Semantics/check-allocate.cpp
@@ -439,7 +439,7 @@ static bool HaveCompatibleLengths(
evaluate::ToInt64(type1.characterTypeSpec().length().GetExplicit())};
auto v2{
evaluate::ToInt64(type2.characterTypeSpec().length().GetExplicit())};
- return !v1 || !v2 || *v1 == *v2;
+ return !v1 || !v2 || (*v1 >= 0 ? *v1 : 0) == (*v2 >= 0 ? *v2 : 0);
} else {
return true;
}
@@ -452,7 +452,7 @@ static bool HaveCompatibleLengths(
auto v1{
evaluate::ToInt64(type1.characterTypeSpec().length().GetExplicit())};
auto v2{type2.knownLength()};
- return !v1 || !v2 || *v1 == *v2;
+ return !v1 || !v2 || (*v1 >= 0 ? *v1 : 0) == (*v2 >= 0 ? *v2 : 0);
} else {
return true;
}
diff --git a/flang/test/Semantics/bug163242.f90 b/flang/test/Semantics/bug163242.f90
new file mode 100644
index 0000000000000..5e020aeb4dc0d
--- /dev/null
+++ b/flang/test/Semantics/bug163242.f90
@@ -0,0 +1,5 @@
+!RUN: %flang -fc1 -fsyntax-only %s | FileCheck --allow-empty %s
+!CHECK-NOT: error:
+character(0), allocatable :: ch
+allocate(character(-1) :: ch)
+end
|
akuhlens
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
eugeneepshteyn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One suggestion, otherwise LGTM
DanielCChen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Thanks.
The known character length compatibility check for ALLOCATE statements needs to allow for negative lengths, which are effectively zero.
Fixes #163242.