[clang] [clang][Interp] Implement IntegralAP subtraction (PR #71648)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 8 06:12:43 PST 2023
================
@@ -256,28 +255,23 @@ template <bool Signed> class IntegralAP final {
}
private:
- static bool CheckAddUB(const IntegralAP &A, const IntegralAP &B,
- unsigned BitWidth, IntegralAP *R) {
- if (!A.isSigned()) {
- R->V = A.V + B.V;
+ template <template <typename T> class Op>
+ static bool CheckAddSubUB(const IntegralAP &A, const IntegralAP &B,
+ unsigned BitWidth, IntegralAP *R) {
+ if constexpr (!Signed) {
+ auto UOp = Op<APInt>();
+ R->V = UOp(A.V, B.V);
return false;
}
- const APSInt &LHS = APSInt(A.V, A.isSigned());
- const APSInt &RHS = APSInt(B.V, B.isSigned());
-
- APSInt Value(LHS.extend(BitWidth) + RHS.extend(BitWidth), false);
+ auto SOp = Op<APSInt>();
+ const APSInt &LHS = A.toAPSInt();
+ const APSInt &RHS = B.toAPSInt();
+ APSInt Value(SOp(LHS.extend(BitWidth), RHS.extend(BitWidth)), false);
----------------
AaronBallman wrote:
```suggestion
const APSInt &LHS = A.toAPSInt();
const APSInt &RHS = B.toAPSInt();
APSInt Value(Op<APSInt>{}(LHS.extend(BitWidth), RHS.extend(BitWidth)), false);
```
https://github.com/llvm/llvm-project/pull/71648
More information about the cfe-commits
mailing list