[clang] [clang][Interp] Implement IntegralAP::mul() (PR #72491)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 16 00:28:08 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/72491.diff
2 Files Affected:
- (modified) clang/lib/AST/Interp/IntegralAP.h (+5-7)
- (modified) clang/test/AST/Interp/intap.cpp (+16)
``````````diff
diff --git a/clang/lib/AST/Interp/IntegralAP.h b/clang/lib/AST/Interp/IntegralAP.h
index b8e37878ce2f848..b9d7eab331d27bd 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -191,17 +191,15 @@ template <bool Signed> class IntegralAP final {
}
static bool add(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
- return CheckAddSubUB<std::plus>(A, B, OpBits, R);
+ return CheckAddSubMulUB<std::plus>(A, B, OpBits, R);
}
static bool sub(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
- return CheckAddSubUB<std::minus>(A, B, OpBits, R);
+ return CheckAddSubMulUB<std::minus>(A, B, OpBits, R);
}
static bool mul(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
- // FIXME: Implement.
- assert(false);
- return false;
+ return CheckAddSubMulUB<std::multiplies>(A, B, OpBits, R);
}
static bool rem(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
@@ -264,8 +262,8 @@ template <bool Signed> class IntegralAP final {
private:
template <template <typename T> class Op>
- static bool CheckAddSubUB(const IntegralAP &A, const IntegralAP &B,
- unsigned BitWidth, IntegralAP *R) {
+ static bool CheckAddSubMulUB(const IntegralAP &A, const IntegralAP &B,
+ unsigned BitWidth, IntegralAP *R) {
if constexpr (!Signed) {
R->V = Op<APInt>{}(A.V, B.V);
return false;
diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index c3cae9a64780d5c..f04a82af2736ca5 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -35,6 +35,15 @@ static_assert(UBitIntZero1 == 0, "");
constexpr unsigned _BitInt(2) BI1 = 3u;
static_assert(BI1 == 3, "");
+constexpr _BitInt(4) MulA = 5;
+constexpr _BitInt(4) MulB = 7;
+static_assert(MulA * MulB == 50, ""); // ref-error {{not an integral constant expression}} \
+ // ref-note {{value 35 is outside the range of representable values of type '_BitInt(4)'}} \
+ // expected-error {{not an integral constant expression}} \
+ // expected-note {{value 35 is outside the range of representable values of type '_BitInt(4)'}}
+static_assert(MulA * 5 == 25, "");
+static_assert(-1 * MulB == -7, "");
+
namespace APCast {
constexpr _BitInt(10) A = 1;
constexpr _BitInt(11) B = A;
@@ -66,6 +75,8 @@ namespace i128 {
// ref-error {{static assertion failed}} \
// ref-note {{'340282366920938463463374607431768211455 == 1'}}
+ constexpr uint128_t TooMuch = UINT128_MAX * 2;
+
static const __int128_t INT128_MAX = UINT128_MAX >> (__int128_t)1;
static_assert(INT128_MAX != 0, "");
static_assert(INT128_MAX == 0, ""); // expected-error {{failed}} \
@@ -73,6 +84,11 @@ namespace i128 {
// ref-error {{failed}} \
// ref-note {{evaluates to '170141183460469231731687303715884105727 == 0'}}
+ constexpr int128_t TooMuch2 = INT128_MAX * INT128_MAX; // ref-error {{must be initialized by a constant expression}} \
+ // ref-note {{value 28948022309329048855892746252171976962977213799489202546401021394546514198529 is outside the range of representable}} \
+ // expected-error {{must be initialized by a constant expression}} \
+ // expected-note {{value 28948022309329048855892746252171976962977213799489202546401021394546514198529 is outside the range of representable}}
+
static const __int128_t INT128_MIN = -INT128_MAX - 1;
constexpr __int128 A = INT128_MAX + 1; // expected-error {{must be initialized by a constant expression}} \
// expected-note {{value 170141183460469231731687303715884105728 is outside the range}} \
``````````
</details>
https://github.com/llvm/llvm-project/pull/72491
More information about the cfe-commits
mailing list