[flang] Fix character length checking in ALLOCATE (#163657)
The known character length compatibility check for ALLOCATE statements needs to allow for negative lengths, which are effectively zero. Fixes https://github.com/llvm/llvm-project/issues/163242.
This commit is contained in:
parent
a6181dc84b
commit
36c9b4fd6d
@ -441,7 +441,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;
|
||||
}
|
||||
@ -454,7 +454,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;
|
||||
}
|
||||
|
||||
5
flang/test/Semantics/bug163242.f90
Normal file
5
flang/test/Semantics/bug163242.f90
Normal file
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user