[flang-commits] [flang] e47fbb7 - [flang] Fixed comparison for derived types constants.
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Tue May 16 09:51:19 PDT 2023
Author: Slava Zakharin
Date: 2023-05-16T09:51:09-07:00
New Revision: e47fbb7cd2d22b787d1022fd2f3bef4a051d67c8
URL: https://github.com/llvm/llvm-project/commit/e47fbb7cd2d22b787d1022fd2f3bef4a051d67c8
DIFF: https://github.com/llvm/llvm-project/commit/e47fbb7cd2d22b787d1022fd2f3bef4a051d67c8.diff
LOG: [flang] Fixed comparison for derived types constants.
The two constants should be equal only if their derived types
are the same. This fixes regression caused by D150380.
Differential Revision: https://reviews.llvm.org/D150634
Added:
Modified:
flang/include/flang/Evaluate/constant.h
flang/lib/Evaluate/constant.cpp
flang/test/Lower/constant-literal-mangling.f90
Removed:
################################################################################
diff --git a/flang/include/flang/Evaluate/constant.h b/flang/include/flang/Evaluate/constant.h
index 611ee7772d2a1..73e4271cc28ad 100644
--- a/flang/include/flang/Evaluate/constant.h
+++ b/flang/include/flang/Evaluate/constant.h
@@ -225,6 +225,7 @@ class Constant<SomeDerived>
std::optional<StructureConstructor> GetScalarValue() const;
StructureConstructor At(const ConstantSubscripts &) const;
+ bool operator==(const Constant &) const;
Constant Reshape(ConstantSubscripts &&) const;
std::size_t CopyFrom(const Constant &source, std::size_t count,
ConstantSubscripts &resultSubscripts, const std::vector<int> *dimOrder);
diff --git a/flang/lib/Evaluate/constant.cpp b/flang/lib/Evaluate/constant.cpp
index 1a4d30cf9d142..c94b198fdaf2e 100644
--- a/flang/lib/Evaluate/constant.cpp
+++ b/flang/lib/Evaluate/constant.cpp
@@ -346,6 +346,12 @@ StructureConstructor Constant<SomeDerived>::At(
return {result().derivedTypeSpec(), values_.at(SubscriptsToOffset(index))};
}
+bool Constant<SomeDerived>::operator==(
+ const Constant<SomeDerived> &that) const {
+ return result().derivedTypeSpec() == that.result().derivedTypeSpec() &&
+ shape() == that.shape() && values_ == that.values_;
+}
+
auto Constant<SomeDerived>::Reshape(ConstantSubscripts &&dims) const
-> Constant {
return {result().derivedTypeSpec(), Base::Reshape(dims), std::move(dims)};
diff --git a/flang/test/Lower/constant-literal-mangling.f90 b/flang/test/Lower/constant-literal-mangling.f90
index ef33ffe450b0f..33a658fb61cd1 100644
--- a/flang/test/Lower/constant-literal-mangling.f90
+++ b/flang/test/Lower/constant-literal-mangling.f90
@@ -9,6 +9,12 @@
integer :: i
end type
+type emptyType1
+end type emptyType1
+
+type emptyType2
+end type emptyType2
+
print *, [42, 42]
! CHECK: fir.address_of(@_QQro.2xi4.0)
@@ -68,6 +74,8 @@
print *, [otherType(42)]
! CHECK: fir.address_of(@_QQro.1x_QFTothertype.14)
+ print *, [emptyType1()]
+ print *, [emptyType2()]
end
! CHECK: fir.global internal @_QQro.1x_QFTsometype.10 constant : !fir.array<1x!fir.type<_QFTsometype{i:i32}>> {
More information about the flang-commits
mailing list