[flang-commits] [flang] ed0abc8 - [flang] Correctly detect overlapping integer cases

Tim Keith via flang-commits flang-commits at lists.llvm.org
Mon Sep 14 09:11:08 PDT 2020


Author: Tim Keith
Date: 2020-09-14T09:10:49-07:00
New Revision: ed0abc8ad3f3be99f40c25238ec42065a8ba077f

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

LOG: [flang] Correctly detect overlapping integer cases

Integer case values were being compared as unsigned by operator<
on evaluate::value::Integer. Change that to signed so that overlap
can be detected correctly.

Explicit CompareUnsigned and BLT are still available if unsigned
comparison is needed.

Fixes https://bugs.llvm.org/show_bug.cgi?id=47309

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

Added: 
    

Modified: 
    flang/include/flang/Evaluate/integer.h
    flang/test/Semantics/case01.f90

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Evaluate/integer.h b/flang/include/flang/Evaluate/integer.h
index 6b91cb250c98..20b6731768de 100644
--- a/flang/include/flang/Evaluate/integer.h
+++ b/flang/include/flang/Evaluate/integer.h
@@ -176,22 +176,22 @@ class Integer {
   constexpr Integer &operator=(const Integer &) = default;
 
   constexpr bool operator<(const Integer &that) const {
-    return CompareUnsigned(that) == Ordering::Less;
+    return CompareSigned(that) == Ordering::Less;
   }
   constexpr bool operator<=(const Integer &that) const {
-    return CompareUnsigned(that) != Ordering::Greater;
+    return CompareSigned(that) != Ordering::Greater;
   }
   constexpr bool operator==(const Integer &that) const {
-    return CompareUnsigned(that) == Ordering::Equal;
+    return CompareSigned(that) == Ordering::Equal;
   }
   constexpr bool operator!=(const Integer &that) const {
     return !(*this == that);
   }
   constexpr bool operator>=(const Integer &that) const {
-    return CompareUnsigned(that) != Ordering::Less;
+    return CompareSigned(that) != Ordering::Less;
   }
   constexpr bool operator>(const Integer &that) const {
-    return CompareUnsigned(that) == Ordering::Greater;
+    return CompareSigned(that) == Ordering::Greater;
   }
 
   // Left-justified mask (e.g., MASKL(1) has only its sign bit set)

diff  --git a/flang/test/Semantics/case01.f90 b/flang/test/Semantics/case01.f90
index e1965db573b6..6342233a727e 100644
--- a/flang/test/Semantics/case01.f90
+++ b/flang/test/Semantics/case01.f90
@@ -163,3 +163,17 @@ program selectCaseProg
    end select
 
 end program
+
+program test_overlap
+  integer :: i
+  !OK: these cases do not overlap
+  select case(i)
+    case(0:)
+    case(:-1)
+  end select
+  select case(i)
+    case(-1:)
+    !ERROR: CASE (:0_4) conflicts with previous cases
+    case(:0)
+  end select
+end


        


More information about the flang-commits mailing list