Revert "[clang][Interp] Fix left-/right-shifting more than sizeof(unsigned)"
authorTimm Bäder <tbaeder@redhat.com>
Thu, 26 Jan 2023 06:49:10 +0000 (07:49 +0100)
committerTimm Bäder <tbaeder@redhat.com>
Thu, 26 Jan 2023 06:49:10 +0000 (07:49 +0100)
This reverts commit 00e967f6c2d626d1913f5af5763beab7946978ce.

This breaks builders where long is only 32 bits, e.g.
https://lab.llvm.org/buildbot/#/builders/65/builds/7721
https://lab.llvm.org/buildbot/#/builders/245/builds/3899

clang/lib/AST/Interp/Integral.h
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/shifts.cpp

index 0eb0990..d536816 100644 (file)
@@ -234,18 +234,6 @@ public:
     return false;
   }
 
-  template <unsigned RHSBits, bool RHSSign>
-  static void shiftLeft(const Integral A, const Integral<RHSBits, RHSSign> B,
-                        unsigned OpBits, Integral *R) {
-    *R = Integral::from(A.V << B.V, OpBits);
-  }
-
-  template <unsigned RHSBits, bool RHSSign>
-  static void shiftRight(const Integral A, const Integral<RHSBits, RHSSign> B,
-                         unsigned OpBits, Integral *R) {
-    *R = Integral::from(A.V >> B.V, OpBits);
-  }
-
 private:
   template <typename T> static bool CheckAddUB(T A, T B, T &R) {
     if constexpr (std::is_signed_v<T>) {
index b36b513..466df04 100644 (file)
@@ -1334,9 +1334,8 @@ inline bool Shr(InterpState &S, CodePtr OpPC) {
   if (!CheckShift<RT>(S, OpPC, RHS, Bits))
     return false;
 
-  Integral<LT::bitWidth(), false> R;
-  Integral<LT::bitWidth(), false>::shiftRight(LHS.toUnsigned(), RHS, Bits, &R);
-  S.Stk.push<LT>(R);
+  unsigned URHS = static_cast<unsigned>(RHS);
+  S.Stk.push<LT>(LT::from(static_cast<unsigned>(LHS) >> URHS, LHS.bitWidth()));
   return true;
 }
 
@@ -1351,9 +1350,9 @@ inline bool Shl(InterpState &S, CodePtr OpPC) {
   if (!CheckShift<RT>(S, OpPC, RHS, Bits))
     return false;
 
-  Integral<LT::bitWidth(), false> R;
-  Integral<LT::bitWidth(), false>::shiftLeft(LHS.toUnsigned(), RHS, Bits, &R);
-  S.Stk.push<LT>(R);
+  unsigned URHS = static_cast<unsigned>(RHS);
+  S.Stk.push<LT>(LT::from(static_cast<unsigned>(LHS) << URHS, LHS.bitWidth()));
+
   return true;
 }
 
index a919325..8fa78be 100644 (file)
@@ -143,9 +143,4 @@ namespace shifts {
 
   constexpr char c2 = 1;
   constexpr int i3 = c2 << (__CHAR_BIT__ + 1); // Not ill-formed
-
-  constexpr signed long int L = 1;
-  constexpr signed int R = 62;
-  constexpr decltype(L) M = L << R;
-  constexpr decltype(L) M2 = L >> R;
 };