Author: Timm Bäder
Date: 2023-11-17T08:04:30+01:00
New Revision: 894a38753e8c4cfef7a1dae17a76b405208b2708

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

LOG: [clang][Interp][NFC] Properly implement IntegralAP::from(IntegralAP)

This used to just pass on the given parameter, but we need to respect
the given bit width.

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 bd665959cf3dcc4..9019f32e6cef2a3 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -102,7 +102,12 @@ template <bool Signed> class IntegralAP final {
 
   template <bool InputSigned>
   static IntegralAP from(IntegralAP<InputSigned> V, unsigned NumBits = 0) {
-    return IntegralAP<Signed>(V.V);
+    if (NumBits == 0)
+      NumBits = V.bitWidth();
+
+    if constexpr (InputSigned)
+      return IntegralAP<Signed>(V.V.sextOrTrunc(NumBits));
+    return IntegralAP<Signed>(V.V.zextOrTrunc(NumBits));
   }
 
   template <unsigned Bits, bool InputSigned>


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to