[clang] c468e89 - [clang][Interp][NFC] Fix right shifting signed IntegralAP values

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 8 00:33:50 PST 2023


Author: Timm Bäder
Date: 2023-11-08T09:33:37+01:00
New Revision: c468e8923cadfa4c181eaa8bdbcf8d95feb70132

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

LOG: [clang][Interp][NFC] Fix right shifting signed IntegralAP values

Added: 
    

Modified: 
    clang/lib/AST/Interp/IntegralAP.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/IntegralAP.h b/clang/lib/AST/Interp/IntegralAP.h
index 1f535d420bcd54b..6d301bad784af47 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -248,7 +248,11 @@ template <bool Signed> class IntegralAP final {
 
   static void shiftRight(const IntegralAP A, const IntegralAP B,
                          unsigned OpBits, IntegralAP *R) {
-    *R = IntegralAP(A.V.ashr(B.V.getZExtValue()));
+    unsigned ShiftAmount = B.V.getZExtValue();
+    if constexpr (Signed)
+      *R = IntegralAP(A.V.ashr(ShiftAmount));
+    else
+      *R = IntegralAP(A.V.lshr(ShiftAmount));
   }
 
 private:


        


More information about the cfe-commits mailing list