[flang-commits] [flang] f9ebf77 - [flang] Correct folding of SAME_TYPE_AS()

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Thu Dec 15 13:52:02 PST 2022


Author: Peter Klausler
Date: 2022-12-15T13:51:50-08:00
New Revision: f9ebf77ffd9aaaa0f90f9e90667e4daaea3377a3

URL: https://github.com/llvm/llvm-project/commit/f9ebf77ffd9aaaa0f90f9e90667e4daaea3377a3
DIFF: https://github.com/llvm/llvm-project/commit/f9ebf77ffd9aaaa0f90f9e90667e4daaea3377a3.diff

LOG: [flang] Correct folding of SAME_TYPE_AS()

The result can't be known to be true at compilation time when
either operand is polymorphic.

Differential Revision: https://reviews.llvm.org/D140126

Added: 
    

Modified: 
    flang/lib/Evaluate/type.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Evaluate/type.cpp b/flang/lib/Evaluate/type.cpp
index d06e7323baa73..79bd8366fb2b8 100644
--- a/flang/lib/Evaluate/type.cpp
+++ b/flang/lib/Evaluate/type.cpp
@@ -354,10 +354,11 @@ bool DynamicType::IsTkLenCompatibleWith(const DynamicType &that) const {
 std::optional<bool> DynamicType::SameTypeAs(const DynamicType &that) const {
   bool x{AreCompatibleTypes(*this, that, true, true)};
   bool y{AreCompatibleTypes(that, *this, true, true)};
-  if (x == y) {
-    return x;
+  if (!x && !y) {
+    return false;
+  } else if (x && y && !IsPolymorphic() && !that.IsPolymorphic()) {
+    return true;
   } else {
-    // If either is unlimited polymorphic, the result is unknown.
     return std::nullopt;
   }
 }


        


More information about the flang-commits mailing list